http_stub 0.25.1 → 0.26.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.rb +32 -9
- data/lib/http_stub/configurer.rb +2 -10
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +13 -11
- data/lib/http_stub/configurer/dsl/server.rb +32 -43
- data/lib/http_stub/configurer/dsl/server_endpoint_template.rb +23 -0
- data/lib/http_stub/configurer/dsl/session.rb +55 -0
- data/lib/http_stub/configurer/dsl/session_endpoint_template.rb +22 -0
- data/lib/http_stub/configurer/dsl/session_factory.rb +34 -0
- data/lib/http_stub/configurer/dsl/stub_builder.rb +18 -8
- data/lib/http_stub/configurer/dsl/stub_builder_template.rb +26 -0
- data/lib/http_stub/configurer/request/http/basic.rb +9 -3
- data/lib/http_stub/configurer/request/http/factory.rb +7 -16
- data/lib/http_stub/configurer/request/http/multipart.rb +5 -7
- data/lib/http_stub/configurer/request/stub.rb +3 -3
- data/lib/http_stub/configurer/request/triggers.rb +25 -0
- data/lib/http_stub/configurer/server/command_processor.rb +8 -10
- data/lib/http_stub/configurer/server/configuration.rb +33 -0
- data/lib/http_stub/configurer/server/facade.rb +21 -43
- data/lib/http_stub/configurer/server/request_processor.rb +2 -2
- data/lib/http_stub/configurer/server/session_facade.rb +64 -0
- data/lib/http_stub/extensions/core/uri.rb +28 -0
- data/lib/http_stub/extensions/rack/handler.rb +1 -0
- data/lib/http_stub/extensions/sinatra/namespace.rb +9 -0
- data/lib/http_stub/rake/server_tasks.rb +1 -4
- data/lib/http_stub/server/application/application.rb +17 -98
- data/lib/http_stub/server/application/configuration.rb +38 -0
- data/lib/http_stub/server/application/cross_origin_support.rb +7 -5
- data/lib/http_stub/server/application/request_support.rb +38 -0
- data/lib/http_stub/server/application/response_support.rb +19 -0
- data/lib/http_stub/server/application/routes/memory.rb +37 -0
- data/lib/http_stub/server/application/routes/resource.rb +23 -0
- data/lib/http_stub/server/application/routes/scenario.rb +52 -0
- data/lib/http_stub/server/application/routes/session.rb +65 -0
- data/lib/http_stub/server/application/routes/stub.rb +75 -0
- data/lib/http_stub/server/application/session_uri_support.rb +15 -0
- data/lib/http_stub/server/memory/controller.rb +25 -0
- data/lib/http_stub/server/memory/memory.rb +32 -0
- data/lib/http_stub/server/registry.rb +25 -8
- data/lib/http_stub/server/request/factory.rb +23 -0
- data/lib/http_stub/server/request/parameters.rb +2 -2
- data/lib/http_stub/server/request/request.rb +6 -11
- data/lib/http_stub/server/request/sinatra_request.rb +26 -0
- data/lib/http_stub/server/scenario/controller.rb +16 -11
- data/lib/http_stub/server/scenario/not_found_error.rb +15 -0
- data/lib/http_stub/server/session.rb +14 -0
- data/lib/http_stub/server/session/configuration.rb +32 -0
- data/lib/http_stub/server/session/controller.rb +40 -0
- data/lib/http_stub/server/session/empty.rb +15 -0
- data/lib/http_stub/server/session/identifier_strategy.rb +24 -0
- data/lib/http_stub/server/session/registry.rb +38 -0
- data/lib/http_stub/server/session/session.rb +80 -0
- data/lib/http_stub/server/stub/controller.rb +18 -12
- data/lib/http_stub/server/stub/empty.rb +1 -1
- data/lib/http_stub/server/stub/match/controller.rb +9 -5
- data/lib/http_stub/server/stub/payload/response_body_modifier.rb +3 -1
- data/lib/http_stub/server/stub/registry.rb +6 -13
- data/lib/http_stub/server/stub/triggers.rb +11 -9
- data/lib/http_stub/server/views/_home.haml +2 -0
- data/lib/http_stub/server/views/_post_link_function.haml +26 -0
- data/lib/http_stub/server/views/_session.haml +16 -0
- data/lib/http_stub/server/views/_stub.haml +8 -2
- data/lib/http_stub/server/views/_stubs.haml +4 -0
- data/lib/http_stub/server/views/application.sass +4 -1
- data/lib/http_stub/server/views/layout.haml +1 -0
- data/lib/http_stub/server/views/scenario.haml +4 -3
- data/lib/http_stub/server/views/scenarios.haml +7 -6
- data/lib/http_stub/server/views/session.haml +3 -0
- data/lib/http_stub/server/views/sessions.haml +6 -0
- data/lib/http_stub/server/views/stubs.haml +1 -4
- data/lib/http_stub/server/views/transactional_session.haml +2 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/configurer_initialization_spec.rb +40 -51
- data/spec/acceptance/configurer_part_spec.rb +5 -7
- data/spec/acceptance/cross_origin_support_spec.rb +7 -13
- data/spec/acceptance/endpoint_template_spec.rb +2 -4
- data/spec/acceptance/request_reference_spec.rb +1 -3
- data/spec/acceptance/scenario_spec.rb +7 -9
- data/spec/acceptance/server_defaults_spec.rb +2 -4
- data/spec/acceptance/server_memory_spec.rb +20 -0
- data/spec/acceptance/session_spec.rb +125 -0
- data/spec/acceptance/stub_body_request_matching_spec.rb +2 -4
- data/spec/acceptance/stub_control_values_spec.rb +19 -18
- data/spec/acceptance/stub_match_last_spec.rb +0 -4
- data/spec/acceptance/stub_match_list_spec.rb +0 -4
- data/spec/acceptance/stub_miss_list_spec.rb +0 -4
- data/spec/acceptance/stub_spec.rb +11 -11
- data/spec/acceptance/stub_trigger_spec.rb +60 -13
- data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +83 -30
- data/spec/lib/http_stub/configurer/dsl/server_endpoint_template_spec.rb +167 -0
- data/spec/lib/http_stub/configurer/dsl/server_spec.rb +306 -176
- data/spec/lib/http_stub/configurer/dsl/session_endpoint_template_spec.rb +150 -0
- data/spec/lib/http_stub/configurer/dsl/session_factory_spec.rb +97 -0
- data/spec/lib/http_stub/configurer/dsl/session_spec.rb +222 -0
- data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +209 -48
- data/spec/lib/http_stub/configurer/dsl/stub_builder_template_spec.rb +203 -0
- data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +80 -4
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +115 -56
- data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +39 -6
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +50 -108
- data/spec/lib/http_stub/configurer/request/triggers_spec.rb +101 -0
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +11 -10
- data/spec/lib/http_stub/configurer/server/configuration_spec.rb +139 -0
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +65 -142
- data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +7 -6
- data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +336 -0
- data/spec/lib/http_stub/configurer_spec.rb +105 -0
- data/spec/lib/http_stub/extensions/core/uri_spec.rb +75 -0
- data/spec/lib/http_stub/extensions/rack/handler_spec.rb +1 -1
- data/spec/lib/http_stub/extensions/sinatra/namespace_spec.rb +36 -0
- data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +4 -3
- data/spec/lib/http_stub/rake/server_tasks_spec.rb +47 -10
- data/spec/lib/http_stub/server/application/application_spec.rb +44 -301
- data/spec/lib/http_stub/server/application/configuration_spec.rb +59 -0
- data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +23 -20
- data/spec/lib/http_stub/server/application/request_support_integration_spec.rb +93 -0
- data/spec/lib/http_stub/server/application/request_support_spec.rb +61 -0
- data/spec/lib/http_stub/server/application/response_support_spec.rb +30 -0
- data/spec/lib/http_stub/server/application/routes/memory_spec.rb +41 -0
- data/spec/lib/http_stub/server/application/routes/resource_spec.rb +16 -0
- data/spec/lib/http_stub/server/application/routes/scenario_spec.rb +117 -0
- data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +46 -0
- data/spec/lib/http_stub/server/application/routes/session_spec.rb +186 -0
- data/spec/lib/http_stub/server/application/{application_integration_spec.rb → routes/stub_integration_spec.rb} +16 -38
- data/spec/lib/http_stub/server/application/routes/stub_spec.rb +202 -0
- data/spec/lib/http_stub/server/application/session_uri_support_spec.rb +48 -0
- data/spec/lib/http_stub/server/application/text_formatting_support_spec.rb +3 -3
- data/spec/lib/http_stub/server/memory/controller_spec.rb +47 -0
- data/spec/lib/http_stub/server/memory/memory_spec.rb +122 -0
- data/spec/lib/http_stub/server/registry_spec.rb +153 -34
- data/spec/lib/http_stub/server/request/factory_spec.rb +74 -0
- data/spec/lib/http_stub/server/request/parameters_spec.rb +5 -8
- data/spec/lib/http_stub/server/request/request_spec.rb +52 -52
- data/spec/lib/http_stub/server/request/sinatra_request_spec.rb +132 -0
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +121 -35
- data/spec/lib/http_stub/server/scenario/not_found_error_spec.rb +25 -0
- data/spec/lib/http_stub/server/session/configuration_spec.rb +94 -0
- data/spec/lib/http_stub/server/session/controller_spec.rb +106 -0
- data/spec/lib/http_stub/server/session/empty_spec.rb +13 -0
- data/spec/lib/http_stub/server/session/identifier_strategy_spec.rb +126 -0
- data/spec/lib/http_stub/server/session/registry_spec.rb +214 -0
- data/spec/lib/http_stub/server/session/session_spec.rb +444 -0
- data/spec/lib/http_stub/server/stub/controller_spec.rb +89 -37
- data/spec/lib/http_stub/server/stub/empty_spec.rb +2 -2
- data/spec/lib/http_stub/server/stub/match/controller_spec.rb +59 -16
- data/spec/lib/http_stub/server/stub/payload/response_body_modifier_spec.rb +7 -8
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +42 -15
- data/spec/lib/http_stub/server/stub/registry_spec.rb +38 -59
- data/spec/lib/http_stub/server/stub/triggers_spec.rb +93 -34
- data/spec/spec_helper.rb +13 -1
- data/spec/support/contain_file.rb +23 -0
- data/spec/support/cross_origin_server/application.rb +1 -1
- data/spec/support/cross_origin_server/index_page.rb +2 -2
- data/spec/support/cross_origin_server/integration.rb +3 -2
- data/spec/support/cross_origin_server/public/index.html +2 -1
- data/spec/support/http_stub/configurer_integration.rb +12 -14
- data/spec/support/http_stub/server/application/http_stub_rack_application_test.rb +47 -0
- data/spec/support/http_stub/server/driver.rb +56 -0
- data/spec/support/http_stub/server/memory_fixture.rb +17 -0
- data/spec/support/http_stub/server/request_fixture.rb +7 -6
- data/spec/support/http_stub/server/scenario_fixture.rb +13 -0
- data/spec/support/http_stub/server/session_fixture.rb +27 -0
- data/spec/support/http_stub/server_integration.rb +12 -17
- data/spec/support/http_stub/stub_fixture.rb +19 -6
- data/spec/support/include_in_json.rb +4 -4
- data/spec/support/rack/rack_application_test.rb +9 -0
- data/spec/support/rack/request_fixture.rb +13 -0
- data/spec/support/surpressed_output.rb +10 -0
- metadata +149 -36
- data/lib/http_stub/configurer/dsl/deprecated.rb +0 -60
- data/lib/http_stub/configurer/dsl/endpoint_template.rb +0 -38
- data/lib/http_stub/configurer/dsl/scenario_activator.rb +0 -15
- data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +0 -24
- data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +0 -21
- data/lib/http_stub/server/request.rb +0 -12
- data/lib/http_stub/server/scenario/activator.rb +0 -25
- data/lib/http_stub/server/views/_activate_scenario.haml +0 -23
- data/lib/http_stub/server/views/index.haml +0 -8
- data/spec/acceptance/activator_spec.rb +0 -81
- data/spec/lib/http_stub/configurer/dsl/deprecated_spec.rb +0 -240
- data/spec/lib/http_stub/configurer/dsl/endpoint_template_spec.rb +0 -255
- data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +0 -62
- data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +0 -120
- data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +0 -85
- data/spec/lib/http_stub/server/request_spec.rb +0 -24
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +0 -111
- data/spec/support/http_stub/server/scenario/scenario_fixture.rb +0 -15
@@ -1,11 +1,9 @@
|
|
1
1
|
describe "Scenario acceptance" do
|
2
|
-
include_context "configurer integration"
|
3
2
|
|
4
3
|
context "when a configurer that contains a stub matching a request body" do
|
4
|
+
include_context "configurer integration"
|
5
5
|
|
6
|
-
let(:
|
7
|
-
|
8
|
-
before(:example) { configurer.class.initialize! }
|
6
|
+
let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithStubRequestBody } }
|
9
7
|
|
10
8
|
context "against an exact match" do
|
11
9
|
|
@@ -1,16 +1,17 @@
|
|
1
1
|
describe "Stub control value acceptance" do
|
2
2
|
include_context "configurer integration"
|
3
3
|
|
4
|
-
let(:
|
5
|
-
|
6
|
-
before(:example) { configurer.class.initialize! }
|
4
|
+
let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithTrivialStub } }
|
7
5
|
|
8
6
|
context "when a stub is submitted" do
|
9
7
|
|
10
8
|
context "with a stub uri that is regular expression containing meta characters" do
|
11
9
|
|
12
10
|
before(:example) do
|
13
|
-
|
11
|
+
stub_server.add_stub! do |stub|
|
12
|
+
stub.match_requests(uri: /\/stub\/regexp\/\$key=value/, method: :get)
|
13
|
+
stub.respond_with(body: "Stub body")
|
14
|
+
end
|
14
15
|
end
|
15
16
|
|
16
17
|
context "and a request is made whose uri matches the regular expression" do
|
@@ -38,10 +39,10 @@ describe "Stub control value acceptance" do
|
|
38
39
|
context "with headers whose values are regular expressions" do
|
39
40
|
|
40
41
|
before(:example) do
|
41
|
-
|
42
|
-
"/stub_with_headers", method: :get, headers: { key: /^match.*/ }
|
43
|
-
|
44
|
-
|
42
|
+
stub_server.add_stub! do |stub|
|
43
|
+
stub.match_requests(uri: "/stub_with_headers", method: :get, headers: { key: /^match.*/ })
|
44
|
+
stub.respond_with(status: 202, body: "Another stub body")
|
45
|
+
end
|
45
46
|
end
|
46
47
|
|
47
48
|
context "and a request that matches is made" do
|
@@ -76,10 +77,10 @@ describe "Stub control value acceptance" do
|
|
76
77
|
context "whose values are regular expressions" do
|
77
78
|
|
78
79
|
before(:example) do
|
79
|
-
|
80
|
-
"/stub_with_parameters", method: :get, parameters: { key: /^match.*/ }
|
81
|
-
|
82
|
-
|
80
|
+
stub_server.add_stub! do |stub|
|
81
|
+
stub.match_requests(uri: "/stub_with_parameters", method: :get, parameters: { key: /^match.*/ })
|
82
|
+
stub.respond_with(status: 202, body: "Another stub body")
|
83
|
+
end
|
83
84
|
end
|
84
85
|
|
85
86
|
context "and a request that matches is made" do
|
@@ -110,10 +111,10 @@ describe "Stub control value acceptance" do
|
|
110
111
|
context "whose values indicate the parameters must be omitted" do
|
111
112
|
|
112
113
|
before(:example) do
|
113
|
-
|
114
|
-
"/stub_with_omitted_parameters", method: :get, parameters: { key: :omitted }
|
115
|
-
|
116
|
-
|
114
|
+
stub_server.add_stub! do |stub|
|
115
|
+
stub.match_requests(uri: "/stub_with_omitted_parameters", method: :get, parameters: { key: :omitted })
|
116
|
+
stub.respond_with(status: 202, body: "Omitted parameter stub body")
|
117
|
+
end
|
117
118
|
end
|
118
119
|
|
119
120
|
context "and a request that matches is made" do
|
@@ -145,7 +146,7 @@ describe "Stub control value acceptance" do
|
|
145
146
|
context "with a response delay" do
|
146
147
|
|
147
148
|
before(:example) do
|
148
|
-
|
149
|
+
stub_server.add_stub! { match_requests(uri: "/some_stub_path", method: :get).respond_with(delay_in_seconds: 1) }
|
149
150
|
end
|
150
151
|
|
151
152
|
it "delays the response by the time provided" do
|
@@ -153,7 +154,7 @@ describe "Stub control value acceptance" do
|
|
153
154
|
|
154
155
|
response = HTTParty.get("#{server_uri}/some_stub_path")
|
155
156
|
|
156
|
-
expect(Time.now - start_time).to be >=
|
157
|
+
expect(Time.now - start_time).to be >= 1.0
|
157
158
|
end
|
158
159
|
|
159
160
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
describe "Stub matches last acceptance" do
|
2
2
|
include_context "configurer integration"
|
3
3
|
|
4
|
-
before(:example) { configurer.initialize! }
|
5
|
-
|
6
|
-
after(:example) { configurer.clear_stubs! }
|
7
|
-
|
8
4
|
describe "GET /http_stub/stubs/matches/last" do
|
9
5
|
|
10
6
|
let(:request_uri) { stub_registrator.request_uri }
|
@@ -1,10 +1,6 @@
|
|
1
1
|
describe "Stub match list acceptance" do
|
2
2
|
include_context "configurer integration"
|
3
3
|
|
4
|
-
before(:example) { configurer.initialize! }
|
5
|
-
|
6
|
-
after(:example) { configurer.clear_stubs! }
|
7
|
-
|
8
4
|
describe "GET /http_stub/stubs/matches" do
|
9
5
|
|
10
6
|
let(:response) { HTTParty.get("#{server_uri}/http_stub/stubs/matches") }
|
@@ -1,10 +1,6 @@
|
|
1
1
|
describe "Stub miss list acceptance" do
|
2
2
|
include_context "configurer integration"
|
3
3
|
|
4
|
-
before(:example) { configurer.initialize! }
|
5
|
-
|
6
|
-
after(:example) { configurer.clear_stubs! }
|
7
|
-
|
8
4
|
describe "GET /http_stub/stubs/misses" do
|
9
5
|
|
10
6
|
let(:response) { HTTParty.get("#{server_uri}/http_stub/stubs/misses") }
|
@@ -1,10 +1,6 @@
|
|
1
1
|
describe "Stub basics acceptance" do
|
2
2
|
include_context "configurer integration"
|
3
3
|
|
4
|
-
let(:configurer) { HttpStub::Examples::ConfigurerWithTrivialStub.new }
|
5
|
-
|
6
|
-
before(:example) { configurer.class.initialize! }
|
7
|
-
|
8
4
|
context "when a stub is submitted" do
|
9
5
|
|
10
6
|
context "that contains no request headers or parameters" do
|
@@ -12,8 +8,9 @@ describe "Stub basics acceptance" do
|
|
12
8
|
context "and it contains a response status" do
|
13
9
|
|
14
10
|
before(:example) do
|
15
|
-
stub_server.add_stub! do
|
16
|
-
match_requests(uri: "/stub_with_status", method: :get)
|
11
|
+
stub_server.add_stub! do |stub|
|
12
|
+
stub.match_requests(uri: "/stub_with_status", method: :get)
|
13
|
+
stub.respond_with(status: 201, body: "Stub body")
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
@@ -33,7 +30,7 @@ describe "Stub basics acceptance" do
|
|
33
30
|
|
34
31
|
context "and stubs are cleared" do
|
35
32
|
|
36
|
-
before(:example) {
|
33
|
+
before(:example) { stub_server.clear_stubs! }
|
37
34
|
|
38
35
|
context "and a matching request is made" do
|
39
36
|
|
@@ -52,7 +49,10 @@ describe "Stub basics acceptance" do
|
|
52
49
|
context "and it does not contain a response status" do
|
53
50
|
|
54
51
|
before(:example) do
|
55
|
-
stub_server.add_stub!
|
52
|
+
stub_server.add_stub! do |stub|
|
53
|
+
stub.match_requests(uri: "/stub_without_status", method: :get)
|
54
|
+
stub.respond_with(body: "Stub body")
|
55
|
+
end
|
56
56
|
end
|
57
57
|
|
58
58
|
context "and a matching request is made" do
|
@@ -233,7 +233,7 @@ describe "Stub basics acceptance" do
|
|
233
233
|
|
234
234
|
context "that contains a response body that is a file" do
|
235
235
|
|
236
|
-
let(:
|
236
|
+
let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithFileResponses } }
|
237
237
|
|
238
238
|
context "and a request that matches is made" do
|
239
239
|
|
@@ -250,7 +250,7 @@ describe "Stub basics acceptance" do
|
|
250
250
|
end
|
251
251
|
|
252
252
|
it "responds with the configured file" do
|
253
|
-
|
253
|
+
expect(response).to contain_file(HttpStub::Examples::ConfigurerWithFileResponses::FILE_PATH)
|
254
254
|
end
|
255
255
|
|
256
256
|
context "and a subsequent request is made that requests the file if it has been modified" do
|
@@ -289,7 +289,7 @@ describe "Stub basics acceptance" do
|
|
289
289
|
end
|
290
290
|
|
291
291
|
it "responds with the configured response" do
|
292
|
-
|
292
|
+
expect(response).to contain_file(HttpStub::Examples::ConfigurerWithFileResponses::FILE_PATH)
|
293
293
|
end
|
294
294
|
|
295
295
|
end
|
@@ -1,13 +1,60 @@
|
|
1
1
|
describe "Stub trigger acceptance" do
|
2
2
|
include_context "configurer integration"
|
3
3
|
|
4
|
-
let(:
|
5
|
-
|
6
|
-
before(:example) { configurer.class.initialize! }
|
4
|
+
let(:configurer_specification) { { class: HttpStub::Examples::ConfigurerWithStubTriggers } }
|
7
5
|
|
8
6
|
context "when a stub is submitted that contains triggers" do
|
9
7
|
|
10
|
-
context "
|
8
|
+
context "that trigger scenarios" do
|
9
|
+
|
10
|
+
let(:triggered_scenario_names) do
|
11
|
+
(1..3).map do |scenario_number|
|
12
|
+
"Triggered Scenario #{scenario_number}".tap do |scenario_name|
|
13
|
+
stub_server.add_scenario_with_one_stub!(scenario_name) do |stub|
|
14
|
+
stub.match_requests(uri: "/triggered_scenario_#{scenario_number}", method: :get)
|
15
|
+
stub.respond_with(status: 200 + scenario_number, body: "Triggered scenario body #{scenario_number}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:example) do
|
22
|
+
stub_server.add_stub! do |stub|
|
23
|
+
stub.match_requests(uri: "/triggers_scenarios", method: :get)
|
24
|
+
stub.respond_with(body: "Stub triggering scenarios body")
|
25
|
+
stub.trigger(scenarios: triggered_scenario_names)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "and a request is made matching the stub" do
|
30
|
+
|
31
|
+
before(:example) { @stub_with_triggers_response = HTTParty.get("#{server_uri}/triggers_scenarios") }
|
32
|
+
|
33
|
+
it "replays the stubbed response" do
|
34
|
+
expect(@stub_with_triggers_response.code).to eql(200)
|
35
|
+
expect(@stub_with_triggers_response.body).to eql("Stub triggering scenarios body")
|
36
|
+
end
|
37
|
+
|
38
|
+
(1..3).each do |scenario_number|
|
39
|
+
|
40
|
+
context "and then a request matching triggered scenario ##{scenario_number} is made" do
|
41
|
+
|
42
|
+
let(:response) { HTTParty.get("#{server_uri}/triggered_scenario_#{scenario_number}") }
|
43
|
+
|
44
|
+
it "replays the triggered response" do
|
45
|
+
expect(response.code).to eql("20#{scenario_number}".to_i)
|
46
|
+
expect(response.body).to eql("Triggered scenario body #{scenario_number}")
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
context "that trigger stubs" do
|
11
58
|
|
12
59
|
let(:triggered_stubs) do
|
13
60
|
(1..3).map do |trigger_number|
|
@@ -20,24 +67,24 @@ describe "Stub trigger acceptance" do
|
|
20
67
|
|
21
68
|
before(:example) do
|
22
69
|
stub_server.add_stub! do |stub|
|
23
|
-
stub.match_requests(uri: "/
|
24
|
-
stub.respond_with(body: "
|
25
|
-
stub.trigger(triggered_stubs)
|
70
|
+
stub.match_requests(uri: "/triggers_stubs", method: :get)
|
71
|
+
stub.respond_with(body: "Stub triggering stubs body")
|
72
|
+
stub.trigger(stubs: triggered_stubs)
|
26
73
|
end
|
27
74
|
end
|
28
75
|
|
29
76
|
context "and a request is made matching the stub" do
|
30
77
|
|
31
|
-
before(:example) { @stub_with_triggers_response = HTTParty.get("#{server_uri}/
|
78
|
+
before(:example) { @stub_with_triggers_response = HTTParty.get("#{server_uri}/triggers_stubs") }
|
32
79
|
|
33
80
|
it "replays the stubbed response" do
|
34
81
|
expect(@stub_with_triggers_response.code).to eql(200)
|
35
|
-
expect(@stub_with_triggers_response.body).to eql("
|
82
|
+
expect(@stub_with_triggers_response.body).to eql("Stub triggering stubs body")
|
36
83
|
end
|
37
84
|
|
38
85
|
(1..3).each do |trigger_number|
|
39
86
|
|
40
|
-
context "and then a request matching triggered stub ##{trigger_number} is made" do
|
87
|
+
context "and then a request matching a triggered stub ##{trigger_number} is made" do
|
41
88
|
|
42
89
|
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_#{trigger_number}") }
|
43
90
|
|
@@ -54,7 +101,7 @@ describe "Stub trigger acceptance" do
|
|
54
101
|
|
55
102
|
end
|
56
103
|
|
57
|
-
context "
|
104
|
+
context "that contain a mix of text and file responses" do
|
58
105
|
|
59
106
|
let(:pdf_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/sample.pdf" }
|
60
107
|
let(:pdf_file_trigger) do
|
@@ -92,7 +139,7 @@ describe "Stub trigger acceptance" do
|
|
92
139
|
stub_server.add_stub! do |stub|
|
93
140
|
stub.match_requests(uri: "/stub_with_triggers", method: :get)
|
94
141
|
stub.respond_with(body: "Trigger stub body")
|
95
|
-
stub.trigger(triggered_stubs)
|
142
|
+
stub.trigger(stubs: triggered_stubs)
|
96
143
|
end
|
97
144
|
end
|
98
145
|
|
@@ -106,7 +153,7 @@ describe "Stub trigger acceptance" do
|
|
106
153
|
|
107
154
|
it "replays the triggered response" do
|
108
155
|
expect(response.code).to eql(200)
|
109
|
-
|
156
|
+
expect(response).to contain_file(pdf_file_path)
|
110
157
|
end
|
111
158
|
|
112
159
|
end
|
@@ -2,40 +2,50 @@ describe HttpStub::Configurer::DSL::ScenarioBuilder do
|
|
2
2
|
|
3
3
|
let(:stub_fixture) { HttpStub::StubFixture.new }
|
4
4
|
|
5
|
-
let(:
|
6
|
-
let(:
|
5
|
+
let(:scenario_name) { "some scenario name" }
|
6
|
+
let(:default_stub_template) { instance_double(HttpStub::Configurer::DSL::StubBuilderTemplate) }
|
7
7
|
|
8
|
-
let(:scenario_builder) { HttpStub::Configurer::DSL::ScenarioBuilder.new(
|
8
|
+
let(:scenario_builder) { HttpStub::Configurer::DSL::ScenarioBuilder.new(scenario_name, default_stub_template) }
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
describe "#build_stub" do
|
11
|
+
|
12
|
+
let(:response_overrides) { { status: 201 } }
|
13
|
+
let(:block_verifier) { double("BlockVerifier") }
|
14
|
+
let(:block) { lambda { block_verifier.verify } }
|
15
|
+
|
16
|
+
subject { scenario_builder.build_stub(response_overrides, &block) }
|
17
|
+
|
18
|
+
it "delegates to the provided default stub template" do
|
19
|
+
expect(default_stub_template).to receive(:build_stub).with(response_overrides).and_yield
|
20
|
+
expect(block_verifier).to receive(:verify)
|
21
|
+
|
22
|
+
subject
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns the built stub" do
|
26
|
+
built_stub = instance_double(HttpStub::Configurer::DSL::StubBuilder)
|
27
|
+
allow(default_stub_template).to receive(:build_stub).and_return(built_stub)
|
28
|
+
|
29
|
+
expect(subject).to eql(built_stub)
|
30
|
+
end
|
13
31
|
|
14
|
-
it "produces stub builders" do
|
15
|
-
expect(scenario_builder).to be_a(HttpStub::Configurer::DSL::StubBuilderProducer)
|
16
32
|
end
|
17
33
|
|
18
34
|
describe "#add_stub!" do
|
19
35
|
|
20
|
-
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder
|
36
|
+
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
|
21
37
|
|
22
38
|
context "when a block is provided" do
|
23
39
|
|
24
40
|
let(:block_verifier) { double("BlockVerifier") }
|
25
|
-
let(:block)
|
41
|
+
let(:block) { lambda { block_verifier.verify } }
|
26
42
|
|
27
43
|
subject { scenario_builder.add_stub!(&block) }
|
28
44
|
|
29
|
-
before(:example) { allow(
|
30
|
-
|
31
|
-
it "creates a stub builder with the response defaults provided to the scenario builder" do
|
32
|
-
expect(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(stub_builder)
|
33
|
-
|
34
|
-
subject
|
35
|
-
end
|
45
|
+
before(:example) { allow(scenario_builder).to receive(:build_stub).and_return(stub_builder) }
|
36
46
|
|
37
|
-
it "
|
38
|
-
expect(
|
47
|
+
it "builds a stub whose values are initialized via the provided block" do
|
48
|
+
expect(scenario_builder).to receive(:build_stub).with(no_args).and_yield
|
39
49
|
expect(block_verifier).to receive(:verify)
|
40
50
|
|
41
51
|
subject
|
@@ -65,6 +75,20 @@ describe HttpStub::Configurer::DSL::ScenarioBuilder do
|
|
65
75
|
|
66
76
|
end
|
67
77
|
|
78
|
+
describe "#add_stubs!" do
|
79
|
+
|
80
|
+
let(:stub_builders) { (1..3).map { instance_double(HttpStub::Configurer::DSL::StubBuilder) } }
|
81
|
+
|
82
|
+
subject { scenario_builder.add_stubs!(stub_builders) }
|
83
|
+
|
84
|
+
it "adds each stub to the scenario builders" do
|
85
|
+
stub_builders.each { |stub_builder| expect(scenario_builder).to receive(:add_stub!).with(stub_builder) }
|
86
|
+
|
87
|
+
subject
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
68
92
|
describe "#build" do
|
69
93
|
|
70
94
|
let(:scenario) { instance_double(HttpStub::Configurer::Request::Scenario) }
|
@@ -79,17 +103,14 @@ describe HttpStub::Configurer::DSL::ScenarioBuilder do
|
|
79
103
|
subject
|
80
104
|
end
|
81
105
|
|
82
|
-
context "when
|
106
|
+
context "when the scenario registers multiple stubs" do
|
83
107
|
|
84
|
-
let(:stubs)
|
108
|
+
let(:stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
|
85
109
|
let(:stub_builders) do
|
86
|
-
stubs.map { |stub| instance_double(HttpStub::Configurer::DSL::StubBuilder,
|
110
|
+
stubs.map { |stub| instance_double(HttpStub::Configurer::DSL::StubBuilder, build: stub) }
|
87
111
|
end
|
88
112
|
|
89
|
-
before(:example)
|
90
|
-
allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(*stub_builders)
|
91
|
-
stub_builders.each { scenario_builder.add_stub! { |_builder| "some block" } }
|
92
|
-
end
|
113
|
+
before(:example) { scenario_builder.add_stubs!(stub_builders) }
|
93
114
|
|
94
115
|
it "builds the stubs" do
|
95
116
|
stub_builders.each { |stub_builder| expect(stub_builder).to receive(:build) }
|
@@ -105,7 +126,7 @@ describe HttpStub::Configurer::DSL::ScenarioBuilder do
|
|
105
126
|
|
106
127
|
end
|
107
128
|
|
108
|
-
context "when
|
129
|
+
context "when the scenario registers no stubs" do
|
109
130
|
|
110
131
|
it "creates a scenario that has empty stubs" do
|
111
132
|
expect(HttpStub::Configurer::Request::Scenario).to receive(:new).with(hash_including(stubs: []))
|
@@ -115,9 +136,9 @@ describe HttpStub::Configurer::DSL::ScenarioBuilder do
|
|
115
136
|
|
116
137
|
end
|
117
138
|
|
118
|
-
context "when
|
139
|
+
context "when the scenario activates an array scenarios" do
|
119
140
|
|
120
|
-
let(:triggered_scenario_names) { (1..3).map { |i| "
|
141
|
+
let(:triggered_scenario_names) { (1..3).map { |i| "scenario #{i}" } }
|
121
142
|
|
122
143
|
before(:example) { scenario_builder.activate!(triggered_scenario_names) }
|
123
144
|
|
@@ -131,7 +152,39 @@ describe HttpStub::Configurer::DSL::ScenarioBuilder do
|
|
131
152
|
|
132
153
|
end
|
133
154
|
|
134
|
-
context "when
|
155
|
+
context "when the scenario activates a list of scenarios" do
|
156
|
+
|
157
|
+
let(:triggered_scenario_names) { (1..3).map { |i| "activator_#{i}" } }
|
158
|
+
|
159
|
+
before(:example) { scenario_builder.activate!(*triggered_scenario_names) }
|
160
|
+
|
161
|
+
it "creates a scenario that includes the triggered scenario names" do
|
162
|
+
expect(HttpStub::Configurer::Request::Scenario).to(
|
163
|
+
receive(:new).with(hash_including(triggered_scenario_names: triggered_scenario_names))
|
164
|
+
)
|
165
|
+
|
166
|
+
subject
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
context "when the scenario activates one scenario" do
|
172
|
+
|
173
|
+
let(:triggered_scenario_name) { "a scenario" }
|
174
|
+
|
175
|
+
before(:example) { scenario_builder.activate!(triggered_scenario_name) }
|
176
|
+
|
177
|
+
it "creates a scenario that includes the triggered scenario names" do
|
178
|
+
expect(HttpStub::Configurer::Request::Scenario).to(
|
179
|
+
receive(:new).with(hash_including(triggered_scenario_names: [ triggered_scenario_name ]))
|
180
|
+
)
|
181
|
+
|
182
|
+
subject
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
context "when the scenario does not activate any scenarios" do
|
135
188
|
|
136
189
|
it "creates a scenario that has empty triggered scenario names" do
|
137
190
|
expect(HttpStub::Configurer::Request::Scenario).to(
|