http_stub 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/http_stub.rb CHANGED
@@ -28,6 +28,7 @@ require File.expand_path('../http_stub/configurer/request/regexpable', __FILE__)
28
28
  require File.expand_path('../http_stub/configurer/request/stub', __FILE__)
29
29
  require File.expand_path('../http_stub/configurer/request/stub_activator', __FILE__)
30
30
  require File.expand_path('../http_stub/configurer/command', __FILE__)
31
+ require File.expand_path('../http_stub/configurer/command_processor', __FILE__)
31
32
  require File.expand_path('../http_stub/configurer/patient_command_chain', __FILE__)
32
33
  require File.expand_path('../http_stub/configurer/impatient_command_chain', __FILE__)
33
34
  require File.expand_path('../http_stub/configurer', __FILE__)
@@ -9,10 +9,18 @@ module HttpStub
9
9
 
10
10
  module ClassMethods
11
11
 
12
+ def get_host
13
+ @host
14
+ end
15
+
12
16
  def host(host)
13
17
  @host = host
14
18
  end
15
19
 
20
+ def get_port
21
+ @port
22
+ end
23
+
16
24
  def port(port)
17
25
  @port = port
18
26
  end
@@ -63,7 +71,7 @@ module HttpStub
63
71
 
64
72
  def handle(command_options)
65
73
  effective_command_chain <<
66
- HttpStub::Configurer::Command.new({ host: @host, port: @port }.merge(command_options))
74
+ HttpStub::Configurer::Command.new({ processor: command_processor }.merge(command_options))
67
75
  end
68
76
 
69
77
  def effective_command_chain
@@ -74,6 +82,10 @@ module HttpStub
74
82
  @initialize_command_chain ||= HttpStub::Configurer::PatientCommandChain.new()
75
83
  end
76
84
 
85
+ def command_processor
86
+ @command_processor ||= HttpStub::Configurer::CommandProcessor.new(self)
87
+ end
88
+
77
89
  end
78
90
 
79
91
  module InstanceMethods
@@ -3,17 +3,17 @@ module HttpStub
3
3
 
4
4
  class Command
5
5
 
6
+ attr_reader :request, :description
7
+
6
8
  def initialize(options)
7
- @host = options[:host]
8
- @port = options[:port]
9
+ @processor = options[:processor]
9
10
  @request = options[:request]
10
11
  @description = options[:description]
11
12
  @resetable_flag = !!options[:resetable]
12
13
  end
13
14
 
14
15
  def execute
15
- response = Net::HTTP.start(@host, @port) { |http| http.request(@request) }
16
- raise "Error occurred #{@description}: #{response.message}" unless response.code == "200"
16
+ @processor.process(self)
17
17
  end
18
18
 
19
19
  def resetable?
@@ -0,0 +1,18 @@
1
+ module HttpStub
2
+ module Configurer
3
+
4
+ class CommandProcessor
5
+
6
+ def initialize(configurer)
7
+ @configurer = configurer
8
+ end
9
+
10
+ def process(command)
11
+ response = Net::HTTP.start(@configurer.get_host, @configurer.get_port) { |http| http.request(command.request) }
12
+ raise "Error occurred #{command.description}: #{response.message}" unless response.code == "200"
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -0,0 +1,33 @@
1
+ describe HttpStub::Configurer::CommandProcessor, "when the server is running" do
2
+ include_context "server integration"
3
+
4
+ let(:configurer) { double(HttpStub::Configurer, get_host: "localhost", get_port: 8001) }
5
+ let(:command) { HttpStub::Configurer::Command.new(request: request, description: "performing an operation") }
6
+
7
+ let(:command_processor) { HttpStub::Configurer::CommandProcessor.new(configurer) }
8
+
9
+ describe "#process" do
10
+
11
+ describe "when the server responds with a 200 response" do
12
+
13
+ let(:request) { Net::HTTP::Get.new("/stubs") }
14
+
15
+ it "should execute without error" do
16
+ lambda { command_processor.process(command) }.should_not raise_error
17
+ end
18
+
19
+ end
20
+
21
+ describe "when the server responds with a non-200 response" do
22
+
23
+ let(:request) { Net::HTTP::Get.new("/causes_error") }
24
+
25
+ it "should raise an exception that includes the commands description" do
26
+ lambda { command_processor.process(command) }.should raise_error(/performing an operation/)
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -1,19 +1,28 @@
1
1
  describe HttpStub::Configurer::Command do
2
2
 
3
- let(:options) do
4
- { host: "some_host", port: 8888, request: double("HttpRequest"), description: "Some Description" }
5
- end
3
+ let(:processor) { double(HttpStub::Configurer::CommandProcessor) }
4
+ let(:options) { { processor: processor, request: double("HttpRequest"), description: "Some Description" } }
5
+
6
+ let(:command) { HttpStub::Configurer::Command.new(options) }
7
+
8
+ describe "#execute" do
9
+
10
+ it "should delegate to the provided processor" do
11
+ processor.should_receive(:process).with(command)
6
12
 
7
- let(:command) { HttpStub::Configurer::Command.new(resetable: true) }
13
+ command.execute
14
+ end
15
+
16
+ end
8
17
 
9
18
  describe "#resetable" do
10
19
 
11
20
  describe "when created with a resetable flag that is true" do
12
21
 
13
- let(:options) { options.merge(resetable: true) }
22
+ before(:each) { options.merge!(resetable: true) }
14
23
 
15
24
  it "should return true" do
16
- command.should be_resetable
25
+ command.resetable?.should be_true
17
26
  end
18
27
 
19
28
  end
@@ -21,7 +30,7 @@ describe HttpStub::Configurer::Command do
21
30
  describe "when created without a resetable flag" do
22
31
 
23
32
  it "should return false" do
24
- command.should be_resetable
33
+ command.resetable?.should be_false
25
34
  end
26
35
 
27
36
  end
@@ -8,17 +8,21 @@ describe HttpStub::Configurer, "when the server is running" do
8
8
  configurer.class.clear_activators!
9
9
  end
10
10
 
11
- describe "and the configurer is initialized" do
11
+ context "and the configurer is initialized" do
12
12
 
13
- before(:each) { configurer.class.initialize! }
13
+ before(:each) do
14
+ configurer.class.host server_host
15
+ configurer.class.port server_port
16
+ configurer.class.initialize!
17
+ end
14
18
 
15
- describe "and a stub is activated" do
19
+ context "and a stub is activated" do
16
20
 
17
21
  before(:each) { configurer.activate!("/an_activator") }
18
22
 
19
- describe "and the stub request is made" do
23
+ context "and the stub request is made" do
20
24
 
21
- let(:response) { Net::HTTP.get_response("localhost", "/stub_path", 8001) }
25
+ let(:response) { Net::HTTP.get_response(server_host, "/stub_path", server_port) }
22
26
 
23
27
  it "should replay the stubbed response" do
24
28
  response.code.should eql("200")
@@ -29,11 +33,11 @@ describe HttpStub::Configurer, "when the server is running" do
29
33
 
30
34
  end
31
35
 
32
- describe "and a stub is not activated" do
36
+ context "and a stub is not activated" do
33
37
 
34
- describe "and the stub request is made" do
38
+ context "and the stub request is made" do
35
39
 
36
- let(:response) { Net::HTTP.get_response("localhost", "/stub_path", 8001) }
40
+ let(:response) { Net::HTTP.get_response(server_host, "/stub_path", server_port) }
37
41
 
38
42
  it "should respond with a 404 status code" do
39
43
  response.code.should eql("404")
@@ -43,29 +47,29 @@ describe HttpStub::Configurer, "when the server is running" do
43
47
 
44
48
  end
45
49
 
46
- describe "and a class stub is defined" do
50
+ context "and a class stub is defined" do
47
51
 
48
52
  let(:configurer) { HttpStub::Examples::ConfigurerWithClassStub.new }
49
53
 
50
54
  it "should register the stub" do
51
- response = Net::HTTP.get_response("localhost", "/a_class_stub", 8001)
55
+ response = Net::HTTP.get_response(server_host, "/a_class_stub", server_port)
52
56
 
53
57
  response.code.should eql("201")
54
58
  response.body.should eql("Class stub body")
55
59
  end
56
60
 
57
- describe "and the stub is overridden" do
61
+ context "and the stub is overridden" do
58
62
 
59
63
  before(:each) do
60
64
  configurer.stub_response!("/a_class_stub", method: :get, response: { body: "Other class stub body" })
61
65
  end
62
66
 
63
- describe "and the configurer is re-initialized" do
67
+ context "and the configurer is re-initialized" do
64
68
 
65
69
  before(:each) { configurer.class.initialize! }
66
70
 
67
71
  it "should re-establish the class stub as having priority" do
68
- response = Net::HTTP.get_response("localhost", "/a_class_stub", 8001)
72
+ response = Net::HTTP.get_response(server_host, "/a_class_stub", server_port)
69
73
 
70
74
  response.code.should eql("201")
71
75
  response.body.should eql("Class stub body")
@@ -77,49 +81,49 @@ describe HttpStub::Configurer, "when the server is running" do
77
81
 
78
82
  end
79
83
 
80
- describe "and the initializer contains stub activators that are activated and conventional stubs" do
84
+ context "and the initializer contains stub activators that are activated and conventional stubs" do
81
85
 
82
86
  let(:configurer) { HttpStub::Examples::ConfigurerWithComplexInitializer.new }
83
87
 
84
88
  it "should register the activated activator" do
85
- response = Net::HTTP.get_response("localhost", "/activated_during_initialization_stub_path", 8001)
89
+ response = Net::HTTP.get_response(server_host, "/activated_during_initialization_stub_path", server_port)
86
90
 
87
91
  response.code.should eql("200")
88
92
  response.body.should eql("Activated during initialization body")
89
93
  end
90
94
 
91
95
  it "should register the stub" do
92
- response = Net::HTTP.get_response("localhost", "/stubbed_during_initialization_path", 8001)
96
+ response = Net::HTTP.get_response(server_host, "/stubbed_during_initialization_path", server_port)
93
97
 
94
98
  response.code.should eql("200")
95
99
  response.body.should eql("Stubbed during initialization body")
96
100
  end
97
101
 
98
- describe "and another stub is registered" do
102
+ context "and another stub is registered" do
99
103
 
100
104
  before(:each) do
101
105
  configurer.stub_response!("/another_stub", method: :get, response: { body: "Another stub body" })
102
106
  end
103
107
 
104
- describe "and the configurer is reset" do
108
+ context "and the configurer is reset" do
105
109
 
106
110
  before(:each) { configurer.reset! }
107
111
 
108
112
  it "should remove the stub registered post-initialization" do
109
- response = Net::HTTP.get_response("localhost", "/another_stub", 8001)
113
+ response = Net::HTTP.get_response(server_host, "/another_stub", server_port)
110
114
 
111
115
  response.code.should eql("404")
112
116
  end
113
117
 
114
118
  it "should retain the activated activator during initialization" do
115
- response = Net::HTTP.get_response("localhost", "/activated_during_initialization_stub_path", 8001)
119
+ response = Net::HTTP.get_response(server_host, "/activated_during_initialization_stub_path", server_port)
116
120
 
117
121
  response.code.should eql("200")
118
122
  response.body.should eql("Activated during initialization body")
119
123
  end
120
124
 
121
125
  it "should retain the stub registered during initialization" do
122
- response = Net::HTTP.get_response("localhost", "/stubbed_during_initialization_path", 8001)
126
+ response = Net::HTTP.get_response(server_host, "/stubbed_during_initialization_path", server_port)
123
127
 
124
128
  response.code.should eql("200")
125
129
  response.body.should eql("Stubbed during initialization body")
@@ -131,19 +135,19 @@ describe HttpStub::Configurer, "when the server is running" do
131
135
 
132
136
  end
133
137
 
134
- describe "and a response for a request is stubbed" do
138
+ context "and a response for a request is stubbed" do
135
139
 
136
- describe "that contains no headers or parameters" do
140
+ context "that contains no headers or parameters" do
137
141
 
138
- describe "and contains a response status" do
142
+ context "and contains a response status" do
139
143
 
140
144
  before(:each) do
141
145
  configurer.stub_response!("/stub_with_status", method: :get, response: { status: 201, body: "Stub body" })
142
146
  end
143
147
 
144
- describe "and that request is made" do
148
+ context "and that request is made" do
145
149
 
146
- let(:response) { Net::HTTP.get_response("localhost", "/stub_with_status", 8001) }
150
+ let(:response) { Net::HTTP.get_response(server_host, "/stub_with_status", server_port) }
147
151
 
148
152
  it "should respond with the stubbed status" do
149
153
  response.code.should eql("201")
@@ -155,13 +159,13 @@ describe HttpStub::Configurer, "when the server is running" do
155
159
 
156
160
  end
157
161
 
158
- describe "and the stub is cleared" do
162
+ context "and the stub is cleared" do
159
163
 
160
164
  before(:each) { configurer.clear! }
161
165
 
162
- describe "and the original request is made" do
166
+ context "and the original request is made" do
163
167
 
164
- let(:response) { Net::HTTP.get_response("localhost", "/stub_with_status", 8001) }
168
+ let(:response) { Net::HTTP.get_response(server_host, "/stub_with_status", server_port) }
165
169
 
166
170
  it "should respond with a 404 status code" do
167
171
  response.code.should eql("404")
@@ -173,15 +177,15 @@ describe HttpStub::Configurer, "when the server is running" do
173
177
 
174
178
  end
175
179
 
176
- describe "and does not contain a response status" do
180
+ context "and does not contain a response status" do
177
181
 
178
182
  before(:each) do
179
183
  configurer.stub_response!("/stub_without_status", method: :get, response: { body: "Stub body" })
180
184
  end
181
185
 
182
- describe "and that request is made" do
186
+ context "and that request is made" do
183
187
 
184
- let(:response) { Net::HTTP.get_response("localhost", "/stub_without_status", 8001) }
188
+ let(:response) { Net::HTTP.get_response(server_host, "/stub_without_status", server_port) }
185
189
 
186
190
  it "should respond with the stubbed body" do
187
191
  response.body.should eql("Stub body")
@@ -189,15 +193,15 @@ describe HttpStub::Configurer, "when the server is running" do
189
193
 
190
194
  end
191
195
 
192
- describe "and the stub uri is regular expression containing meta characters" do
196
+ context "and the stub uri is regular expression containing meta characters" do
193
197
 
194
198
  before(:each) do
195
199
  configurer.stub_response!(/\/stub\/regexp\/\$key=value/, method: :get, response: { body: "Stub body" })
196
200
  end
197
201
 
198
- describe "and a request is made whose uri matches the regular expression" do
202
+ context "and a request is made whose uri matches the regular expression" do
199
203
 
200
- let(:response) { Net::HTTP.get_response("localhost", "/match/stub/regexp/$key=value", 8001) }
204
+ let(:response) { Net::HTTP.get_response(server_host, "/match/stub/regexp/$key=value", server_port) }
201
205
 
202
206
  it "should respond with the stubbed body" do
203
207
  response.body.should eql("Stub body")
@@ -205,9 +209,9 @@ describe HttpStub::Configurer, "when the server is running" do
205
209
 
206
210
  end
207
211
 
208
- describe "and a request is made whose uri does not match the regular expression" do
212
+ context "and a request is made whose uri does not match the regular expression" do
209
213
 
210
- let(:response) { Net::HTTP.get_response("localhost", "/stub/no_match/regexp", 8001) }
214
+ let(:response) { Net::HTTP.get_response(server_host, "/stub/no_match/regexp", server_port) }
211
215
 
212
216
  it "should respond with a 404 status code" do
213
217
  response.code.should eql("404")
@@ -222,18 +226,18 @@ describe HttpStub::Configurer, "when the server is running" do
222
226
 
223
227
  end
224
228
 
225
- describe "that contains headers" do
229
+ context "that contains headers" do
226
230
 
227
- describe "whose values are strings" do
231
+ context "whose values are strings" do
228
232
 
229
233
  before(:each) do
230
234
  configurer.stub_response!("/stub_with_headers", method: :get, headers: { key: "value" },
231
235
  response: { status: 202, body: "Another stub body" })
232
236
  end
233
237
 
234
- describe "and that request is made" do
238
+ context "and that request is made" do
235
239
 
236
- let(:response) { HTTParty.get("http://localhost:8001/stub_with_headers", headers: { "key" => "value" }) }
240
+ let(:response) { HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "value" }) }
237
241
 
238
242
  it "should replay the stubbed response" do
239
243
  response.code.should eql(202)
@@ -242,11 +246,9 @@ describe HttpStub::Configurer, "when the server is running" do
242
246
 
243
247
  end
244
248
 
245
- describe "and a request with different headers is made" do
249
+ context "and a request with different headers is made" do
246
250
 
247
- let(:response) do
248
- HTTParty.get("http://localhost:8001/stub_with_headers", headers: { "key" => "other_value" })
249
- end
251
+ let(:response) { HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "other_value" }) }
250
252
 
251
253
  it "should respond with a 404 status code" do
252
254
  response.code.should eql(404)
@@ -256,17 +258,17 @@ describe HttpStub::Configurer, "when the server is running" do
256
258
 
257
259
  end
258
260
 
259
- describe "whose values are regular expressions" do
261
+ context "whose values are regular expressions" do
260
262
 
261
263
  before(:each) do
262
264
  configurer.stub_response!("/stub_with_headers", method: :get, headers: { key: /^match.*/ },
263
265
  response: { status: 202, body: "Another stub body" })
264
266
  end
265
267
 
266
- describe "and a request that matches is made" do
268
+ context "and a request that matches is made" do
267
269
 
268
270
  let(:response) do
269
- HTTParty.get("http://localhost:8001/stub_with_headers", headers: { "key" => "matching_value" })
271
+ HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "matching_value" })
270
272
  end
271
273
 
272
274
  it "should replay the stubbed response" do
@@ -276,10 +278,10 @@ describe HttpStub::Configurer, "when the server is running" do
276
278
 
277
279
  end
278
280
 
279
- describe "and a request that does not match is made" do
281
+ context "and a request that does not match is made" do
280
282
 
281
283
  let(:response) do
282
- HTTParty.get("http://localhost:8001/stub_with_headers", headers: { "key" => "does_not_match_value" })
284
+ HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "does_not_match_value" })
283
285
  end
284
286
 
285
287
  it "should respond with a 404 status code" do
@@ -292,18 +294,18 @@ describe HttpStub::Configurer, "when the server is running" do
292
294
 
293
295
  end
294
296
 
295
- describe "that contains parameters" do
297
+ context "that contains parameters" do
296
298
 
297
- describe "whose values are strings" do
299
+ context "whose values are strings" do
298
300
 
299
301
  before(:each) do
300
302
  configurer.stub_response!("/stub_with_parameters", method: :get, parameters: { key: "value" },
301
303
  response: { status: 202, body: "Another stub body" })
302
304
  end
303
305
 
304
- describe "and that request is made" do
306
+ context "and that request is made" do
305
307
 
306
- let(:response) { Net::HTTP.get_response("localhost", "/stub_with_parameters?key=value", 8001) }
308
+ let(:response) { Net::HTTP.get_response(server_host, "/stub_with_parameters?key=value", server_port) }
307
309
 
308
310
  it "should replay the stubbed response" do
309
311
  response.code.should eql("202")
@@ -312,9 +314,11 @@ describe HttpStub::Configurer, "when the server is running" do
312
314
 
313
315
  end
314
316
 
315
- describe "and a request with different parameters is made" do
317
+ context "and a request with different parameters is made" do
316
318
 
317
- let(:response) { Net::HTTP.get_response("localhost", "/stub_with_parameters?key=another_value", 8001) }
319
+ let(:response) do
320
+ Net::HTTP.get_response(server_host, "/stub_with_parameters?key=another_value", server_port)
321
+ end
318
322
 
319
323
  it "should respond with a 404 status code" do
320
324
  response.code.should eql("404")
@@ -324,16 +328,18 @@ describe HttpStub::Configurer, "when the server is running" do
324
328
 
325
329
  end
326
330
 
327
- describe "whose values are regular expressions" do
331
+ context "whose values are regular expressions" do
328
332
 
329
333
  before(:each) do
330
334
  configurer.stub_response!("/stub_with_parameters", method: :get, parameters: { key: /^match.*/ },
331
335
  response: { status: 202, body: "Another stub body" })
332
336
  end
333
337
 
334
- describe "and a request that matches is made" do
338
+ context "and a request that matches is made" do
335
339
 
336
- let(:response) { Net::HTTP.get_response("localhost", "/stub_with_parameters?key=matching_value", 8001) }
340
+ let(:response) do
341
+ Net::HTTP.get_response(server_host, "/stub_with_parameters?key=matching_value", server_port)
342
+ end
337
343
 
338
344
  it "should replay the stubbed response" do
339
345
  response.code.should eql("202")
@@ -342,10 +348,10 @@ describe HttpStub::Configurer, "when the server is running" do
342
348
 
343
349
  end
344
350
 
345
- describe "and a request that does not match is made" do
351
+ context "and a request that does not match is made" do
346
352
 
347
353
  let(:response) do
348
- Net::HTTP.get_response("localhost", "/stub_with_parameters?key=does_not_match_value", 8001)
354
+ Net::HTTP.get_response(server_host, "/stub_with_parameters?key=does_not_match_value", server_port)
349
355
  end
350
356
 
351
357
  it "should respond with a 404 status code" do
@@ -362,9 +368,9 @@ describe HttpStub::Configurer, "when the server is running" do
362
368
 
363
369
  end
364
370
 
365
- describe "and the configurer is uninitialized" do
371
+ context "and the configurer is uninitialized" do
366
372
 
367
- describe "and the configurer is informed that the server has started" do
373
+ context "and the configurer is informed that the server has started" do
368
374
 
369
375
  before(:each) { configurer.server_has_started! }
370
376
 
@@ -374,14 +380,14 @@ describe HttpStub::Configurer, "when the server is running" do
374
380
  activation_lambda.should raise_error(/error occurred activating '\/an_activator'/i)
375
381
  end
376
382
 
377
- describe "and an attempt is made to register a stub" do
383
+ context "and an attempt is made to register a stub" do
378
384
 
379
385
  before(:each) do
380
386
  configurer.stub_response!("/some_stub_path", method: :get, response: { body: "Some stub body"})
381
387
  end
382
388
 
383
389
  it "should register the stub" do
384
- response = Net::HTTP.get_response("localhost", "/some_stub_path", 8001)
390
+ response = Net::HTTP.get_response(server_host, "/some_stub_path", server_port)
385
391
 
386
392
  response.code.should eql("200")
387
393
  response.body.should eql("Some stub body")
@@ -389,7 +395,7 @@ describe HttpStub::Configurer, "when the server is running" do
389
395
 
390
396
  end
391
397
 
392
- describe "and an attempt is made to register a stub with a timeout" do
398
+ context "and an attempt is made to register a stub with a timeout" do
393
399
 
394
400
  before(:each) do
395
401
  configurer.stub_response!("/some_stub_path", method: :get, response: {:delay_in_seconds => 2})
@@ -398,7 +404,7 @@ describe HttpStub::Configurer, "when the server is running" do
398
404
  it "should delegate to request pipeline" do
399
405
  before = Time.new
400
406
 
401
- response = Net::HTTP.get_response("localhost", "/some_stub_path", 8001)
407
+ response = Net::HTTP.get_response(server_host, "/some_stub_path", server_port)
402
408
  response.code.should eql("200")
403
409
 
404
410
  after = Time.now
@@ -423,9 +429,9 @@ describe HttpStub::Configurer, "when the server is running" do
423
429
 
424
430
  end
425
431
 
426
- describe "and the configurer has not been informed that the server has started" do
432
+ context "and the configurer has not been informed that the server has started" do
427
433
 
428
- describe "and an attempt is made to activate a stub" do
434
+ context "and an attempt is made to activate a stub" do
429
435
 
430
436
  it "should raise an exception indicating an error occurred during activation" do
431
437
  activation_lambda = lambda { configurer.activate!("/an_activator") }
@@ -6,11 +6,15 @@ describe HttpStub::Server, "when the server is running" do
6
6
 
7
7
  describe "and a configurer with multiple stub activators is initialized" do
8
8
 
9
- before(:all) { HttpStub::Examples::ConfigurerWithManyActivators.initialize! }
9
+ before(:all) do
10
+ HttpStub::Examples::ConfigurerWithManyActivators.host server_host
11
+ HttpStub::Examples::ConfigurerWithManyActivators.port server_port
12
+ HttpStub::Examples::ConfigurerWithManyActivators.initialize!
13
+ end
10
14
 
11
15
  describe "GET #stubs/activators" do
12
16
 
13
- let(:response) { Net::HTTP.get_response("localhost", "/stubs/activators", 8001) }
17
+ let(:response) { Net::HTTP.get_response(server_host, "/stubs/activators", server_port) }
14
18
  let(:response_document) { Nokogiri::HTML(response.body) }
15
19
 
16
20
  it "should return a 200 response code" do
@@ -52,10 +56,10 @@ describe HttpStub::Server, "when the server is running" do
52
56
  describe "when multiple stubs are configured" do
53
57
 
54
58
  before(:all) do
55
- (1..3).each { |i| Net::HTTP.get_response("localhost", "/activator#{i}", 8001) }
59
+ (1..3).each { |i| Net::HTTP.get_response(server_host, "/activator#{i}", server_port) }
56
60
  end
57
61
 
58
- let(:response) { Net::HTTP.get_response("localhost", "/stubs", 8001) }
62
+ let(:response) { Net::HTTP.get_response(server_host, "/stubs", server_port) }
59
63
  let(:response_document) { Nokogiri::HTML(response.body) }
60
64
 
61
65
  it "should return a 200 response code" do
@@ -2,11 +2,21 @@ shared_context "server integration" do
2
2
 
3
3
  before(:all) do
4
4
  @pid = Process.spawn("rake start_example_server --trace")
5
- ::Wait.until!("http stub server started") { Net::HTTP.get_response("localhost", "/", 8001) }
5
+ ::Wait.until!("http stub server started") { Net::HTTP.get_response(server_host, "/", server_port) }
6
6
  end
7
7
 
8
- after(:all) do
9
- Process.kill(9, @pid)
8
+ after(:all) { Process.kill(9, @pid) }
9
+
10
+ def server_host
11
+ "localhost"
12
+ end
13
+
14
+ def server_port
15
+ 8001
16
+ end
17
+
18
+ def server_uri
19
+ "http://#{server_host}:#{server_port}"
10
20
  end
11
21
 
12
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_stub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-17 00:00:00.000000000 Z
13
+ date: 2013-09-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
@@ -243,6 +243,7 @@ extensions: []
243
243
  extra_rdoc_files: []
244
244
  files:
245
245
  - ./lib/http_stub/configurer/command.rb
246
+ - ./lib/http_stub/configurer/command_processor.rb
246
247
  - ./lib/http_stub/configurer/impatient_command_chain.rb
247
248
  - ./lib/http_stub/configurer/patient_command_chain.rb
248
249
  - ./lib/http_stub/configurer/request/regexpable.rb
@@ -274,7 +275,7 @@ files:
274
275
  - ./lib/http_stub/views/stubs.haml
275
276
  - ./lib/http_stub.rb
276
277
  - ./spec/curl_samples.txt
277
- - ./spec/lib/http_stub/configurer/command_integration_spec.rb
278
+ - ./spec/lib/http_stub/configurer/command_processor_integration_spec.rb
278
279
  - ./spec/lib/http_stub/configurer/command_spec.rb
279
280
  - ./spec/lib/http_stub/configurer/impatient_command_chain_spec.rb
280
281
  - ./spec/lib/http_stub/configurer/patient_command_chain_spec.rb
@@ -323,16 +324,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
324
  version: '0'
324
325
  segments:
325
326
  - 0
326
- hash: 1728406266310263637
327
+ hash: -682079675256504767
327
328
  requirements: []
328
329
  rubyforge_project: http_stub
329
- rubygems_version: 1.8.23
330
+ rubygems_version: 1.8.25
330
331
  signing_key:
331
332
  specification_version: 3
332
333
  summary: A HTTP Server replaying configured stub responses.
333
334
  test_files:
334
335
  - ./spec/curl_samples.txt
335
- - ./spec/lib/http_stub/configurer/command_integration_spec.rb
336
+ - ./spec/lib/http_stub/configurer/command_processor_integration_spec.rb
336
337
  - ./spec/lib/http_stub/configurer/command_spec.rb
337
338
  - ./spec/lib/http_stub/configurer/impatient_command_chain_spec.rb
338
339
  - ./spec/lib/http_stub/configurer/patient_command_chain_spec.rb
@@ -1,33 +0,0 @@
1
- describe HttpStub::Configurer::Command, "when the server is running" do
2
- include_context "server integration"
3
-
4
- let(:command) do
5
- HttpStub::Configurer::Command.new(host: "localhost", port: 8001,
6
- request: request, description: "performing an operation")
7
- end
8
-
9
- describe "#execute" do
10
-
11
- describe "when the server responds with a 200 response" do
12
-
13
- let(:request) { Net::HTTP::Get.new("/stubs") }
14
-
15
- it "should execute without error" do
16
- lambda { command.execute() }.should_not raise_error
17
- end
18
-
19
- end
20
-
21
- describe "when the server responds with a non-200 response" do
22
-
23
- let(:request) { Net::HTTP::Get.new("/causes_error") }
24
-
25
- it "should raise an exception that includes the commands description" do
26
- lambda { command.execute() }.should raise_error(/performing an operation/)
27
- end
28
-
29
- end
30
-
31
- end
32
-
33
- end