Skip to content

Commit fd874ec

Browse files
committed
Pass API to server block.
This allows the tests to access the api as a parameter to the with_api block. (Credit goes to Alexkwolfe for this one)
1 parent 4a13e1f commit fd874ec

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

‎lib/goliath/server.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def start(&blk)
9090
conn.options=options
9191
end
9292

93-
blk.callifblk
93+
blk.call(self)ifblk
9494
end
9595
end
9696

‎spec/integration/http_log_spec.rb‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def config_file
3232

3333
let(:api_options){{:config=>config_file}}
3434

35-
defmock_mongo
36-
@api_server.config['mongo']=mock('mongo').as_null_object
35+
defmock_mongo(api)
36+
api.config['mongo']=mock('mongo').as_null_object
3737
end
3838

3939
it'responds to requests'do
40-
with_api(HttpLog,api_options)do
40+
with_api(HttpLog,api_options)do |api|
4141
server(Responder,8080)
42-
mock_mongo
42+
mock_mongo(api)
4343

4444
get_request({},err)do |c|
4545
c.response_header.status.should == 200
@@ -48,9 +48,9 @@ def mock_mongo
4848
end
4949

5050
it'forwards to our API server'do
51-
with_api(HttpLog,api_options)do
51+
with_api(HttpLog,api_options)do |api|
5252
server(Responder,8080)
53-
mock_mongo
53+
mock_mongo(api)
5454

5555
get_request({},err)do |c|
5656
c.response_header.status.should == 200
@@ -70,9 +70,9 @@ def mock_mongo
7070

7171
context'query parameters'do
7272
it'forwards the query parameters'do
73-
with_api(HttpLog,api_options)do
73+
with_api(HttpLog,api_options)do |api|
7474
server(Responder,8080)
75-
mock_mongo
75+
mock_mongo(api)
7676

7777
get_request({:query=>{:first=>:foo,:second=>:bar,:third=>:baz}},err)do |c|
7878
c.response_header.status.should == 200
@@ -84,9 +84,9 @@ def mock_mongo
8484

8585
context'request path'do
8686
it'forwards the request path'do
87-
with_api(HttpLog,api_options)do
87+
with_api(HttpLog,api_options)do |api|
8888
server(Responder,8080)
89-
mock_mongo
89+
mock_mongo(api)
9090

9191
get_request({:path=>'/my/request/path'},err)do |c|
9292
c.response_header.status.should == 200
@@ -98,9 +98,9 @@ def mock_mongo
9898

9999
context'headers'do
100100
it'forwards the headers'do
101-
with_api(HttpLog,api_options)do
101+
with_api(HttpLog,api_options)do |api|
102102
server(Responder,8080)
103-
mock_mongo
103+
mock_mongo(api)
104104

105105
get_request({:head=>{:first=>:foo,:second=>:bar}},err)do |c|
106106
c.response_header.status.should == 200
@@ -112,9 +112,9 @@ def mock_mongo
112112

113113
context'request method'do
114114
it'forwards GET requests'do
115-
with_api(HttpLog,api_options)do
115+
with_api(HttpLog,api_options)do |api|
116116
server(Responder,8080)
117-
mock_mongo
117+
mock_mongo(api)
118118

119119
get_request({},err)do |c|
120120
c.response_header.status.should == 200
@@ -124,9 +124,9 @@ def mock_mongo
124124
end
125125

126126
it'forwards POST requests'do
127-
with_api(HttpLog,api_options)do
127+
with_api(HttpLog,api_options)do |api|
128128
server(Responder,8080)
129-
mock_mongo
129+
mock_mongo(api)
130130

131131
post_request({},err)do |c|
132132
c.response_header.status.should == 200

0 commit comments

Comments
(0)