http_stub 0.14.2 → 0.15.0
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.
- checksums.yaml +4 -4
- data/lib/http_stub/configurer/request/http/basic.rb +21 -0
- data/lib/http_stub/configurer/request/http/factory.rb +43 -0
- data/lib/http_stub/configurer/request/http/multipart.rb +33 -0
- data/lib/http_stub/configurer/request/stub.rb +24 -8
- data/lib/http_stub/configurer/request/stub_activator.rb +12 -8
- data/lib/http_stub/configurer/request/{stub_activator_payload_builder.rb → stub_activator_builder.rb} +4 -4
- data/lib/http_stub/configurer/request/stub_builder.rb +34 -0
- data/lib/http_stub/configurer/request/stub_response.rb +40 -0
- data/lib/http_stub/configurer/request/stub_response_file.rb +20 -0
- data/lib/http_stub/configurer/server/command.rb +5 -1
- data/lib/http_stub/configurer/server/command_processor.rb +1 -1
- data/lib/http_stub/configurer/server/dsl.rb +4 -4
- data/lib/http_stub/configurer/server/facade.rb +25 -11
- data/lib/http_stub/extensions/core/hash.rb +26 -0
- data/lib/http_stub/rake/server_daemon_tasks.rb +1 -1
- data/lib/http_stub/rake/server_tasks.rb +1 -1
- data/lib/http_stub/rake/task_generators.rb +3 -3
- data/lib/http_stub/server/application.rb +117 -0
- data/lib/http_stub/server/daemon.rb +39 -0
- data/lib/http_stub/{models → server}/exact_value_matcher.rb +1 -1
- data/lib/http_stub/{models → server}/hash_with_string_value_matchers.rb +2 -2
- data/lib/http_stub/{models → server}/headers.rb +1 -1
- data/lib/http_stub/{models → server}/omitted_value_matcher.rb +1 -1
- data/lib/http_stub/{models → server}/regexp_value_matcher.rb +1 -1
- data/lib/http_stub/{models → server}/registry.rb +10 -3
- data/lib/http_stub/{models → server}/request_header_parser.rb +1 -1
- data/lib/http_stub/server/response.rb +13 -0
- data/lib/http_stub/server/response_pipeline.rb +18 -0
- data/lib/http_stub/{models → server}/string_value_matcher.rb +4 -4
- data/lib/http_stub/server/stub.rb +37 -0
- data/lib/http_stub/{models → server}/stub_activator.rb +10 -2
- data/lib/http_stub/{controllers → server}/stub_activator_controller.rb +5 -5
- data/lib/http_stub/{controllers → server}/stub_controller.rb +4 -4
- data/lib/http_stub/server/stub_factory.rb +30 -0
- data/lib/http_stub/{models → server}/stub_headers.rb +4 -4
- data/lib/http_stub/{models → server}/stub_parameters.rb +2 -2
- data/lib/http_stub/{models → server}/stub_registry.rb +4 -4
- data/lib/http_stub/server/stub_response/base.rb +62 -0
- data/lib/http_stub/server/stub_response/file.rb +48 -0
- data/lib/http_stub/server/stub_response/text.rb +17 -0
- data/lib/http_stub/server/stub_response.rb +14 -0
- data/lib/http_stub/{models → server}/stub_triggers.rb +6 -2
- data/lib/http_stub/{models → server}/stub_uri.rb +2 -2
- data/lib/http_stub/{views → server/views}/_stub.haml +0 -0
- data/lib/http_stub/{views → server/views}/application.sass +0 -0
- data/lib/http_stub/{views → server/views}/layout.haml +0 -0
- data/lib/http_stub/{views → server/views}/stub_activators.haml +0 -0
- data/lib/http_stub/{views → server/views}/stubs.haml +0 -0
- data/lib/http_stub/version.rb +1 -1
- data/lib/http_stub.rb +41 -24
- data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +2 -2
- data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +15 -0
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +148 -0
- data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +74 -0
- data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +119 -0
- data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +24 -22
- data/spec/lib/http_stub/configurer/request/stub_builder_spec.rb +154 -0
- data/spec/lib/http_stub/configurer/request/stub_response_spec.rb +136 -0
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +238 -17
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +7 -3
- data/spec/lib/http_stub/configurer/server/command_spec.rb +7 -6
- data/spec/lib/http_stub/configurer/server/dsl_spec.rb +58 -94
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +56 -41
- data/spec/lib/http_stub/configurer_integration_spec.rb +180 -81
- data/spec/lib/http_stub/{hash_extensions_spec.rb → extensions/core/hash_spec.rb} +1 -1
- data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +1 -1
- data/spec/lib/http_stub/{server_integration_spec.rb → server/application_integration_spec.rb} +1 -1
- data/spec/lib/http_stub/server/application_spec.rb +205 -0
- data/spec/lib/http_stub/server/daemon_integration_spec.rb +7 -0
- data/spec/lib/http_stub/{server_daemon_spec.rb → server/daemon_spec.rb} +4 -4
- data/spec/lib/http_stub/{models → server}/exact_value_matcher_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/hash_with_string_value_matchers_spec.rb +5 -5
- data/spec/lib/http_stub/{models → server}/headers_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/omitted_value_matcher_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/regexp_value_matcher_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/registry_spec.rb +52 -55
- data/spec/lib/http_stub/{models → server}/request_header_parser_spec.rb +4 -4
- data/spec/lib/http_stub/server/response_pipeline_spec.rb +29 -0
- data/spec/lib/http_stub/server/response_spec.rb +41 -0
- data/spec/lib/http_stub/{models → server}/string_value_matcher_spec.rb +11 -11
- data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +85 -0
- data/spec/lib/http_stub/server/stub_activator_spec.rb +124 -0
- data/spec/lib/http_stub/server/stub_controller_spec.rb +74 -0
- data/spec/lib/http_stub/server/stub_factory_spec.rb +117 -0
- data/spec/lib/http_stub/{models → server}/stub_headers_spec.rb +9 -9
- data/spec/lib/http_stub/{models → server}/stub_parameters_spec.rb +6 -6
- data/spec/lib/http_stub/{models → server}/stub_registry_integration_spec.rb +3 -3
- data/spec/lib/http_stub/{models → server}/stub_registry_spec.rb +15 -35
- data/spec/lib/http_stub/server/stub_response/base_spec.rb +225 -0
- data/spec/lib/http_stub/server/stub_response/file_spec.rb +140 -0
- data/spec/lib/http_stub/server/stub_response/text_spec.rb +103 -0
- data/spec/lib/http_stub/server/stub_response_spec.rb +49 -0
- data/spec/lib/http_stub/{models → server}/stub_spec.rb +34 -18
- data/spec/lib/http_stub/{models → server}/stub_triggers_spec.rb +26 -16
- data/spec/lib/http_stub/{models → server}/stub_uri_spec.rb +5 -5
- data/spec/resources/sample.pdf +0 -0
- data/spec/resources/sample.txt +1 -0
- data/spec/spec_helper.rb +13 -4
- data/spec/support/stub_fixture.rb +106 -0
- metadata +148 -102
- data/lib/http_stub/configurer/request/stub_payload_builder.rb +0 -46
- data/lib/http_stub/hash_extensions.rb +0 -22
- data/lib/http_stub/models/request_pipeline.rb +0 -13
- data/lib/http_stub/models/response.rb +0 -43
- data/lib/http_stub/models/stub.rb +0 -35
- data/lib/http_stub/server.rb +0 -114
- data/lib/http_stub/server_daemon.rb +0 -36
- data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +0 -103
- data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +0 -304
- data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +0 -94
- data/spec/lib/http_stub/controllers/stub_controller_spec.rb +0 -83
- data/spec/lib/http_stub/models/request_pipeline_spec.rb +0 -17
- data/spec/lib/http_stub/models/response_spec.rb +0 -206
- data/spec/lib/http_stub/models/stub_activator_spec.rb +0 -76
- data/spec/lib/http_stub/server_daemon_integration_spec.rb +0 -7
- data/spec/lib/http_stub/server_spec.rb +0 -234
- data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +0 -27
|
@@ -23,10 +23,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
23
23
|
|
|
24
24
|
context "and the stub request is made" do
|
|
25
25
|
|
|
26
|
-
let(:response) {
|
|
26
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_path") }
|
|
27
27
|
|
|
28
28
|
it "replays the stubbed response" do
|
|
29
|
-
expect(response.code).to eql(
|
|
29
|
+
expect(response.code).to eql(200)
|
|
30
30
|
expect(response.body).to eql("Stub activator body")
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -38,10 +38,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
38
38
|
|
|
39
39
|
context "and the stub request is made" do
|
|
40
40
|
|
|
41
|
-
let(:response) {
|
|
41
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_path") }
|
|
42
42
|
|
|
43
43
|
it "responds with a 404 status code" do
|
|
44
|
-
expect(response.code).to eql(
|
|
44
|
+
expect(response.code).to eql(404)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
end
|
|
@@ -53,9 +53,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
53
53
|
let(:configurer) { HttpStub::Examples::ConfigurerWithClassStub.new }
|
|
54
54
|
|
|
55
55
|
it "registers the stub" do
|
|
56
|
-
response =
|
|
56
|
+
response = HTTParty.get("#{server_uri}/a_class_stub")
|
|
57
57
|
|
|
58
|
-
expect(response.code).to eql(
|
|
58
|
+
expect(response.code).to eql(201)
|
|
59
59
|
expect(response.body).to eql("Class stub body")
|
|
60
60
|
end
|
|
61
61
|
|
|
@@ -67,12 +67,14 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
67
67
|
|
|
68
68
|
context "and the configurer is re-initialized" do
|
|
69
69
|
|
|
70
|
-
before(:example)
|
|
70
|
+
before(:example) do
|
|
71
|
+
configurer.class.initialize!
|
|
72
|
+
end
|
|
71
73
|
|
|
72
74
|
it "re-establishes the class stub as having priority" do
|
|
73
|
-
response =
|
|
75
|
+
response = HTTParty.get("#{server_uri}/a_class_stub")
|
|
74
76
|
|
|
75
|
-
expect(response.code).to eql(
|
|
77
|
+
expect(response.code).to eql(201)
|
|
76
78
|
expect(response.body).to eql("Class stub body")
|
|
77
79
|
end
|
|
78
80
|
|
|
@@ -87,16 +89,16 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
87
89
|
let(:configurer) { HttpStub::Examples::ConfigurerWithComplexInitializer.new }
|
|
88
90
|
|
|
89
91
|
it "registers the activated activator" do
|
|
90
|
-
response =
|
|
92
|
+
response = HTTParty.get("#{server_uri}/activated_during_initialization_stub_path")
|
|
91
93
|
|
|
92
|
-
expect(response.code).to eql(
|
|
94
|
+
expect(response.code).to eql(200)
|
|
93
95
|
expect(response.body).to eql("Activated during initialization body")
|
|
94
96
|
end
|
|
95
97
|
|
|
96
98
|
it "registers the stub" do
|
|
97
|
-
response =
|
|
99
|
+
response = HTTParty.get("#{server_uri}/stubbed_during_initialization_path")
|
|
98
100
|
|
|
99
|
-
expect(response.code).to eql(
|
|
101
|
+
expect(response.code).to eql(200)
|
|
100
102
|
expect(response.body).to eql("Stubbed during initialization body")
|
|
101
103
|
end
|
|
102
104
|
|
|
@@ -111,22 +113,22 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
111
113
|
before(:example) { configurer.recall_stubs! }
|
|
112
114
|
|
|
113
115
|
it "removes the stub registered post-initialization" do
|
|
114
|
-
response =
|
|
116
|
+
response = HTTParty.get("#{server_uri}/another_stub")
|
|
115
117
|
|
|
116
|
-
expect(response.code).to eql(
|
|
118
|
+
expect(response.code).to eql(404)
|
|
117
119
|
end
|
|
118
120
|
|
|
119
121
|
it "retains the activated activator during initialization" do
|
|
120
|
-
response =
|
|
122
|
+
response = HTTParty.get("#{server_uri}/activated_during_initialization_stub_path")
|
|
121
123
|
|
|
122
|
-
expect(response.code).to eql(
|
|
124
|
+
expect(response.code).to eql(200)
|
|
123
125
|
expect(response.body).to eql("Activated during initialization body")
|
|
124
126
|
end
|
|
125
127
|
|
|
126
128
|
it "retains the stub registered during initialization" do
|
|
127
|
-
response =
|
|
129
|
+
response = HTTParty.get("#{server_uri}/stubbed_during_initialization_path")
|
|
128
130
|
|
|
129
|
-
expect(response.code).to eql(
|
|
131
|
+
expect(response.code).to eql(200)
|
|
130
132
|
expect(response.body).to eql("Stubbed during initialization body")
|
|
131
133
|
end
|
|
132
134
|
|
|
@@ -148,10 +150,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
148
150
|
|
|
149
151
|
context "and that request is made" do
|
|
150
152
|
|
|
151
|
-
let(:response) {
|
|
153
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_status") }
|
|
152
154
|
|
|
153
155
|
it "responds with the stubbed status" do
|
|
154
|
-
expect(response.code).to eql(
|
|
156
|
+
expect(response.code).to eql(201)
|
|
155
157
|
end
|
|
156
158
|
|
|
157
159
|
it "replays the stubbed body" do
|
|
@@ -166,10 +168,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
166
168
|
|
|
167
169
|
context "and the original request is made" do
|
|
168
170
|
|
|
169
|
-
let(:response) {
|
|
171
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_status") }
|
|
170
172
|
|
|
171
173
|
it "responds with a 404 status code" do
|
|
172
|
-
expect(response.code).to eql(
|
|
174
|
+
expect(response.code).to eql(404)
|
|
173
175
|
end
|
|
174
176
|
|
|
175
177
|
end
|
|
@@ -186,7 +188,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
186
188
|
|
|
187
189
|
context "and that request is made" do
|
|
188
190
|
|
|
189
|
-
let(:response) {
|
|
191
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_without_status") }
|
|
190
192
|
|
|
191
193
|
it "responds with the stubbed body" do
|
|
192
194
|
expect(response.body).to eql("Stub body")
|
|
@@ -202,7 +204,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
202
204
|
|
|
203
205
|
context "and a request is made whose uri matches the regular expression" do
|
|
204
206
|
|
|
205
|
-
let(:response) {
|
|
207
|
+
let(:response) { HTTParty.get("#{server_uri}/match/stub/regexp/$key=value") }
|
|
206
208
|
|
|
207
209
|
it "responds with the stubbed body" do
|
|
208
210
|
expect(response.body).to eql("Stub body")
|
|
@@ -212,10 +214,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
212
214
|
|
|
213
215
|
context "and a request is made whose uri does not match the regular expression" do
|
|
214
216
|
|
|
215
|
-
let(:response) {
|
|
217
|
+
let(:response) { HTTParty.get("#{server_uri}/stub/no_match/regexp") }
|
|
216
218
|
|
|
217
219
|
it "responds with a 404 status code" do
|
|
218
|
-
expect(response.code).to eql(
|
|
220
|
+
expect(response.code).to eql(404)
|
|
219
221
|
end
|
|
220
222
|
|
|
221
223
|
end
|
|
@@ -310,10 +312,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
310
312
|
|
|
311
313
|
context "and that request is made" do
|
|
312
314
|
|
|
313
|
-
let(:response) {
|
|
315
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters?key=value") }
|
|
314
316
|
|
|
315
317
|
it "replays the stubbed response" do
|
|
316
|
-
expect(response.code).to eql(
|
|
318
|
+
expect(response.code).to eql(202)
|
|
317
319
|
expect(response.body).to eql("Another stub body")
|
|
318
320
|
end
|
|
319
321
|
|
|
@@ -321,12 +323,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
321
323
|
|
|
322
324
|
context "and a request with different parameters is made" do
|
|
323
325
|
|
|
324
|
-
let(:response)
|
|
325
|
-
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=another_value", server_port)
|
|
326
|
-
end
|
|
326
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters?key=another_value") }
|
|
327
327
|
|
|
328
328
|
it "responds with a 404 status code" do
|
|
329
|
-
expect(response.code).to eql(
|
|
329
|
+
expect(response.code).to eql(404)
|
|
330
330
|
end
|
|
331
331
|
|
|
332
332
|
end
|
|
@@ -344,12 +344,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
344
344
|
|
|
345
345
|
context "and a request that matches is made" do
|
|
346
346
|
|
|
347
|
-
let(:response)
|
|
348
|
-
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=matching_value", server_port)
|
|
349
|
-
end
|
|
347
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters?key=matching_value") }
|
|
350
348
|
|
|
351
349
|
it "replays the stubbed response" do
|
|
352
|
-
expect(response.code).to eql(
|
|
350
|
+
expect(response.code).to eql(202)
|
|
353
351
|
expect(response.body).to eql("Another stub body")
|
|
354
352
|
end
|
|
355
353
|
|
|
@@ -357,12 +355,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
357
355
|
|
|
358
356
|
context "and a request that does not match is made" do
|
|
359
357
|
|
|
360
|
-
let(:response)
|
|
361
|
-
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=does_not_match_value", server_port)
|
|
362
|
-
end
|
|
358
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters?key=does_not_match_value") }
|
|
363
359
|
|
|
364
360
|
it "responds with a 404 status code" do
|
|
365
|
-
expect(response.code).to eql(
|
|
361
|
+
expect(response.code).to eql(404)
|
|
366
362
|
end
|
|
367
363
|
|
|
368
364
|
end
|
|
@@ -380,10 +376,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
380
376
|
|
|
381
377
|
context "and a request that matches is made" do
|
|
382
378
|
|
|
383
|
-
let(:response) {
|
|
379
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_omitted_parameters") }
|
|
384
380
|
|
|
385
381
|
it "replays the stubbed response" do
|
|
386
|
-
expect(response.code).to eql(
|
|
382
|
+
expect(response.code).to eql(202)
|
|
387
383
|
expect(response.body).to eql("Omitted parameter stub body")
|
|
388
384
|
end
|
|
389
385
|
|
|
@@ -391,12 +387,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
391
387
|
|
|
392
388
|
context "and a request that does not match is made" do
|
|
393
389
|
|
|
394
|
-
let(:response)
|
|
395
|
-
Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters?key=must_be_omitted", server_port)
|
|
396
|
-
end
|
|
390
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_omitted_parameters?key=must_be_omitted") }
|
|
397
391
|
|
|
398
392
|
it "responds with a 404 status code" do
|
|
399
|
-
expect(response.code).to eql(
|
|
393
|
+
expect(response.code).to eql(404)
|
|
400
394
|
end
|
|
401
395
|
|
|
402
396
|
end
|
|
@@ -412,10 +406,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
412
406
|
|
|
413
407
|
context "and that request is made" do
|
|
414
408
|
|
|
415
|
-
let(:response) {
|
|
409
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters?key=88") }
|
|
416
410
|
|
|
417
411
|
it "replays the stubbed response" do
|
|
418
|
-
expect(response.code).to eql(
|
|
412
|
+
expect(response.code).to eql(203)
|
|
419
413
|
expect(response.body).to eql("Body for parameter number")
|
|
420
414
|
end
|
|
421
415
|
|
|
@@ -434,12 +428,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
434
428
|
|
|
435
429
|
context "and a request that matches is made" do
|
|
436
430
|
|
|
437
|
-
let(:response)
|
|
438
|
-
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=matching_value", server_port)
|
|
439
|
-
end
|
|
431
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters?key=matching_value") }
|
|
440
432
|
|
|
441
433
|
it "replays the stubbed response" do
|
|
442
|
-
expect(response.code).to eql(
|
|
434
|
+
expect(response.code).to eql(202)
|
|
443
435
|
expect(response.body).to eql("Another stub body")
|
|
444
436
|
end
|
|
445
437
|
|
|
@@ -447,12 +439,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
447
439
|
|
|
448
440
|
context "and a request that does not match is made" do
|
|
449
441
|
|
|
450
|
-
let(:response)
|
|
451
|
-
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=does_not_match_value", server_port)
|
|
452
|
-
end
|
|
442
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_parameters?key=does_not_match_value") }
|
|
453
443
|
|
|
454
444
|
it "responds with a 404 status code" do
|
|
455
|
-
expect(response.code).to eql(
|
|
445
|
+
expect(response.code).to eql(404)
|
|
456
446
|
end
|
|
457
447
|
|
|
458
448
|
end
|
|
@@ -470,10 +460,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
470
460
|
|
|
471
461
|
context "and a request that matches is made" do
|
|
472
462
|
|
|
473
|
-
let(:response) {
|
|
463
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_omitted_parameters") }
|
|
474
464
|
|
|
475
465
|
it "replays the stubbed response" do
|
|
476
|
-
expect(response.code).to eql(
|
|
466
|
+
expect(response.code).to eql(202)
|
|
477
467
|
expect(response.body).to eql("Omitted parameter stub body")
|
|
478
468
|
end
|
|
479
469
|
|
|
@@ -481,12 +471,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
481
471
|
|
|
482
472
|
context "and a request that does not match is made" do
|
|
483
473
|
|
|
484
|
-
let(:response)
|
|
485
|
-
Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters?key=must_be_omitted", server_port)
|
|
486
|
-
end
|
|
474
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_with_omitted_parameters?key=must_be_omitted") }
|
|
487
475
|
|
|
488
476
|
it "responds with a 404 status code" do
|
|
489
|
-
expect(response.code).to eql(
|
|
477
|
+
expect(response.code).to eql(404)
|
|
490
478
|
end
|
|
491
479
|
|
|
492
480
|
end
|
|
@@ -495,7 +483,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
495
483
|
|
|
496
484
|
end
|
|
497
485
|
|
|
498
|
-
context "that contains triggers" do
|
|
486
|
+
context "that contains triggers with simple response bodies" do
|
|
499
487
|
|
|
500
488
|
let(:triggered_stubs) do
|
|
501
489
|
(1..3).map do |trigger_number|
|
|
@@ -516,12 +504,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
516
504
|
|
|
517
505
|
context "and a request is made matching the stub" do
|
|
518
506
|
|
|
519
|
-
before(:example)
|
|
520
|
-
@stub_with_triggers_response = Net::HTTP.get_response(server_host, "/stub_with_triggers", server_port)
|
|
521
|
-
end
|
|
507
|
+
before(:example) { @stub_with_triggers_response = HTTParty.get("#{server_uri}/stub_with_triggers") }
|
|
522
508
|
|
|
523
509
|
it "replays the stubbed response" do
|
|
524
|
-
expect(@stub_with_triggers_response.code).to eql(
|
|
510
|
+
expect(@stub_with_triggers_response.code).to eql(200)
|
|
525
511
|
expect(@stub_with_triggers_response.body).to eql("Trigger stub body")
|
|
526
512
|
end
|
|
527
513
|
|
|
@@ -529,10 +515,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
529
515
|
|
|
530
516
|
context "and then a request matching triggered stub ##{trigger_number} is made" do
|
|
531
517
|
|
|
532
|
-
let(:response) {
|
|
518
|
+
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_#{trigger_number}") }
|
|
533
519
|
|
|
534
520
|
it "replays the triggered response" do
|
|
535
|
-
expect(response.code).to eql("20#{trigger_number}")
|
|
521
|
+
expect(response.code).to eql("20#{trigger_number}".to_i)
|
|
536
522
|
expect(response.body).to eql("Triggered stub body #{trigger_number}")
|
|
537
523
|
end
|
|
538
524
|
|
|
@@ -544,6 +530,91 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
544
530
|
|
|
545
531
|
end
|
|
546
532
|
|
|
533
|
+
context "that contains triggers with a mix of file and text responses" do
|
|
534
|
+
|
|
535
|
+
let(:pdf_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/sample.pdf" }
|
|
536
|
+
let(:pdf_file_trigger) do
|
|
537
|
+
stub_server.build_stub do |stub|
|
|
538
|
+
stub.match_requests("/triggered_stub_pdf_file", method: :get)
|
|
539
|
+
stub.respond_with(
|
|
540
|
+
status: 201,
|
|
541
|
+
headers: { "content-type" => "application/pdf" },
|
|
542
|
+
body: { file: { path: pdf_file_path, name: ::File.basename(pdf_file_path) } }
|
|
543
|
+
)
|
|
544
|
+
end
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
let(:text_body) { "Sample trigger stub body" }
|
|
548
|
+
let(:text_trigger) do
|
|
549
|
+
stub_server.build_stub do |stub|
|
|
550
|
+
stub.match_requests("/triggered_stub_text", method: :get)
|
|
551
|
+
stub.respond_with(status: 202, body: "Sample trigger stub body")
|
|
552
|
+
end
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
let(:txt_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/sample.txt" }
|
|
556
|
+
let(:txt_file_trigger) do
|
|
557
|
+
stub_server.build_stub do |stub|
|
|
558
|
+
stub.match_requests("/triggered_stub_txt_file", method: :get)
|
|
559
|
+
stub.respond_with(
|
|
560
|
+
status: 203,
|
|
561
|
+
headers: { "content-type" => "text/plain" },
|
|
562
|
+
body: { file: { path: txt_file_path, name: ::File.basename(txt_file_path) } }
|
|
563
|
+
)
|
|
564
|
+
end
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
let(:triggered_stubs) { [ pdf_file_trigger, text_trigger, txt_file_trigger ] }
|
|
568
|
+
|
|
569
|
+
before(:example) do
|
|
570
|
+
stub_server.add_stub! do |stub|
|
|
571
|
+
stub.match_requests("/stub_with_triggers", method: :get)
|
|
572
|
+
stub.respond_with(body: "Trigger stub body")
|
|
573
|
+
stub.trigger(triggered_stubs)
|
|
574
|
+
end
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
context "and a request is made matching the stub" do
|
|
578
|
+
|
|
579
|
+
before(:example) { HTTParty.get("#{server_uri}/stub_with_triggers") }
|
|
580
|
+
|
|
581
|
+
context "and then a request matching a triggered stub returning a PDF file is made" do
|
|
582
|
+
|
|
583
|
+
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_pdf_file") }
|
|
584
|
+
|
|
585
|
+
it "replays the triggered response" do
|
|
586
|
+
expect(response.code).to eql(201)
|
|
587
|
+
assert_response_contains_file(pdf_file_path)
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
end
|
|
591
|
+
|
|
592
|
+
context "and then a request matching a triggered stub returning texrt is made" do
|
|
593
|
+
|
|
594
|
+
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_text") }
|
|
595
|
+
|
|
596
|
+
it "replays the triggered response" do
|
|
597
|
+
expect(response.code).to eql(202)
|
|
598
|
+
expect(response.body).to eql(text_body)
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
context "and then a request matching a triggered stub returning a text file is made" do
|
|
604
|
+
|
|
605
|
+
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_txt_file") }
|
|
606
|
+
|
|
607
|
+
it "replays the triggered response" do
|
|
608
|
+
expect(response.code).to eql(203)
|
|
609
|
+
expect(response.parsed_response).to eql(::File.read(txt_file_path))
|
|
610
|
+
end
|
|
611
|
+
|
|
612
|
+
end
|
|
613
|
+
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
end
|
|
617
|
+
|
|
547
618
|
end
|
|
548
619
|
|
|
549
620
|
context "and the configurer contains an on initialize callback" do
|
|
@@ -551,9 +622,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
551
622
|
let(:configurer) { HttpStub::Examples::ConfigurerWithInitializeCallback.new }
|
|
552
623
|
|
|
553
624
|
it "executes the callback" do
|
|
554
|
-
response =
|
|
625
|
+
response = HTTParty.get("#{server_uri}/stubbed_on_initialize_path")
|
|
555
626
|
|
|
556
|
-
expect(response.code).to eql(
|
|
627
|
+
expect(response.code).to eql(200)
|
|
557
628
|
expect(response.body).to eql("Stubbed on initialize body")
|
|
558
629
|
end
|
|
559
630
|
|
|
@@ -571,6 +642,26 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
571
642
|
|
|
572
643
|
end
|
|
573
644
|
|
|
645
|
+
context "and the configurer stubs a response with a file body" do
|
|
646
|
+
|
|
647
|
+
let(:configurer) { HttpStub::Examples::ConfigurerWithFileResponse.new }
|
|
648
|
+
|
|
649
|
+
context "and a request that matches is made" do
|
|
650
|
+
|
|
651
|
+
let(:response) { HTTParty.get("#{server_uri}/stub_response_with_file") }
|
|
652
|
+
|
|
653
|
+
it "responds with the configured status code" do
|
|
654
|
+
expect(response.code).to eql(200)
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
it "responds with the file" do
|
|
658
|
+
assert_response_contains_file(HttpStub::Examples::ConfigurerWithFileResponse::FILE_PATH)
|
|
659
|
+
end
|
|
660
|
+
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
end
|
|
664
|
+
|
|
574
665
|
end
|
|
575
666
|
|
|
576
667
|
context "and the configurer is uninitialized" do
|
|
@@ -588,13 +679,13 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
588
679
|
context "and an attempt is made to register a stub" do
|
|
589
680
|
|
|
590
681
|
before(:example) do
|
|
591
|
-
configurer.stub_response!("/some_stub_path", method: :get, response: { body: "Some stub body"})
|
|
682
|
+
configurer.stub_response!("/some_stub_path", method: :get, response: { body: "Some stub body" })
|
|
592
683
|
end
|
|
593
684
|
|
|
594
685
|
it "registers the stub" do
|
|
595
|
-
response =
|
|
686
|
+
response = HTTParty.get("#{server_uri}/some_stub_path")
|
|
596
687
|
|
|
597
|
-
expect(response.code).to eql(
|
|
688
|
+
expect(response.code).to eql(200)
|
|
598
689
|
expect(response.body).to eql("Some stub body")
|
|
599
690
|
end
|
|
600
691
|
|
|
@@ -603,14 +694,14 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
603
694
|
context "and an attempt is made to register a stub with a timeout" do
|
|
604
695
|
|
|
605
696
|
before(:example) do
|
|
606
|
-
configurer.stub_response!("/some_stub_path", method: :get, response: {:
|
|
697
|
+
configurer.stub_response!("/some_stub_path", method: :get, response: { delay_in_seconds: 2 })
|
|
607
698
|
end
|
|
608
699
|
|
|
609
700
|
it "delegates to request pipeline" do
|
|
610
701
|
before = Time.new
|
|
611
702
|
|
|
612
|
-
response =
|
|
613
|
-
expect(response.code).to eql(
|
|
703
|
+
response = HTTParty.get("#{server_uri}/some_stub_path")
|
|
704
|
+
expect(response.code).to eql(200)
|
|
614
705
|
|
|
615
706
|
after = Time.now
|
|
616
707
|
|
|
@@ -629,7 +720,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
629
720
|
end
|
|
630
721
|
|
|
631
722
|
it "registers the stub" do
|
|
632
|
-
response =
|
|
723
|
+
response = HTTParty.get("#{server_uri}/some_stub_path")
|
|
633
724
|
|
|
634
725
|
expect(response.content_type).to eql("application/xhtml")
|
|
635
726
|
end
|
|
@@ -681,13 +772,21 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
|
681
772
|
let(:configurer) { HttpStub::Examples::ConfigurerWithInitializeCallback.new }
|
|
682
773
|
|
|
683
774
|
it "does not execute the callback" do
|
|
684
|
-
response =
|
|
775
|
+
response = HTTParty.get("#{server_uri}/stubbed_on_initialize_path")
|
|
685
776
|
|
|
686
|
-
expect(response.code).to eql(
|
|
777
|
+
expect(response.code).to eql(404)
|
|
687
778
|
end
|
|
688
779
|
|
|
689
780
|
end
|
|
690
781
|
|
|
691
782
|
end
|
|
692
783
|
|
|
784
|
+
def assert_response_contains_file(path)
|
|
785
|
+
response_file = Tempfile.new(File.basename(path)).tap do |file|
|
|
786
|
+
file.write(response.parsed_response)
|
|
787
|
+
file.flush
|
|
788
|
+
end
|
|
789
|
+
expect(FileUtils.compare_file(path, response_file.path)).to be(true)
|
|
790
|
+
end
|
|
791
|
+
|
|
693
792
|
end
|
|
@@ -17,7 +17,7 @@ describe HttpStub::Rake::ServerDaemonTasks do
|
|
|
17
17
|
|
|
18
18
|
it "starts a stub server that responds to stub requests" do
|
|
19
19
|
request = Net::HTTP::Post.new("/stubs")
|
|
20
|
-
request.body = {
|
|
20
|
+
request.body = { response: { status: 302, body: "Some Body" } }.to_json
|
|
21
21
|
|
|
22
22
|
response = Net::HTTP.new("localhost", 8002).start { |http| http.request(request) }
|
|
23
23
|
|