http_stub 0.27.0 → 0.28.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/http_stub/client.rb +18 -0
- data/lib/http_stub/client/client.rb +28 -0
- data/lib/http_stub/client/request.rb +38 -0
- data/lib/http_stub/client/server.rb +20 -0
- data/lib/http_stub/client/session.rb +43 -0
- data/lib/http_stub/configurator.rb +61 -0
- data/lib/http_stub/configurator/endpoint_template.rb +24 -0
- data/lib/http_stub/configurator/part.rb +23 -0
- data/lib/http_stub/configurator/scenario.rb +42 -0
- data/lib/http_stub/configurator/server.rb +53 -0
- data/lib/http_stub/configurator/state.rb +41 -0
- data/lib/http_stub/configurator/stub.rb +13 -0
- data/lib/http_stub/configurator/stub/stub.rb +75 -0
- data/lib/http_stub/{configurer/dsl/stub_builder_template.rb → configurator/stub/template.rb} +5 -5
- data/lib/http_stub/extensions/core/object.rb +17 -0
- data/lib/http_stub/rake/server_tasks.rb +2 -14
- data/lib/http_stub/rake/task_generators.rb +3 -3
- data/lib/http_stub/server.rb +110 -0
- data/lib/http_stub/server/application/application.rb +10 -6
- data/lib/http_stub/server/application/request_support.rb +2 -2
- data/lib/http_stub/server/application/routes/memory.rb +1 -6
- data/lib/http_stub/server/application/routes/scenario.rb +1 -11
- data/lib/http_stub/server/application/routes/session.rb +1 -1
- data/lib/http_stub/server/application/routes/status.rb +0 -10
- data/lib/http_stub/server/application/routes/stub.rb +2 -12
- data/lib/http_stub/server/daemon.rb +1 -10
- data/lib/http_stub/server/memory/controller.rb +2 -8
- data/lib/http_stub/server/memory/initial_state.rb +27 -0
- data/lib/http_stub/server/memory/memory.rb +6 -27
- data/lib/http_stub/server/registry.rb +3 -1
- data/lib/http_stub/server/request/factory.rb +3 -3
- data/lib/http_stub/server/response.rb +12 -6
- data/lib/http_stub/server/scenario.rb +2 -2
- data/lib/http_stub/server/scenario/controller.rb +3 -13
- data/lib/http_stub/server/scenario/registry.rb +25 -0
- data/lib/http_stub/server/scenario/scenario.rb +13 -8
- data/lib/http_stub/server/session.rb +0 -1
- data/lib/http_stub/server/session/controller.rb +7 -8
- data/lib/http_stub/server/session/identifier_strategy.rb +9 -2
- data/lib/http_stub/server/session/registry.rb +7 -13
- data/lib/http_stub/server/session/session.rb +4 -8
- data/lib/http_stub/server/stdout_logger.rb +13 -0
- data/lib/http_stub/server/stub.rb +3 -2
- data/lib/http_stub/server/stub/controller.rb +0 -10
- data/lib/http_stub/server/stub/empty.rb +2 -1
- data/lib/http_stub/server/stub/match/controller.rb +1 -1
- data/lib/http_stub/server/stub/match/exact_value_matcher.rb +2 -1
- data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +1 -1
- data/lib/http_stub/server/stub/match/regexp_value_matcher.rb +1 -2
- data/lib/http_stub/server/stub/match/rule/body.rb +7 -29
- data/lib/http_stub/server/stub/match/rule/{json_body.rb → json_schema_body.rb} +1 -1
- data/lib/http_stub/server/stub/match/rule/method.rb +1 -1
- data/lib/http_stub/server/stub/match/rule/schema_body.rb +39 -0
- data/lib/http_stub/server/stub/match/rules.rb +6 -6
- data/lib/http_stub/server/stub/match/string_value_matcher.rb +1 -2
- data/lib/http_stub/server/stub/registry.rb +4 -4
- data/lib/http_stub/server/stub/response.rb +2 -6
- data/lib/http_stub/server/stub/response/blocks.rb +33 -0
- data/lib/http_stub/server/stub/response/body.rb +21 -0
- data/lib/http_stub/server/stub/response/file_body.rb +46 -0
- data/lib/http_stub/server/stub/response/headers.rb +24 -0
- data/lib/http_stub/server/stub/response/response.rb +52 -0
- data/lib/http_stub/server/stub/response/text_body.rb +32 -0
- data/lib/http_stub/server/stub/stub.rb +17 -11
- data/lib/http_stub/server/stub/triggers.rb +16 -5
- data/lib/http_stub/server/views/_file_body_response.haml +1 -0
- data/lib/http_stub/server/views/_response.haml +6 -1
- data/lib/http_stub/server/views/_text_body_response.haml +1 -0
- data/lib/http_stub/server/views/application.sass +31 -31
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/{configurer_part_spec.rb → configurator_part_spec.rb} +8 -8
- data/spec/acceptance/cross_origin_support_spec.rb +9 -11
- data/spec/acceptance/endpoint_template_spec.rb +5 -5
- data/spec/acceptance/scenario_spec.rb +8 -8
- data/spec/acceptance/server_defaults_spec.rb +3 -3
- data/spec/acceptance/server_memory_spec.rb +13 -5
- data/spec/acceptance/server_status_spec.rb +4 -21
- data/spec/acceptance/session_spec.rb +8 -11
- data/spec/acceptance/stub_body_request_matching_spec.rb +9 -9
- data/spec/acceptance/stub_control_values_spec.rb +74 -82
- data/spec/acceptance/stub_match_last_spec.rb +60 -80
- data/spec/acceptance/stub_match_list_spec.rb +30 -66
- data/spec/acceptance/stub_miss_list_spec.rb +19 -27
- data/spec/acceptance/stub_response_block_spec.rb +66 -0
- data/spec/acceptance/stub_spec.rb +109 -185
- data/spec/acceptance/stub_trigger_spec.rb +12 -89
- data/spec/helper.rb +32 -10
- data/spec/lib/http_stub/client/client_spec.rb +109 -0
- data/spec/lib/http_stub/client/request_integration_spec.rb +74 -0
- data/spec/lib/http_stub/client/request_spec.rb +32 -0
- data/spec/lib/http_stub/client/server_spec.rb +75 -0
- data/spec/lib/http_stub/client/session_spec.rb +117 -0
- data/spec/lib/http_stub/client_spec.rb +15 -0
- data/spec/lib/http_stub/{configurer/dsl/server_endpoint_template_spec.rb → configurator/endpoint_template_spec.rb} +49 -38
- data/spec/lib/http_stub/configurator/part_spec.rb +103 -0
- data/spec/lib/http_stub/configurator/scenario_spec.rb +162 -0
- data/spec/lib/http_stub/configurator/server_spec.rb +344 -0
- data/spec/lib/http_stub/configurator/state_spec.rb +113 -0
- data/spec/lib/http_stub/configurator/stub/stub_spec.rb +867 -0
- data/spec/lib/http_stub/{configurer/dsl/stub_builder_template_spec.rb → configurator/stub/template_spec.rb} +46 -44
- data/spec/lib/http_stub/configurator/stub_spec.rb +27 -0
- data/spec/lib/http_stub/configurator_spec.rb +113 -0
- data/spec/lib/http_stub/extensions/core/hash_spec.rb +3 -3
- data/spec/lib/http_stub/extensions/core/object_spec.rb +29 -0
- data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +14 -9
- data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +25 -53
- data/spec/lib/http_stub/rake/server_tasks_spec.rb +12 -55
- data/spec/lib/http_stub/server/application/application_spec.rb +4 -49
- data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +2 -5
- data/spec/lib/http_stub/server/application/request_support_integration_spec.rb +4 -4
- data/spec/lib/http_stub/server/application/request_support_spec.rb +16 -11
- data/spec/lib/http_stub/server/application/routes/memory_spec.rb +1 -21
- data/spec/lib/http_stub/server/application/routes/scenario_spec.rb +4 -56
- data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +1 -1
- data/spec/lib/http_stub/server/application/routes/status_spec.rb +2 -36
- data/spec/lib/http_stub/server/application/routes/stub_integration_spec.rb +3 -34
- data/spec/lib/http_stub/server/application/routes/stub_spec.rb +6 -55
- data/spec/lib/http_stub/server/daemon_integration_spec.rb +5 -1
- data/spec/lib/http_stub/server/daemon_spec.rb +8 -77
- data/spec/lib/http_stub/server/memory/controller_spec.rb +2 -28
- data/spec/lib/http_stub/server/memory/initial_state_spec.rb +57 -0
- data/spec/lib/http_stub/server/memory/memory_spec.rb +28 -116
- data/spec/lib/http_stub/server/registry_spec.rb +57 -2
- data/spec/lib/http_stub/server/request/factory_spec.rb +8 -6
- data/spec/lib/http_stub/server/response_spec.rb +32 -10
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +14 -53
- data/spec/lib/http_stub/server/scenario/registry_spec.rb +147 -0
- data/spec/lib/http_stub/server/scenario/scenario_spec.rb +8 -10
- data/spec/lib/http_stub/server/scenario_spec.rb +1 -1
- data/spec/lib/http_stub/server/session/controller_spec.rb +4 -5
- data/spec/lib/http_stub/server/session/identifier_strategy_spec.rb +15 -48
- data/spec/lib/http_stub/server/session/registry_spec.rb +15 -28
- data/spec/lib/http_stub/server/session/session_spec.rb +13 -71
- data/spec/lib/http_stub/server/stdout_logger_spec.rb +17 -0
- data/spec/lib/http_stub/server/stub/controller_spec.rb +7 -65
- data/spec/lib/http_stub/server/stub/empty_spec.rb +8 -0
- data/spec/lib/http_stub/server/stub/match/controller_spec.rb +2 -2
- data/spec/lib/http_stub/server/stub/match/exact_value_matcher_spec.rb +49 -11
- data/spec/lib/http_stub/server/stub/match/hash_matcher_spec.rb +4 -4
- data/spec/lib/http_stub/server/stub/match/match_spec.rb +4 -4
- data/spec/lib/http_stub/server/stub/match/miss_spec.rb +2 -2
- data/spec/lib/http_stub/server/stub/match/omitted_value_matcher_spec.rb +31 -12
- data/spec/lib/http_stub/server/stub/match/regexp_value_matcher_spec.rb +20 -11
- data/spec/lib/http_stub/server/stub/match/rule/body_spec.rb +3 -3
- data/spec/lib/http_stub/server/stub/match/rule/{json_body_spec.rb → json_schema_body_spec.rb} +5 -5
- data/spec/lib/http_stub/server/stub/match/rule/method_spec.rb +42 -8
- data/spec/lib/http_stub/server/stub/match/rule/schema_body_spec.rb +64 -0
- data/spec/lib/http_stub/server/stub/match/rules_spec.rb +18 -18
- data/spec/lib/http_stub/server/stub/match/string_value_matcher_spec.rb +10 -63
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +11 -28
- data/spec/lib/http_stub/server/stub/registry_spec.rb +6 -13
- data/spec/lib/http_stub/server/stub/response/blocks_spec.rb +64 -0
- data/spec/lib/http_stub/server/stub/response/body_spec.rb +52 -0
- data/spec/lib/http_stub/server/stub/response/file_body_spec.rb +117 -0
- data/spec/lib/http_stub/server/stub/response/headers_spec.rb +89 -0
- data/spec/lib/http_stub/server/stub/response/response_spec.rb +342 -0
- data/spec/lib/http_stub/server/stub/response/text_body_spec.rb +138 -0
- data/spec/lib/http_stub/server/stub/response_spec.rb +23 -32
- data/spec/lib/http_stub/server/stub/stub_spec.rb +33 -39
- data/spec/lib/http_stub/server/stub/triggers_spec.rb +47 -12
- data/spec/lib/http_stub/server/stub_spec.rb +1 -1
- data/spec/support/extensions/core/random.rb +23 -0
- data/spec/support/http_stub/configurator/scenario_builder.rb +35 -0
- data/spec/support/http_stub/configurator/scenario_fixture.rb +39 -0
- data/spec/support/http_stub/configurator/stub_builder.rb +112 -0
- data/spec/support/http_stub/configurator/stub_fixture.rb +58 -0
- data/spec/support/http_stub/configurator_fixture.rb +13 -0
- data/spec/support/http_stub/configurator_with_stub_builder_and_requester.rb +14 -0
- data/spec/support/http_stub/headers_fixture.rb +11 -0
- data/spec/support/http_stub/{html_view_excluding_request_details.rb → html_view_excluding_a_stub_request.rb} +2 -2
- data/spec/support/http_stub/{html_view_including_request_details.rb → html_view_including_a_stub_request.rb} +20 -12
- data/spec/support/http_stub/port.rb +12 -0
- data/spec/support/http_stub/server/application/http_stub_rack_application_test.rb +2 -3
- data/spec/support/http_stub/server/driver.rb +20 -15
- data/spec/support/http_stub/server/memory_fixture.rb +2 -2
- data/spec/support/http_stub/server/request/sinatra_request_fixture.rb +16 -0
- data/spec/support/http_stub/server/request_fixture.rb +11 -6
- data/spec/support/http_stub/server/scenario_fixture.rb +14 -2
- data/spec/support/http_stub/server/session_fixture.rb +2 -16
- data/spec/support/http_stub/server/silent_logger.rb +7 -0
- data/spec/support/http_stub/server/simple_request.rb +17 -0
- data/spec/support/http_stub/server/stub/match/match_fixture.rb +1 -1
- data/spec/support/http_stub/server/stub/response/blocks_fixture.rb +54 -0
- data/spec/support/http_stub/server/stub/response/file_body_fixture.rb +25 -0
- data/spec/support/http_stub/server/stub/response/text_body_fixture.rb +33 -0
- data/spec/support/http_stub/server/stub/response_builder.rb +24 -0
- data/spec/support/http_stub/server/stub/response_fixture.rb +15 -0
- data/spec/support/http_stub/server/stub_fixture.rb +21 -0
- data/spec/support/http_stub/server_integration.rb +9 -6
- data/spec/support/http_stub/stub_requester.rb +37 -0
- data/spec/support/object_convertable_to_json.rb +11 -0
- data/spec/support/rack/rack_application_test.rb +1 -1
- data/spec/support/rack/request_fixture.rb +22 -4
- metadata +166 -207
- data/lib/http_stub.rb +0 -131
- data/lib/http_stub/configurer.rb +0 -42
- data/lib/http_stub/configurer/dsl/request_attribute_referencer.rb +0 -19
- data/lib/http_stub/configurer/dsl/request_referencer.rb +0 -24
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +0 -39
- data/lib/http_stub/configurer/dsl/server.rb +0 -80
- data/lib/http_stub/configurer/dsl/server_endpoint_template.rb +0 -23
- data/lib/http_stub/configurer/dsl/session.rb +0 -51
- data/lib/http_stub/configurer/dsl/session_endpoint_template.rb +0 -22
- data/lib/http_stub/configurer/dsl/session_factory.rb +0 -34
- data/lib/http_stub/configurer/dsl/stub_builder.rb +0 -65
- data/lib/http_stub/configurer/part.rb +0 -23
- data/lib/http_stub/configurer/request/controllable_value.rb +0 -19
- data/lib/http_stub/configurer/request/http/basic.rb +0 -27
- data/lib/http_stub/configurer/request/http/factory.rb +0 -33
- data/lib/http_stub/configurer/request/http/multipart.rb +0 -34
- data/lib/http_stub/configurer/request/omittable.rb +0 -26
- data/lib/http_stub/configurer/request/regexpable.rb +0 -33
- data/lib/http_stub/configurer/request/scenario.rb +0 -29
- data/lib/http_stub/configurer/request/stub.rb +0 -39
- data/lib/http_stub/configurer/request/stub_response.rb +0 -38
- data/lib/http_stub/configurer/request/stub_response_file.rb +0 -20
- data/lib/http_stub/configurer/request/triggers.rb +0 -25
- data/lib/http_stub/configurer/server/buffered_command_processor.rb +0 -24
- data/lib/http_stub/configurer/server/command.rb +0 -22
- data/lib/http_stub/configurer/server/command_processor.rb +0 -35
- data/lib/http_stub/configurer/server/configuration.rb +0 -33
- data/lib/http_stub/configurer/server/facade.rb +0 -61
- data/lib/http_stub/configurer/server/request_processor.rb +0 -30
- data/lib/http_stub/configurer/server/session_facade.rb +0 -57
- data/lib/http_stub/server/application/configuration.rb +0 -38
- data/lib/http_stub/server/application/response_pipeline.rb +0 -20
- data/lib/http_stub/server/application/response_support.rb +0 -19
- data/lib/http_stub/server/scenario/parser.rb +0 -17
- data/lib/http_stub/server/session/configuration.rb +0 -32
- data/lib/http_stub/server/status/controller.rb +0 -25
- data/lib/http_stub/server/stub/parser.rb +0 -17
- data/lib/http_stub/server/stub/payload.rb +0 -20
- data/lib/http_stub/server/stub/payload/base_uri_modifier.rb +0 -17
- data/lib/http_stub/server/stub/payload/response_body_modifier.rb +0 -21
- data/lib/http_stub/server/stub/response/attribute/body.rb +0 -32
- data/lib/http_stub/server/stub/response/attribute/headers.rb +0 -32
- data/lib/http_stub/server/stub/response/attribute/interpolator.rb +0 -26
- data/lib/http_stub/server/stub/response/attribute/interpolator/headers.rb +0 -27
- data/lib/http_stub/server/stub/response/attribute/interpolator/parameters.rb +0 -27
- data/lib/http_stub/server/stub/response/base.rb +0 -61
- data/lib/http_stub/server/stub/response/file.rb +0 -45
- data/lib/http_stub/server/stub/response/text.rb +0 -35
- data/lib/http_stub/server/views/_file_response.haml +0 -1
- data/lib/http_stub/server/views/_text_response.haml +0 -1
- data/spec/acceptance/configurer_initialization_spec.rb +0 -157
- data/spec/acceptance/request_reference_spec.rb +0 -42
- data/spec/lib/http_stub/configurer/dsl/request_attribute_referencer_spec.rb +0 -37
- data/spec/lib/http_stub/configurer/dsl/request_referencer_spec.rb +0 -37
- data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +0 -201
- data/spec/lib/http_stub/configurer/dsl/server_spec.rb +0 -575
- data/spec/lib/http_stub/configurer/dsl/session_endpoint_template_spec.rb +0 -150
- data/spec/lib/http_stub/configurer/dsl/session_factory_spec.rb +0 -97
- data/spec/lib/http_stub/configurer/dsl/session_spec.rb +0 -210
- data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +0 -747
- data/spec/lib/http_stub/configurer/part_spec.rb +0 -103
- data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +0 -34
- data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +0 -91
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +0 -222
- data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +0 -118
- data/spec/lib/http_stub/configurer/request/omittable_spec.rb +0 -70
- data/spec/lib/http_stub/configurer/request/regexpable_spec.rb +0 -77
- data/spec/lib/http_stub/configurer/request/scenario_spec.rb +0 -69
- data/spec/lib/http_stub/configurer/request/stub_response_spec.rb +0 -195
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +0 -231
- data/spec/lib/http_stub/configurer/request/triggers_spec.rb +0 -101
- data/spec/lib/http_stub/configurer/server/buffered_command_processor_spec.rb +0 -35
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +0 -75
- data/spec/lib/http_stub/configurer/server/command_spec.rb +0 -26
- data/spec/lib/http_stub/configurer/server/configuration_spec.rb +0 -139
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +0 -235
- data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +0 -100
- data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +0 -285
- data/spec/lib/http_stub/configurer_spec.rb +0 -105
- data/spec/lib/http_stub/server/application/configuration_spec.rb +0 -59
- data/spec/lib/http_stub/server/application/response_pipeline_spec.rb +0 -29
- data/spec/lib/http_stub/server/application/response_support_spec.rb +0 -30
- data/spec/lib/http_stub/server/scenario/parser_spec.rb +0 -64
- data/spec/lib/http_stub/server/session/configuration_spec.rb +0 -94
- data/spec/lib/http_stub/server/status/controller_spec.rb +0 -47
- data/spec/lib/http_stub/server/stub/parser_spec.rb +0 -56
- data/spec/lib/http_stub/server/stub/payload/base_uri_modifier_spec.rb +0 -23
- data/spec/lib/http_stub/server/stub/payload/response_body_modifier_spec.rb +0 -84
- data/spec/lib/http_stub/server/stub/payload_spec.rb +0 -33
- data/spec/lib/http_stub/server/stub/response/attribute/body_spec.rb +0 -98
- data/spec/lib/http_stub/server/stub/response/attribute/headers_spec.rb +0 -73
- data/spec/lib/http_stub/server/stub/response/attribute/interpolator/headers_spec.rb +0 -53
- data/spec/lib/http_stub/server/stub/response/attribute/interpolator/parameters_spec.rb +0 -53
- data/spec/lib/http_stub/server/stub/response/attribute/interpolator_spec.rb +0 -41
- data/spec/lib/http_stub/server/stub/response/base_spec.rb +0 -217
- data/spec/lib/http_stub/server/stub/response/file_spec.rb +0 -197
- data/spec/lib/http_stub/server/stub/response/text_spec.rb +0 -182
- data/spec/resources/sample.pdf +0 -0
- data/spec/resources/sample.txt +0 -1
- data/spec/support/http_stub/configurer_integration.rb +0 -24
- data/spec/support/http_stub/empty_configurer.rb +0 -7
- data/spec/support/http_stub/scenario_fixture.rb +0 -33
- data/spec/support/http_stub/stub_fixture.rb +0 -125
- data/spec/support/http_stub/stub_registrator.rb +0 -83
@@ -0,0 +1,113 @@
|
|
1
|
+
describe HttpStub::Configurator::State do
|
2
|
+
|
3
|
+
let(:port) { 8888 }
|
4
|
+
|
5
|
+
let(:state) { described_class.new }
|
6
|
+
|
7
|
+
before(:example) { state.port = port }
|
8
|
+
|
9
|
+
describe "#external_base_uri" do
|
10
|
+
|
11
|
+
subject { state.external_base_uri }
|
12
|
+
|
13
|
+
before(:example) { @initial_base_uri = ENV["STUB_EXTERNAL_BASE_URI"] }
|
14
|
+
|
15
|
+
after(:example) { ENV["STUB_EXTERNAL_BASE_URI"] = @initial_base_uri }
|
16
|
+
|
17
|
+
context "when the STUB_EXTERNAL_BASE_URI environment variable is established" do
|
18
|
+
|
19
|
+
let(:base_uri) { "http://some/base/uri" }
|
20
|
+
|
21
|
+
before(:example) { ENV["STUB_EXTERNAL_BASE_URI"] = base_uri }
|
22
|
+
|
23
|
+
after(:example) { ENV["STUB_EXTERNAL_BASE_URI"] = @initial_base_uri }
|
24
|
+
|
25
|
+
it "returns the environments variables value" do
|
26
|
+
expect(subject).to eql(base_uri)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when the STUB_EXTERNAL_BASE_URI environment variable is not established" do
|
32
|
+
|
33
|
+
before(:example) { ENV["STUB_EXTERNAL_BASE_URI"] = nil }
|
34
|
+
|
35
|
+
it "returns a local uri containing the port" do
|
36
|
+
expect(subject).to eql("http://localhost:#{port}")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#add_scenario" do
|
44
|
+
|
45
|
+
let(:scenario_hash) { { some_scenario_key: "some value" } }
|
46
|
+
let(:scenario) { instance_double(HttpStub::Configurator::Scenario, to_hash: scenario_hash) }
|
47
|
+
|
48
|
+
subject { state.add_scenario(scenario) }
|
49
|
+
|
50
|
+
it "adds the hash representation of the scenario" do
|
51
|
+
subject
|
52
|
+
|
53
|
+
expect(state.scenario_hashes).to include(scenario_hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#add_stub" do
|
59
|
+
|
60
|
+
let(:stub_hash) { { some_stub_key: "some value" } }
|
61
|
+
let(:the_stub) { instance_double(HttpStub::Configurator::Stub::Stub, to_hash: stub_hash) }
|
62
|
+
|
63
|
+
subject { state.add_stub(the_stub) }
|
64
|
+
|
65
|
+
it "adds the hash representation of the stub" do
|
66
|
+
subject
|
67
|
+
|
68
|
+
expect(state.stub_hashes).to include(stub_hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#application_settings" do
|
74
|
+
|
75
|
+
subject { state.application_settings }
|
76
|
+
|
77
|
+
it "includes the configured port" do
|
78
|
+
expect(subject).to include(port: port)
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when a session identifier is provided" do
|
82
|
+
|
83
|
+
let(:session_identifier) { { parameter: "some_session_identifier" } }
|
84
|
+
|
85
|
+
before(:example) { state.session_identifier = session_identifier }
|
86
|
+
|
87
|
+
it "includes the session identifier" do
|
88
|
+
expect(subject).to include(session_identifier: session_identifier)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when cross-origin support is enabled" do
|
94
|
+
|
95
|
+
before(:example) { state.enable(:cross_origin_support) }
|
96
|
+
|
97
|
+
it "indicates cross-origin support is enabled" do
|
98
|
+
expect(subject).to include(cross_origin_support: true)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when cross-origin support is disabled" do
|
104
|
+
|
105
|
+
it "indicates cross-origin support is disabled" do
|
106
|
+
expect(subject).to include(cross_origin_support: false)
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,867 @@
|
|
1
|
+
describe HttpStub::Configurator::Stub::Stub do
|
2
|
+
|
3
|
+
let(:parent_stub) { nil }
|
4
|
+
|
5
|
+
let(:composed_stub) { described_class.new(parent_stub) }
|
6
|
+
|
7
|
+
let(:composed_stub_match_rules_payload) { composed_stub.to_hash[:match_rules] }
|
8
|
+
let(:composed_stub_response_payload) { composed_stub.to_hash[:response] }
|
9
|
+
let(:composed_stub_triggers_payload) { composed_stub.to_hash[:triggers] }
|
10
|
+
|
11
|
+
shared_context "triggers one scenario" do
|
12
|
+
|
13
|
+
let(:trigger_scenario) { "Some triggered scenario" }
|
14
|
+
|
15
|
+
before(:example) { composed_stub.trigger(scenario: trigger_scenario) }
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
shared_context "triggers many scenarios" do
|
20
|
+
|
21
|
+
let(:trigger_scenarios) { (1..3).map { |i| "Some triggered scenario #{i}" } }
|
22
|
+
|
23
|
+
before(:example) { composed_stub.trigger(scenarios: trigger_scenarios) }
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
shared_context "triggers one stub" do
|
28
|
+
|
29
|
+
let(:trigger_stub_hash) { { trigger_key: "trigger value" } }
|
30
|
+
let(:trigger_stub) { instance_double(described_class, to_hash: trigger_stub_hash) }
|
31
|
+
|
32
|
+
before(:example) { composed_stub.trigger(stub: trigger_stub) }
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
shared_context "triggers many stubs" do
|
37
|
+
|
38
|
+
let(:trigger_stub_hashes) { (1..3).map { |i| { trigger_key: "trigger value #{i}" } } }
|
39
|
+
let(:trigger_stubs) { trigger_stub_hashes.map { |hash| instance_double(described_class, to_hash: hash) } }
|
40
|
+
|
41
|
+
before(:example) { composed_stub.trigger(stubs: trigger_stubs) }
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "constructor" do
|
46
|
+
|
47
|
+
class HttpStub::Configurator::Stub::StubWithObservedMerge < HttpStub::Configurator::Stub::Stub
|
48
|
+
|
49
|
+
attr_reader :merged_stubs
|
50
|
+
|
51
|
+
def initialize(parent=nil, &block)
|
52
|
+
@merged_stubs = []
|
53
|
+
super(parent, &block)
|
54
|
+
end
|
55
|
+
|
56
|
+
def merge!(stub)
|
57
|
+
@merged_stubs << stub
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when a parent stub is provided" do
|
63
|
+
|
64
|
+
let(:parent_stub) { instance_double(described_class) }
|
65
|
+
|
66
|
+
let(:composed_stub) { HttpStub::Configurator::Stub::StubWithObservedMerge.new(parent_stub) }
|
67
|
+
|
68
|
+
it "merges the parent stub" do
|
69
|
+
composed_stub
|
70
|
+
|
71
|
+
expect(composed_stub.merged_stubs).to eql([ parent_stub ])
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when a block is provided" do
|
77
|
+
|
78
|
+
let(:block_verifier) { double("BlockVerifier", verify: nil) }
|
79
|
+
let(:block) { lambda { |builder| block_verifier.verify(builder) } }
|
80
|
+
|
81
|
+
let(:composed_stub) { HttpStub::Configurator::Stub::StubWithObservedMerge.new(&block) }
|
82
|
+
|
83
|
+
it "creates a stub that is yielded to the provided block" do
|
84
|
+
expect(block_verifier).to receive(:verify).with(a_kind_of(described_class))
|
85
|
+
|
86
|
+
composed_stub
|
87
|
+
end
|
88
|
+
|
89
|
+
it "does not merge any parent stubs" do
|
90
|
+
composed_stub
|
91
|
+
|
92
|
+
expect(composed_stub.merged_stubs).to eql([])
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when neither a parent stub or block is provided" do
|
98
|
+
|
99
|
+
let(:composed_stub) { HttpStub::Configurator::Stub::StubWithObservedMerge.new(nil) }
|
100
|
+
|
101
|
+
it "does not merge any parent stub" do
|
102
|
+
composed_stub
|
103
|
+
|
104
|
+
expect(composed_stub.merged_stubs).to eql([])
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#match_requests" do
|
112
|
+
|
113
|
+
let(:fixture) { HttpStub::Configurator::StubBuilder.new }
|
114
|
+
|
115
|
+
subject { composed_stub.match_requests(fixture.match_rules) }
|
116
|
+
|
117
|
+
it "returns the stub to support method chaining" do
|
118
|
+
expect(subject).to eql(composed_stub)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#schema" do
|
124
|
+
|
125
|
+
let(:type) { :some_type }
|
126
|
+
|
127
|
+
subject { composed_stub.schema(type, schema_definition) }
|
128
|
+
|
129
|
+
context "when a definition is provided in a ruby hash" do
|
130
|
+
|
131
|
+
let(:schema_definition) { { schema: "definition" } }
|
132
|
+
|
133
|
+
it "returns a hash with a :schema entry containing both the type and schema definition" do
|
134
|
+
expect(subject).to eql(schema: { type: type, definition: schema_definition })
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "#respond_with" do
|
142
|
+
|
143
|
+
context "when a block is provided referencing the matching request" do
|
144
|
+
|
145
|
+
let(:response_block) { lambda { |request| { headers: request.headers[:some_header] } } }
|
146
|
+
|
147
|
+
subject { composed_stub.respond_with(&response_block) }
|
148
|
+
|
149
|
+
it "adds the block to the stub payloads response" do
|
150
|
+
subject
|
151
|
+
|
152
|
+
expect(composed_stub_response_payload).to include(blocks: [ response_block ])
|
153
|
+
end
|
154
|
+
|
155
|
+
it "returns the stub to support method chaining" do
|
156
|
+
expect(subject).to eql(composed_stub)
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
context "when a hash is provided" do
|
162
|
+
|
163
|
+
let(:response_hash) { { status: 201 } }
|
164
|
+
|
165
|
+
subject { composed_stub.respond_with(response_hash) }
|
166
|
+
|
167
|
+
it "includes the proivded hash in the stub payloads response" do
|
168
|
+
subject
|
169
|
+
|
170
|
+
expect(composed_stub_response_payload).to include(response_hash)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "returns the stub to support method chaining" do
|
174
|
+
expect(subject).to eql(composed_stub)
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#trigger" do
|
182
|
+
|
183
|
+
let(:args) { {} }
|
184
|
+
|
185
|
+
subject { composed_stub.trigger(args) }
|
186
|
+
|
187
|
+
it "returns the stub to support method chaining" do
|
188
|
+
expect(subject).to eql(composed_stub)
|
189
|
+
end
|
190
|
+
|
191
|
+
context "when scenarios are provided" do
|
192
|
+
|
193
|
+
let(:scenarios) { (1..3).map { |i| "Scenario name #{i}" } }
|
194
|
+
|
195
|
+
let(:args) { { scenarios: scenarios } }
|
196
|
+
|
197
|
+
it "adds the scenarios" do
|
198
|
+
subject
|
199
|
+
|
200
|
+
expect(composed_stub_triggers_payload).to include(scenario_names: scenarios)
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
context "when a scenario is provided" do
|
206
|
+
|
207
|
+
let(:scenario) { "Some scenario name" }
|
208
|
+
|
209
|
+
let(:args) { { scenario: scenario } }
|
210
|
+
|
211
|
+
it "adds the scenario" do
|
212
|
+
subject
|
213
|
+
|
214
|
+
expect(composed_stub_triggers_payload).to include(scenario_names: [ scenario ])
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
context "when stubs are provided" do
|
220
|
+
|
221
|
+
let(:stub_hashes) { (1..3).map { |i| { stub_key: "stub value #{i}" } } }
|
222
|
+
let(:stubs) { stub_hashes.map { |hash| instance_double(described_class, to_hash: hash) } }
|
223
|
+
|
224
|
+
let(:args) { { stubs: stubs } }
|
225
|
+
|
226
|
+
it "adds the stubs" do
|
227
|
+
subject
|
228
|
+
|
229
|
+
expect(composed_stub_triggers_payload).to include(stubs: stub_hashes)
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
context "when a stub is provided" do
|
235
|
+
|
236
|
+
let(:stub_hash) { { stub_key: "stub value" } }
|
237
|
+
let(:stub) { instance_double(described_class, to_hash: stub_hash) }
|
238
|
+
|
239
|
+
let(:args) { { stub: stub } }
|
240
|
+
|
241
|
+
it "adds the stub" do
|
242
|
+
subject
|
243
|
+
|
244
|
+
expect(composed_stub_triggers_payload).to include(stubs: [ stub_hash ])
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "#invoke" do
|
252
|
+
|
253
|
+
context "when the block accepts an argument" do
|
254
|
+
|
255
|
+
subject { composed_stub.invoke { |a_stub| a_stub.match_requests(uri: "/some_uri") } }
|
256
|
+
|
257
|
+
it "invokes the block with the stub as the argument" do
|
258
|
+
expect(composed_stub).to receive(:match_requests).with(uri: "/some_uri")
|
259
|
+
|
260
|
+
subject
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
context "when the block accepts no arguments" do
|
266
|
+
|
267
|
+
subject { composed_stub.invoke { match_requests(uri: "/some_uri") } }
|
268
|
+
|
269
|
+
it "invokes the block in the context of the stub" do
|
270
|
+
expect(composed_stub).to receive(:match_requests).with(uri: "/some_uri")
|
271
|
+
|
272
|
+
subject
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
describe "#merge!" do
|
280
|
+
|
281
|
+
subject { composed_stub.merge!(provided_stub) }
|
282
|
+
|
283
|
+
shared_context "a completely configured provided stub" do
|
284
|
+
|
285
|
+
let(:provided_trigger_scenarios) { (1..3).map { |i| "Triggered scenario #{i}" } }
|
286
|
+
let(:provided_trigger_stub_hashes) { (1..3).map { |i| { trigger_hash_key: "trigger hash value #{i}" } } }
|
287
|
+
let(:provided_trigger_stubs) do
|
288
|
+
provided_trigger_stub_hashes.map { |hash| instance_double(described_class, to_hash: hash) }
|
289
|
+
end
|
290
|
+
|
291
|
+
let(:provided_stub) do
|
292
|
+
described_class.new.tap do |a_stub|
|
293
|
+
a_stub.match_requests(uri: "/replacement_uri",
|
294
|
+
method: :put,
|
295
|
+
headers: { request_header_key: "replacement request header value",
|
296
|
+
other_request_header_key: "other request header value" },
|
297
|
+
parameters: { parameter_key: "replacement parameter value",
|
298
|
+
other_request_parameter_key: "other request parameter value" })
|
299
|
+
a_stub.respond_with(status: 203,
|
300
|
+
headers: { response_header_key: "replacement response header value",
|
301
|
+
other_response_header_key: "other response header value" },
|
302
|
+
body: "replacement body value",
|
303
|
+
delay_in_seconds: 3)
|
304
|
+
a_stub.trigger(scenarios: provided_trigger_scenarios,
|
305
|
+
stubs: provided_trigger_stubs)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
context "when the stub has been completely configured" do
|
312
|
+
|
313
|
+
let(:original_trigger_scenarios) { (1..3).map { |i| "Original trigger scenario #{i}" } }
|
314
|
+
let(:original_trigger_stub_hashes) { (1..3).map { |i| { match_rules: { uri: "original/uri/#{i}" } } } }
|
315
|
+
let(:original_trigger_stubs) do
|
316
|
+
original_trigger_stub_hashes.map { |hash| instance_double(described_class, to_hash: hash) }
|
317
|
+
end
|
318
|
+
|
319
|
+
before(:example) do
|
320
|
+
composed_stub.match_requests(uri: "/original_uri",
|
321
|
+
method: :get,
|
322
|
+
headers: { request_header_key: "original request header value" },
|
323
|
+
parameters: { parameter_key: "original parameter value" })
|
324
|
+
composed_stub.respond_with(status: 202,
|
325
|
+
headers: { response_header_key: "original response header value" },
|
326
|
+
body: "original body",
|
327
|
+
delay_in_seconds: 2)
|
328
|
+
composed_stub.trigger(scenarios: original_trigger_scenarios,
|
329
|
+
stubs: original_trigger_stubs)
|
330
|
+
end
|
331
|
+
|
332
|
+
context "and a stub that is completely configured is provided" do
|
333
|
+
include_context "a completely configured provided stub"
|
334
|
+
|
335
|
+
it "replaces the matched uri" do
|
336
|
+
subject
|
337
|
+
|
338
|
+
expect(composed_stub_match_rules_payload).to include(uri: "/replacement_uri")
|
339
|
+
end
|
340
|
+
|
341
|
+
it "replaces the matched method" do
|
342
|
+
subject
|
343
|
+
|
344
|
+
expect(composed_stub_match_rules_payload).to include(method: :put)
|
345
|
+
end
|
346
|
+
|
347
|
+
it "deeply merges the matched headers" do
|
348
|
+
subject
|
349
|
+
|
350
|
+
expect(composed_stub_match_rules_payload).to(
|
351
|
+
include(headers: { request_header_key: "replacement request header value",
|
352
|
+
other_request_header_key: "other request header value" })
|
353
|
+
)
|
354
|
+
end
|
355
|
+
|
356
|
+
it "deeply merges the matched parameters" do
|
357
|
+
subject
|
358
|
+
|
359
|
+
expect(composed_stub_match_rules_payload).to(
|
360
|
+
include(parameters: { parameter_key: "replacement parameter value",
|
361
|
+
other_request_parameter_key: "other request parameter value" })
|
362
|
+
)
|
363
|
+
end
|
364
|
+
|
365
|
+
it "replaces the response status" do
|
366
|
+
subject
|
367
|
+
|
368
|
+
expect(composed_stub_response_payload).to include(status: 203)
|
369
|
+
end
|
370
|
+
|
371
|
+
it "deeply merges the response headers" do
|
372
|
+
subject
|
373
|
+
|
374
|
+
expect(composed_stub_response_payload).to(
|
375
|
+
include(headers: { response_header_key: "replacement response header value",
|
376
|
+
other_response_header_key: "other response header value" })
|
377
|
+
)
|
378
|
+
end
|
379
|
+
|
380
|
+
it "replaces the response body" do
|
381
|
+
subject
|
382
|
+
|
383
|
+
expect(composed_stub_response_payload).to include(body: "replacement body value")
|
384
|
+
end
|
385
|
+
|
386
|
+
it "replaces the response delay" do
|
387
|
+
subject
|
388
|
+
|
389
|
+
expect(composed_stub_response_payload).to include(delay_in_seconds: 3)
|
390
|
+
end
|
391
|
+
|
392
|
+
it "adds to the triggered scenarios" do
|
393
|
+
subject
|
394
|
+
|
395
|
+
expect(composed_stub_triggers_payload).to(
|
396
|
+
include(scenario_names: original_trigger_scenarios + provided_trigger_scenarios)
|
397
|
+
)
|
398
|
+
end
|
399
|
+
|
400
|
+
it "adds to the triggered stubs" do
|
401
|
+
subject
|
402
|
+
|
403
|
+
expect(composed_stub_triggers_payload).to(
|
404
|
+
include(stubs: original_trigger_stub_hashes + provided_trigger_stub_hashes)
|
405
|
+
)
|
406
|
+
end
|
407
|
+
|
408
|
+
end
|
409
|
+
|
410
|
+
context "and a stub that is empty is provided" do
|
411
|
+
|
412
|
+
let(:provided_stub) { described_class.new }
|
413
|
+
|
414
|
+
it "preserves the matched uri" do
|
415
|
+
subject
|
416
|
+
|
417
|
+
expect(composed_stub_match_rules_payload).to include(uri: "/original_uri")
|
418
|
+
end
|
419
|
+
|
420
|
+
it "preserves the matched method" do
|
421
|
+
subject
|
422
|
+
|
423
|
+
expect(composed_stub_match_rules_payload).to include(method: :get)
|
424
|
+
end
|
425
|
+
|
426
|
+
it "preserves the matched headers" do
|
427
|
+
subject
|
428
|
+
|
429
|
+
expect(composed_stub_match_rules_payload).to(
|
430
|
+
include(headers: { request_header_key: "original request header value" })
|
431
|
+
)
|
432
|
+
end
|
433
|
+
|
434
|
+
it "preserves the matched parameters" do
|
435
|
+
subject
|
436
|
+
|
437
|
+
expect(composed_stub_match_rules_payload).to(
|
438
|
+
include(parameters: { parameter_key: "original parameter value" })
|
439
|
+
)
|
440
|
+
end
|
441
|
+
|
442
|
+
it "preserves the response status" do
|
443
|
+
subject
|
444
|
+
|
445
|
+
expect(composed_stub_response_payload).to include(status: 202)
|
446
|
+
end
|
447
|
+
|
448
|
+
it "preserves the response headers" do
|
449
|
+
subject
|
450
|
+
|
451
|
+
expect(composed_stub_response_payload).to(
|
452
|
+
include(headers: { response_header_key: "original response header value" })
|
453
|
+
)
|
454
|
+
end
|
455
|
+
|
456
|
+
it "preserves the response body" do
|
457
|
+
subject
|
458
|
+
|
459
|
+
expect(composed_stub_response_payload).to include(body: "original body")
|
460
|
+
end
|
461
|
+
|
462
|
+
it "preserves the response delay" do
|
463
|
+
subject
|
464
|
+
|
465
|
+
expect(composed_stub_response_payload).to include(delay_in_seconds: 2)
|
466
|
+
end
|
467
|
+
|
468
|
+
it "preserves the triggered scenarios" do
|
469
|
+
subject
|
470
|
+
|
471
|
+
expect(composed_stub_triggers_payload).to include(scenario_names: original_trigger_scenarios)
|
472
|
+
end
|
473
|
+
|
474
|
+
it "preserves the triggered stubs" do
|
475
|
+
subject
|
476
|
+
|
477
|
+
expect(composed_stub_triggers_payload).to include(stubs: original_trigger_stub_hashes)
|
478
|
+
end
|
479
|
+
|
480
|
+
end
|
481
|
+
|
482
|
+
end
|
483
|
+
|
484
|
+
context "when the stub has not been previously configured" do
|
485
|
+
include_context "a completely configured provided stub"
|
486
|
+
|
487
|
+
it "assumes the provided matched uri" do
|
488
|
+
subject
|
489
|
+
|
490
|
+
expect(composed_stub_match_rules_payload).to include(uri: "/replacement_uri")
|
491
|
+
end
|
492
|
+
|
493
|
+
it "assumes the provided matched method" do
|
494
|
+
subject
|
495
|
+
|
496
|
+
expect(composed_stub_match_rules_payload).to include(method: :put)
|
497
|
+
end
|
498
|
+
|
499
|
+
it "assumes the provided matched headers" do
|
500
|
+
subject
|
501
|
+
|
502
|
+
expect(composed_stub_match_rules_payload).to(
|
503
|
+
include(headers: { request_header_key: "replacement request header value",
|
504
|
+
other_request_header_key: "other request header value" })
|
505
|
+
)
|
506
|
+
end
|
507
|
+
|
508
|
+
it "assumes the provided matched parameters" do
|
509
|
+
subject
|
510
|
+
|
511
|
+
expect(composed_stub_match_rules_payload).to(
|
512
|
+
include(parameters: { parameter_key: "replacement parameter value",
|
513
|
+
other_request_parameter_key: "other request parameter value" })
|
514
|
+
)
|
515
|
+
end
|
516
|
+
|
517
|
+
it "assumes the provided response status" do
|
518
|
+
subject
|
519
|
+
|
520
|
+
expect(composed_stub_response_payload).to include(status: 203)
|
521
|
+
end
|
522
|
+
|
523
|
+
it "assumes the provided response headers" do
|
524
|
+
subject
|
525
|
+
|
526
|
+
expect(composed_stub_response_payload).to(
|
527
|
+
include(headers: { response_header_key: "replacement response header value",
|
528
|
+
other_response_header_key: "other response header value" })
|
529
|
+
)
|
530
|
+
end
|
531
|
+
|
532
|
+
it "assumes the provided response body" do
|
533
|
+
subject
|
534
|
+
|
535
|
+
expect(composed_stub_response_payload).to include(body: "replacement body value")
|
536
|
+
end
|
537
|
+
|
538
|
+
it "assumes the provided response delay" do
|
539
|
+
subject
|
540
|
+
|
541
|
+
expect(composed_stub_response_payload).to include(delay_in_seconds: 3)
|
542
|
+
end
|
543
|
+
|
544
|
+
it "assumes the provided triggered scenarios" do
|
545
|
+
subject
|
546
|
+
|
547
|
+
expect(composed_stub_triggers_payload).to include(scenario_names: provided_trigger_scenarios)
|
548
|
+
end
|
549
|
+
|
550
|
+
it "assumes the provided triggered stubs" do
|
551
|
+
subject
|
552
|
+
|
553
|
+
expect(composed_stub_triggers_payload).to include(stubs: provided_trigger_stub_hashes)
|
554
|
+
end
|
555
|
+
|
556
|
+
end
|
557
|
+
|
558
|
+
end
|
559
|
+
|
560
|
+
describe "#id" do
|
561
|
+
|
562
|
+
let(:fixture) { HttpStub::Configurator::StubBuilder.new }
|
563
|
+
|
564
|
+
subject { composed_stub.id }
|
565
|
+
|
566
|
+
before(:example) do
|
567
|
+
fixture.with_response_block!
|
568
|
+
fixture.with_triggered_scenarios!
|
569
|
+
end
|
570
|
+
|
571
|
+
context "when a stub has been supplied data" do
|
572
|
+
|
573
|
+
before(:example) do
|
574
|
+
composed_stub.match_requests(fixture.match_rules)
|
575
|
+
composed_stub.respond_with(fixture.response)
|
576
|
+
end
|
577
|
+
|
578
|
+
it "returns a string identifying the stub" do
|
579
|
+
expect(composed_stub.id).to be_a(String)
|
580
|
+
end
|
581
|
+
|
582
|
+
context "when the stubs data has not changed" do
|
583
|
+
|
584
|
+
it "always returns an equal value" do
|
585
|
+
expect(subject).to eql(composed_stub.id)
|
586
|
+
end
|
587
|
+
|
588
|
+
end
|
589
|
+
|
590
|
+
context "when the stubs data has changed" do
|
591
|
+
|
592
|
+
before(:example) do
|
593
|
+
@initial_id = composed_stub.id
|
594
|
+
|
595
|
+
composed_stub.match_requests(uri: "some_other_uri")
|
596
|
+
end
|
597
|
+
|
598
|
+
it "returns a different value" do
|
599
|
+
expect(subject).to_not eql(@initial_id)
|
600
|
+
end
|
601
|
+
|
602
|
+
end
|
603
|
+
|
604
|
+
context "when compared with that of another stub" do
|
605
|
+
|
606
|
+
let(:other_composed_stub) { described_class.new(parent_stub) }
|
607
|
+
|
608
|
+
before(:example) do
|
609
|
+
other_composed_stub.match_requests(fixture.match_rules)
|
610
|
+
other_composed_stub.respond_with(fixture.response)
|
611
|
+
end
|
612
|
+
|
613
|
+
context "who has the same data" do
|
614
|
+
|
615
|
+
it "returns the same value" do
|
616
|
+
expect(subject).to eql(other_composed_stub.id)
|
617
|
+
end
|
618
|
+
|
619
|
+
end
|
620
|
+
|
621
|
+
context "who has different data" do
|
622
|
+
|
623
|
+
before(:example) { other_composed_stub.trigger(fixture.triggers) }
|
624
|
+
|
625
|
+
it "returns a different value" do
|
626
|
+
expect(subject).to_not eql(other_composed_stub.id)
|
627
|
+
end
|
628
|
+
|
629
|
+
end
|
630
|
+
|
631
|
+
end
|
632
|
+
|
633
|
+
end
|
634
|
+
|
635
|
+
context "when a stub has not been supplied data" do
|
636
|
+
|
637
|
+
it "always returns an equal value" do
|
638
|
+
expect(subject).to eql(composed_stub.id)
|
639
|
+
end
|
640
|
+
|
641
|
+
end
|
642
|
+
|
643
|
+
end
|
644
|
+
|
645
|
+
describe "#to_hash" do
|
646
|
+
|
647
|
+
let(:fixture) { HttpStub::Configurator::StubBuilder.new }
|
648
|
+
let(:triggers) { { scenarios: [], stubs: [] } }
|
649
|
+
|
650
|
+
subject do
|
651
|
+
composed_stub.match_requests(fixture.match_rules.to_hash)
|
652
|
+
composed_stub.respond_with(fixture.response.to_hash)
|
653
|
+
composed_stub.trigger(triggers)
|
654
|
+
|
655
|
+
composed_stub.to_hash
|
656
|
+
end
|
657
|
+
|
658
|
+
it "returns a hash with indifferent access" do
|
659
|
+
expect(subject).to be_a(HashWithIndifferentAccess)
|
660
|
+
end
|
661
|
+
|
662
|
+
context "when provided with request match and response data" do
|
663
|
+
|
664
|
+
it "creates a hash with match rules that include the uri and the match options" do
|
665
|
+
expect(subject[:match_rules]).to eql(fixture.match_rules.to_hash)
|
666
|
+
end
|
667
|
+
|
668
|
+
it "creates a hash with response arguments" do
|
669
|
+
expect(subject[:response]).to eql(fixture.response.to_hash)
|
670
|
+
end
|
671
|
+
|
672
|
+
context "and the response data contains blocks" do
|
673
|
+
|
674
|
+
before(:example) { fixture.with_response_block! }
|
675
|
+
|
676
|
+
it "creates a hash with response arguments that include the blocks" do
|
677
|
+
expect(subject[:response]).to include(blocks: fixture.response.blocks)
|
678
|
+
end
|
679
|
+
|
680
|
+
end
|
681
|
+
|
682
|
+
describe "creates a hash with triggers that" do
|
683
|
+
|
684
|
+
context "when a scenario trigger is added" do
|
685
|
+
include_context "triggers one scenario"
|
686
|
+
|
687
|
+
it "contain the provided trigger scenario name" do
|
688
|
+
expect(subject[:triggers]).to include(scenario_names: [ trigger_scenario ])
|
689
|
+
|
690
|
+
subject
|
691
|
+
end
|
692
|
+
|
693
|
+
end
|
694
|
+
|
695
|
+
context "when many scenario triggers are added" do
|
696
|
+
include_context "triggers many scenarios"
|
697
|
+
|
698
|
+
it "contain the provided trigger scenario names" do
|
699
|
+
expect(subject[:triggers]).to include(scenario_names: trigger_scenarios)
|
700
|
+
|
701
|
+
subject
|
702
|
+
end
|
703
|
+
|
704
|
+
end
|
705
|
+
|
706
|
+
context "when a stub trigger is added" do
|
707
|
+
include_context "triggers one stub"
|
708
|
+
|
709
|
+
it "contain the provided triggerred stub hash" do
|
710
|
+
expect(subject[:triggers]).to include(stubs: [ trigger_stub_hash ])
|
711
|
+
|
712
|
+
subject
|
713
|
+
end
|
714
|
+
|
715
|
+
end
|
716
|
+
|
717
|
+
context "when many stub triggers are added" do
|
718
|
+
include_context "triggers many stubs"
|
719
|
+
|
720
|
+
it "contains the provided triggerred stub hashes" do
|
721
|
+
expect(subject[:triggers]).to include(stubs: trigger_stub_hashes)
|
722
|
+
|
723
|
+
subject
|
724
|
+
end
|
725
|
+
|
726
|
+
end
|
727
|
+
|
728
|
+
end
|
729
|
+
|
730
|
+
context "when a stub is provided that contains defaults" do
|
731
|
+
|
732
|
+
let(:match_rule_defaults) do
|
733
|
+
{
|
734
|
+
uri: "/uri/value",
|
735
|
+
headers: { "request_header_name_1" => "request header value 1",
|
736
|
+
"request_header_name_2" => "request header value 2" },
|
737
|
+
parameters: { "parameter_name_1" => "parameter value 1",
|
738
|
+
"parameter_name_2" => "parameter value 2" },
|
739
|
+
body: "body value"
|
740
|
+
}
|
741
|
+
end
|
742
|
+
let(:response_block_default) do
|
743
|
+
lambda do
|
744
|
+
{ status: 301 }
|
745
|
+
end
|
746
|
+
end
|
747
|
+
let(:response_defaults) do
|
748
|
+
{
|
749
|
+
status: 203,
|
750
|
+
headers: { "response_header_name_1" => "response header value 1",
|
751
|
+
"response_header_name_2" => "response header value 2" },
|
752
|
+
body: "some body",
|
753
|
+
delay_in_seconds: 8,
|
754
|
+
blocks: [ response_block_default ]
|
755
|
+
}
|
756
|
+
end
|
757
|
+
let(:trigger_scenario_defaults) { (1..3).map { |i| "Default trigger scenario #{i}" } }
|
758
|
+
let(:trigger_stub_hash_defaults) { (1..3).map { |i| { match_request: { uri: "Default stub uri #{i}" } } } }
|
759
|
+
|
760
|
+
let(:parent_hash) do
|
761
|
+
{
|
762
|
+
match_rules: match_rule_defaults,
|
763
|
+
response: response_defaults,
|
764
|
+
triggers: { scenario_names: trigger_scenario_defaults,
|
765
|
+
stubs: trigger_stub_hash_defaults }
|
766
|
+
}
|
767
|
+
end
|
768
|
+
let(:parent_stub) { instance_double(described_class, to_hash: parent_hash) }
|
769
|
+
|
770
|
+
describe "the match rules payload" do
|
771
|
+
|
772
|
+
let(:match_rule_overrides) do
|
773
|
+
{
|
774
|
+
uri: "/some/updated/uri",
|
775
|
+
headers: { "request_header_name_2" => "updated request header value 2",
|
776
|
+
"request_header_name_3" => "request header value 3" },
|
777
|
+
parameters: { "parameter_name_2" => "updated parameter value 2",
|
778
|
+
"parameter_name_3" => "parameter value 3" },
|
779
|
+
body: "updated body value"
|
780
|
+
}
|
781
|
+
end
|
782
|
+
|
783
|
+
before(:example) { fixture.match_rules = match_rule_overrides }
|
784
|
+
|
785
|
+
it "merges any defaults with values established in the stub" do
|
786
|
+
expect(subject[:match_rules]).to eql(
|
787
|
+
{
|
788
|
+
uri: "/some/updated/uri",
|
789
|
+
headers: { "request_header_name_1" => "request header value 1",
|
790
|
+
"request_header_name_2" => "updated request header value 2",
|
791
|
+
"request_header_name_3" => "request header value 3" },
|
792
|
+
parameters: { "parameter_name_1" => "parameter value 1",
|
793
|
+
"parameter_name_2" => "updated parameter value 2",
|
794
|
+
"parameter_name_3" => "parameter value 3" },
|
795
|
+
body: "updated body value"
|
796
|
+
}.with_indifferent_access
|
797
|
+
)
|
798
|
+
end
|
799
|
+
|
800
|
+
end
|
801
|
+
|
802
|
+
describe "the response payload" do
|
803
|
+
|
804
|
+
let(:response_block_override) do
|
805
|
+
lambda do
|
806
|
+
{ status: 400 }
|
807
|
+
end
|
808
|
+
end
|
809
|
+
let(:response_overrides) do
|
810
|
+
{
|
811
|
+
status: 302,
|
812
|
+
headers: { "response_header_name_2" => "updated response header value 2",
|
813
|
+
"response_header_name_3" => "response header value 3" },
|
814
|
+
body: "updated body",
|
815
|
+
blocks: [ response_block_override ]
|
816
|
+
}
|
817
|
+
end
|
818
|
+
|
819
|
+
before(:example) { fixture.response = response_overrides }
|
820
|
+
|
821
|
+
it "merges any defaults with values established in the stub" do
|
822
|
+
expect(subject[:response]).to eql(
|
823
|
+
{
|
824
|
+
status: 302,
|
825
|
+
headers: { "response_header_name_1" => "response header value 1",
|
826
|
+
"response_header_name_2" => "updated response header value 2",
|
827
|
+
"response_header_name_3" => "response header value 3" },
|
828
|
+
body: "updated body",
|
829
|
+
delay_in_seconds: 8,
|
830
|
+
blocks: [ response_block_default, response_block_override ]
|
831
|
+
}.with_indifferent_access
|
832
|
+
)
|
833
|
+
end
|
834
|
+
|
835
|
+
end
|
836
|
+
|
837
|
+
describe "the triggers payload" do
|
838
|
+
|
839
|
+
let(:trigger_scenarios) { (1..3).map { |i| "Trigger scenario #{i}" } }
|
840
|
+
let(:trigger_stub_hashes) { (1..3).map { |i| { trigger_key: "trigger #{i}" } } }
|
841
|
+
let(:trigger_stubs) do
|
842
|
+
trigger_stub_hashes.map { |hash| instance_double(described_class, to_hash: hash) }
|
843
|
+
end
|
844
|
+
|
845
|
+
let(:triggers) { { scenarios: trigger_scenarios, stubs: trigger_stubs } }
|
846
|
+
|
847
|
+
it "combines any scenario defaults with values established in the stub" do
|
848
|
+
expect(subject[:triggers]).to include(scenario_names: trigger_scenario_defaults + trigger_scenarios)
|
849
|
+
|
850
|
+
subject
|
851
|
+
end
|
852
|
+
|
853
|
+
it "combines any stub defaults with values established in the stub" do
|
854
|
+
expect(subject[:triggers]).to include(stubs: trigger_stub_hash_defaults + trigger_stub_hashes)
|
855
|
+
|
856
|
+
subject
|
857
|
+
end
|
858
|
+
|
859
|
+
end
|
860
|
+
|
861
|
+
end
|
862
|
+
|
863
|
+
end
|
864
|
+
|
865
|
+
end
|
866
|
+
|
867
|
+
end
|