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
@@ -1,747 +0,0 @@
|
|
1
|
-
describe HttpStub::Configurer::DSL::StubBuilder do
|
2
|
-
|
3
|
-
let(:default_builder) { nil }
|
4
|
-
|
5
|
-
let(:builder) { HttpStub::Configurer::DSL::StubBuilder.new(default_builder) }
|
6
|
-
|
7
|
-
shared_context "triggers one scenario" do
|
8
|
-
|
9
|
-
let(:trigger_scenario) { "Some triggered scenario" }
|
10
|
-
|
11
|
-
before(:example) { builder.trigger(scenario: trigger_scenario) }
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
shared_context "triggers many scenarios" do
|
16
|
-
|
17
|
-
let(:trigger_scenarios) { (1..3).map { |i| "Some triggered scenario #{i}" } }
|
18
|
-
|
19
|
-
before(:example) { builder.trigger(scenarios: trigger_scenarios) }
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
shared_context "triggers one stub" do
|
24
|
-
|
25
|
-
let(:trigger_stub) { instance_double(HttpStub::Configurer::Request::Stub) }
|
26
|
-
let(:trigger_stub_builder) { instance_double(described_class, build: trigger_stub) }
|
27
|
-
|
28
|
-
before(:example) { builder.trigger(stub: trigger_stub_builder) }
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
shared_context "triggers many stubs" do
|
33
|
-
|
34
|
-
let(:trigger_stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
|
35
|
-
let(:trigger_stub_builders) do
|
36
|
-
trigger_stubs.map { |stub| instance_double(described_class, build: stub) }
|
37
|
-
end
|
38
|
-
|
39
|
-
before(:example) { builder.trigger(stubs: trigger_stub_builders) }
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "constructor" do
|
44
|
-
|
45
|
-
class HttpStub::Configurer::DSL::StubBuilderWithObservedMerge < HttpStub::Configurer::DSL::StubBuilder
|
46
|
-
|
47
|
-
attr_reader :merged_stub_builders
|
48
|
-
|
49
|
-
def initialize(parent_builder=nil, &block)
|
50
|
-
@merged_stub_builders = []
|
51
|
-
super(parent_builder, &block)
|
52
|
-
end
|
53
|
-
|
54
|
-
def merge!(stub_builder)
|
55
|
-
@merged_stub_builders << stub_builder
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when a parent builder is provided" do
|
61
|
-
|
62
|
-
let(:parent_builder) { instance_double(described_class) }
|
63
|
-
|
64
|
-
let(:builder) { HttpStub::Configurer::DSL::StubBuilderWithObservedMerge.new(parent_builder) }
|
65
|
-
|
66
|
-
it "merges the parent builder" do
|
67
|
-
builder
|
68
|
-
|
69
|
-
expect(builder.merged_stub_builders).to eql([ parent_builder ])
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
context "when a block is provided" do
|
75
|
-
|
76
|
-
let(:block_verifier) { double("BlockVerifier", verify: nil) }
|
77
|
-
let(:block) { lambda { |builder| block_verifier.verify(builder) } }
|
78
|
-
|
79
|
-
let(:builder) { HttpStub::Configurer::DSL::StubBuilderWithObservedMerge.new(&block) }
|
80
|
-
|
81
|
-
it "creates a builder that is yielded to the provided block" do
|
82
|
-
expect(block_verifier).to receive(:verify).with(a_kind_of(described_class))
|
83
|
-
|
84
|
-
builder
|
85
|
-
end
|
86
|
-
|
87
|
-
it "does not merge any parent builders" do
|
88
|
-
builder
|
89
|
-
|
90
|
-
expect(builder.merged_stub_builders).to eql([])
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
context "when neither a parent builder or block is provided" do
|
96
|
-
|
97
|
-
let(:builder) { HttpStub::Configurer::DSL::StubBuilderWithObservedMerge.new(nil) }
|
98
|
-
|
99
|
-
it "does not merge any parent builder" do
|
100
|
-
builder
|
101
|
-
|
102
|
-
expect(builder.merged_stub_builders).to eql([])
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
describe "#match_requests" do
|
111
|
-
|
112
|
-
let(:fixture) { HttpStub::StubFixture.new }
|
113
|
-
|
114
|
-
subject { builder.match_requests(fixture.request.symbolized) }
|
115
|
-
|
116
|
-
it "returns the builder to support method chaining" do
|
117
|
-
expect(subject).to eql(builder)
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "#schema" do
|
123
|
-
|
124
|
-
let(:type) { :some_type }
|
125
|
-
|
126
|
-
subject { builder.schema(type, schema_definition) }
|
127
|
-
|
128
|
-
context "when a definition is provided in a ruby hash" do
|
129
|
-
|
130
|
-
let(:schema_definition) { { schema: "definition" } }
|
131
|
-
|
132
|
-
it "returns a hash with a :schema entry containing both the type and schema definition" do
|
133
|
-
expect(subject).to eql(schema: { type: type, definition: schema_definition })
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "#respond_with" do
|
141
|
-
|
142
|
-
context "when a block is provided referencing the matching request" do
|
143
|
-
|
144
|
-
let(:request_referencer) { instance_double(HttpStub::Configurer::DSL::RequestReferencer) }
|
145
|
-
|
146
|
-
subject { builder.respond_with { |request| { headers: request.headers[:some_header] } } }
|
147
|
-
|
148
|
-
it "includes the hash returned from the evaluated block in the response hash" do
|
149
|
-
subject
|
150
|
-
|
151
|
-
expect(builder.response).to include(headers: a_string_matching(/^control/))
|
152
|
-
end
|
153
|
-
|
154
|
-
it "returns the builder to support method chaining" do
|
155
|
-
expect(subject).to eql(builder)
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
context "when a block is not provided" do
|
161
|
-
|
162
|
-
subject { builder.respond_with(status: 201) }
|
163
|
-
|
164
|
-
it "includes the proivded hash in the response hash" do
|
165
|
-
subject
|
166
|
-
|
167
|
-
expect(builder.response).to include(status: 201)
|
168
|
-
end
|
169
|
-
|
170
|
-
it "returns the builder to support method chaining" do
|
171
|
-
expect(subject).to eql(builder)
|
172
|
-
end
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
describe "#trigger" do
|
179
|
-
|
180
|
-
let(:args) { {} }
|
181
|
-
|
182
|
-
subject { builder.trigger(args) }
|
183
|
-
|
184
|
-
it "returns the builder to support method chaining" do
|
185
|
-
expect(subject).to eql(builder)
|
186
|
-
end
|
187
|
-
|
188
|
-
context "when scenarios are provided" do
|
189
|
-
|
190
|
-
let(:scenarios) { (1..3).map { |i| "Scenario name #{i}" } }
|
191
|
-
|
192
|
-
let(:args) { { scenarios: scenarios } }
|
193
|
-
|
194
|
-
it "adds the scenarios" do
|
195
|
-
subject
|
196
|
-
|
197
|
-
expect(builder.triggers).to include(scenarios: scenarios)
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
|
202
|
-
context "when a scenario is provided" do
|
203
|
-
|
204
|
-
let(:scenario) { "Some scenario name" }
|
205
|
-
|
206
|
-
let(:args) { { scenario: scenario } }
|
207
|
-
|
208
|
-
it "adds the scenario" do
|
209
|
-
subject
|
210
|
-
|
211
|
-
expect(builder.triggers).to include(scenarios: [ scenario ])
|
212
|
-
end
|
213
|
-
|
214
|
-
end
|
215
|
-
|
216
|
-
context "when stubs are provided" do
|
217
|
-
|
218
|
-
let(:stubs) { (1..3).map { instance_double(described_class) } }
|
219
|
-
|
220
|
-
let(:args) { { stubs: stubs } }
|
221
|
-
|
222
|
-
it "adds the stubs" do
|
223
|
-
subject
|
224
|
-
|
225
|
-
expect(builder.triggers).to include(stubs: stubs)
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
context "when a stub is provided" do
|
231
|
-
|
232
|
-
let(:stub) { instance_double(described_class) }
|
233
|
-
|
234
|
-
let(:args) { { stub: stub } }
|
235
|
-
|
236
|
-
it "adds the stub" do
|
237
|
-
subject
|
238
|
-
|
239
|
-
expect(builder.triggers).to include(stubs: [ stub ])
|
240
|
-
end
|
241
|
-
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
describe "#invoke" do
|
247
|
-
|
248
|
-
context "when the block accepts an argument" do
|
249
|
-
|
250
|
-
subject { builder.invoke { |builder| builder.match_requests(uri: "/some_uri") } }
|
251
|
-
|
252
|
-
it "invokes the block with the builder as the argument" do
|
253
|
-
expect(builder).to receive(:match_requests).with(uri: "/some_uri")
|
254
|
-
|
255
|
-
subject
|
256
|
-
end
|
257
|
-
|
258
|
-
end
|
259
|
-
|
260
|
-
context "when the block accepts no arguments" do
|
261
|
-
|
262
|
-
subject { builder.invoke { match_requests(uri: "/some_uri") } }
|
263
|
-
|
264
|
-
it "invokes the block in the context of the builder" do
|
265
|
-
expect(builder).to receive(:match_requests).with(uri: "/some_uri")
|
266
|
-
|
267
|
-
subject
|
268
|
-
end
|
269
|
-
|
270
|
-
end
|
271
|
-
|
272
|
-
end
|
273
|
-
|
274
|
-
describe "#merge!" do
|
275
|
-
|
276
|
-
subject { builder.merge!(provided_builder) }
|
277
|
-
|
278
|
-
shared_context "a completely configured provided builder" do
|
279
|
-
|
280
|
-
let(:provided_trigger_scenarios) { (1..3).map { |i| "Triggered scenario #{i}" } }
|
281
|
-
let(:provided_trigger_stub_builders) { (1..3).map { instance_double(described_class) } }
|
282
|
-
|
283
|
-
let(:provided_builder) do
|
284
|
-
described_class.new.tap do |builder|
|
285
|
-
builder.match_requests(uri: "/replacement_uri", method: :put,
|
286
|
-
headers: { request_header_key: "replacement request header value",
|
287
|
-
other_request_header_key: "other request header value" },
|
288
|
-
parameters: { parameter_key: "replacement parameter value",
|
289
|
-
other_request_parameter_key: "other request parameter value" })
|
290
|
-
builder.respond_with(status: 203,
|
291
|
-
headers: { response_header_key: "reaplcement response header value",
|
292
|
-
other_response_header_key: "other response header value" },
|
293
|
-
body: "replacement body value",
|
294
|
-
delay_in_seconds: 3)
|
295
|
-
builder.trigger(scenarios: provided_trigger_scenarios,
|
296
|
-
stubs: provided_trigger_stub_builders)
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
end
|
301
|
-
|
302
|
-
context "when the builder has been completely configured" do
|
303
|
-
|
304
|
-
let(:original_trigger_scenarios) { (1..3).map { |i| "Original trigger scenario #{i}" } }
|
305
|
-
let(:original_trigger_stub_builders) { (1..3).map { instance_double(described_class) } }
|
306
|
-
|
307
|
-
before(:example) do
|
308
|
-
builder.match_requests(uri: "/original_uri", method: :get,
|
309
|
-
headers: { request_header_key: "original request header value" },
|
310
|
-
parameters: { parameter_key: "original parameter value" })
|
311
|
-
builder.respond_with(status: 202,
|
312
|
-
headers: { response_header_key: "original response header value" },
|
313
|
-
body: "original body",
|
314
|
-
delay_in_seconds: 2)
|
315
|
-
builder.trigger(scenarios: original_trigger_scenarios,
|
316
|
-
stubs: original_trigger_stub_builders)
|
317
|
-
end
|
318
|
-
|
319
|
-
context "and a builder that is completely configured is provided" do
|
320
|
-
include_context "a completely configured provided builder"
|
321
|
-
|
322
|
-
it "replaces the uri" do
|
323
|
-
subject
|
324
|
-
|
325
|
-
expect(builder.request).to include(uri: "/replacement_uri")
|
326
|
-
end
|
327
|
-
|
328
|
-
it "replaces the request method" do
|
329
|
-
subject
|
330
|
-
|
331
|
-
expect(builder.request).to include(method: :put)
|
332
|
-
end
|
333
|
-
|
334
|
-
it "deeply merges the request headers" do
|
335
|
-
subject
|
336
|
-
|
337
|
-
expect(builder.request).to include(headers: { request_header_key: "replacement request header value",
|
338
|
-
other_request_header_key: "other request header value" })
|
339
|
-
end
|
340
|
-
|
341
|
-
it "deeply merges the request parameters" do
|
342
|
-
subject
|
343
|
-
|
344
|
-
expect(builder.request).to(
|
345
|
-
include(parameters: { parameter_key: "replacement parameter value",
|
346
|
-
other_request_parameter_key: "other request parameter value" })
|
347
|
-
)
|
348
|
-
end
|
349
|
-
|
350
|
-
it "replaces the response status" do
|
351
|
-
subject
|
352
|
-
|
353
|
-
expect(builder.response).to include(status: 203)
|
354
|
-
end
|
355
|
-
|
356
|
-
it "deeply merges the response headers" do
|
357
|
-
subject
|
358
|
-
|
359
|
-
expect(builder.response).to include(headers: { response_header_key: "reaplcement response header value",
|
360
|
-
other_response_header_key: "other response header value" })
|
361
|
-
end
|
362
|
-
|
363
|
-
it "replaces the body" do
|
364
|
-
subject
|
365
|
-
|
366
|
-
expect(builder.response).to include(body: "replacement body value")
|
367
|
-
end
|
368
|
-
|
369
|
-
it "replaces the response delay" do
|
370
|
-
subject
|
371
|
-
|
372
|
-
expect(builder.response).to include(delay_in_seconds: 3)
|
373
|
-
end
|
374
|
-
|
375
|
-
it "adds to the triggered scenarios" do
|
376
|
-
subject
|
377
|
-
|
378
|
-
expect(builder.triggers).to include(scenarios: original_trigger_scenarios + provided_trigger_scenarios)
|
379
|
-
end
|
380
|
-
|
381
|
-
it "adds to the triggered stubs" do
|
382
|
-
subject
|
383
|
-
|
384
|
-
expect(builder.triggers).to include(stubs: original_trigger_stub_builders + provided_trigger_stub_builders)
|
385
|
-
end
|
386
|
-
|
387
|
-
end
|
388
|
-
|
389
|
-
context "and a builder that is empty is provided" do
|
390
|
-
|
391
|
-
let(:provided_builder) { described_class.new }
|
392
|
-
|
393
|
-
it "preserves the uri" do
|
394
|
-
subject
|
395
|
-
|
396
|
-
expect(builder.request).to include(uri: "/original_uri")
|
397
|
-
end
|
398
|
-
|
399
|
-
it "preserves the request method" do
|
400
|
-
subject
|
401
|
-
|
402
|
-
expect(builder.request).to include(method: :get)
|
403
|
-
end
|
404
|
-
|
405
|
-
it "preserves the request headers" do
|
406
|
-
subject
|
407
|
-
|
408
|
-
expect(builder.request).to include(headers: { request_header_key: "original request header value" })
|
409
|
-
end
|
410
|
-
|
411
|
-
it "preserves the request parameters" do
|
412
|
-
subject
|
413
|
-
|
414
|
-
expect(builder.request).to include(parameters: { parameter_key: "original parameter value" })
|
415
|
-
end
|
416
|
-
|
417
|
-
it "preserves the response status" do
|
418
|
-
subject
|
419
|
-
|
420
|
-
expect(builder.response).to include(status: 202)
|
421
|
-
end
|
422
|
-
|
423
|
-
it "preserves the response headers" do
|
424
|
-
subject
|
425
|
-
|
426
|
-
expect(builder.response).to include(headers: { response_header_key: "original response header value" })
|
427
|
-
end
|
428
|
-
|
429
|
-
it "preserves the body" do
|
430
|
-
subject
|
431
|
-
|
432
|
-
expect(builder.response).to include(body: "original body")
|
433
|
-
end
|
434
|
-
|
435
|
-
it "preserves the response delay" do
|
436
|
-
subject
|
437
|
-
|
438
|
-
expect(builder.response).to include(delay_in_seconds: 2)
|
439
|
-
end
|
440
|
-
|
441
|
-
it "preserves the triggered scenarios" do
|
442
|
-
subject
|
443
|
-
|
444
|
-
expect(builder.triggers).to include(scenarios: original_trigger_scenarios)
|
445
|
-
end
|
446
|
-
|
447
|
-
it "preserves the triggered stubs" do
|
448
|
-
subject
|
449
|
-
|
450
|
-
expect(builder.triggers).to include(stubs: original_trigger_stub_builders)
|
451
|
-
end
|
452
|
-
|
453
|
-
end
|
454
|
-
|
455
|
-
end
|
456
|
-
|
457
|
-
context "when the builder has not been previously configured" do
|
458
|
-
include_context "a completely configured provided builder"
|
459
|
-
|
460
|
-
it "assumes the provided uri" do
|
461
|
-
subject
|
462
|
-
|
463
|
-
expect(builder.request).to include(uri: "/replacement_uri")
|
464
|
-
end
|
465
|
-
|
466
|
-
it "assumes the provided request method" do
|
467
|
-
subject
|
468
|
-
|
469
|
-
expect(builder.request).to include(method: :put)
|
470
|
-
end
|
471
|
-
|
472
|
-
it "assumes the provided request headers" do
|
473
|
-
subject
|
474
|
-
|
475
|
-
expect(builder.request).to include(headers: { request_header_key: "replacement request header value",
|
476
|
-
other_request_header_key: "other request header value" })
|
477
|
-
end
|
478
|
-
|
479
|
-
it "assumes the provided request parameters" do
|
480
|
-
subject
|
481
|
-
|
482
|
-
expect(builder.request).to(
|
483
|
-
include(parameters: { parameter_key: "replacement parameter value",
|
484
|
-
other_request_parameter_key: "other request parameter value" })
|
485
|
-
)
|
486
|
-
end
|
487
|
-
|
488
|
-
it "assumes the provided response status" do
|
489
|
-
subject
|
490
|
-
|
491
|
-
expect(builder.response).to include(status: 203)
|
492
|
-
end
|
493
|
-
|
494
|
-
it "assumes the provided response headers" do
|
495
|
-
subject
|
496
|
-
|
497
|
-
expect(builder.response).to include(headers: { response_header_key: "reaplcement response header value",
|
498
|
-
other_response_header_key: "other response header value" })
|
499
|
-
end
|
500
|
-
|
501
|
-
it "assumes the provided response body" do
|
502
|
-
subject
|
503
|
-
|
504
|
-
expect(builder.response).to include(body: "replacement body value")
|
505
|
-
end
|
506
|
-
|
507
|
-
it "assumes the provided response delay" do
|
508
|
-
subject
|
509
|
-
|
510
|
-
expect(builder.response).to include(delay_in_seconds: 3)
|
511
|
-
end
|
512
|
-
|
513
|
-
it "assumes the provided triggered scenarios" do
|
514
|
-
subject
|
515
|
-
|
516
|
-
expect(builder.triggers).to include(scenarios: provided_trigger_scenarios)
|
517
|
-
end
|
518
|
-
|
519
|
-
it "assumes the provided triggered stubs" do
|
520
|
-
subject
|
521
|
-
|
522
|
-
expect(builder.triggers).to include(stubs: provided_trigger_stub_builders)
|
523
|
-
end
|
524
|
-
|
525
|
-
end
|
526
|
-
|
527
|
-
end
|
528
|
-
|
529
|
-
describe "#build" do
|
530
|
-
|
531
|
-
let(:fixture) { HttpStub::StubFixture.new }
|
532
|
-
let(:triggers) { { scenarios: [], stubs: [] } }
|
533
|
-
let(:stub) { instance_double(HttpStub::Configurer::Request::Stub) }
|
534
|
-
|
535
|
-
subject do
|
536
|
-
builder.match_requests(fixture.request.symbolized)
|
537
|
-
builder.respond_with(fixture.response.symbolized)
|
538
|
-
builder.trigger(triggers)
|
539
|
-
|
540
|
-
builder.build
|
541
|
-
end
|
542
|
-
|
543
|
-
before(:example) { allow(HttpStub::Configurer::Request::Stub).to receive(:new).and_return(stub) }
|
544
|
-
|
545
|
-
context "when provided a request match and response data" do
|
546
|
-
|
547
|
-
it "creates a stub payload with request options that include the uri and the provided request options" do
|
548
|
-
expect_stub_to_be_created_with(request: fixture.request.symbolized)
|
549
|
-
|
550
|
-
subject
|
551
|
-
end
|
552
|
-
|
553
|
-
it "creates a stub payload with response arguments" do
|
554
|
-
expect_stub_to_be_created_with(response: fixture.response.symbolized)
|
555
|
-
|
556
|
-
subject
|
557
|
-
end
|
558
|
-
|
559
|
-
describe "creates a stub payload with triggers that" do
|
560
|
-
|
561
|
-
context "when a scenario trigger is added" do
|
562
|
-
include_context "triggers one scenario"
|
563
|
-
|
564
|
-
it "contains the provided trigger scenario name" do
|
565
|
-
expect_stub_to_be_created_with_triggers(scenario_names: [ trigger_scenario ])
|
566
|
-
|
567
|
-
subject
|
568
|
-
end
|
569
|
-
|
570
|
-
end
|
571
|
-
|
572
|
-
context "when many scenario triggers are added" do
|
573
|
-
include_context "triggers many scenarios"
|
574
|
-
|
575
|
-
it "contains the provided trigger scenario names" do
|
576
|
-
expect_stub_to_be_created_with_triggers(scenario_names: trigger_scenarios)
|
577
|
-
|
578
|
-
subject
|
579
|
-
end
|
580
|
-
|
581
|
-
end
|
582
|
-
|
583
|
-
context "when a stub trigger is added" do
|
584
|
-
include_context "triggers one stub"
|
585
|
-
|
586
|
-
it "contains the provided trigger builder" do
|
587
|
-
expect_stub_to_be_created_with_triggers(stubs: [ trigger_stub ])
|
588
|
-
|
589
|
-
subject
|
590
|
-
end
|
591
|
-
|
592
|
-
end
|
593
|
-
|
594
|
-
context "when many stub triggers are added" do
|
595
|
-
include_context "triggers many stubs"
|
596
|
-
|
597
|
-
it "contains the provided trigger builders" do
|
598
|
-
expect_stub_to_be_created_with_triggers(stubs: trigger_stubs)
|
599
|
-
|
600
|
-
subject
|
601
|
-
end
|
602
|
-
|
603
|
-
end
|
604
|
-
|
605
|
-
end
|
606
|
-
|
607
|
-
context "when a default stub builder is provided that contains defaults" do
|
608
|
-
|
609
|
-
let(:request_defaults) do
|
610
|
-
{
|
611
|
-
uri: "/uri/value",
|
612
|
-
headers: { "request_header_name_1" => "request header value 1",
|
613
|
-
"request_header_name_2" => "request header value 2" },
|
614
|
-
parameters: { "parameter_name_1" => "parameter value 1",
|
615
|
-
"parameter_name_2" => "parameter value 2" },
|
616
|
-
body: "body value"
|
617
|
-
}
|
618
|
-
end
|
619
|
-
let(:response_defaults) do
|
620
|
-
{
|
621
|
-
status: 203,
|
622
|
-
headers: { "response_header_name_1" => "response header value 1",
|
623
|
-
"response_header_name_2" => "response header value 2" },
|
624
|
-
body: "some body",
|
625
|
-
delay_in_seconds: 8
|
626
|
-
}
|
627
|
-
end
|
628
|
-
let(:trigger_scenario_defaults) { (1..3).map { |i| "Default trigger scenario #{i}" } }
|
629
|
-
let(:trigger_stub_defaults) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
|
630
|
-
let(:trigger_stub_builder_defaults) do
|
631
|
-
trigger_stub_defaults.map { |stub| instance_double(described_class, build: stub) }
|
632
|
-
end
|
633
|
-
|
634
|
-
let(:default_builder) do
|
635
|
-
instance_double(described_class, request: request_defaults,
|
636
|
-
response: response_defaults,
|
637
|
-
triggers: { scenarios: trigger_scenario_defaults,
|
638
|
-
stubs: trigger_stub_builder_defaults })
|
639
|
-
end
|
640
|
-
|
641
|
-
describe "the built request payload" do
|
642
|
-
|
643
|
-
let(:request_overrides) do
|
644
|
-
{
|
645
|
-
uri: "/some/updated/uri",
|
646
|
-
headers: { "request_header_name_2" => "updated request header value 2",
|
647
|
-
"request_header_name_3" => "request header value 3" },
|
648
|
-
parameters: { "parameter_name_2" => "updated parameter value 2",
|
649
|
-
"parameter_name_3" => "parameter value 3" },
|
650
|
-
body: "updated body value"
|
651
|
-
}
|
652
|
-
end
|
653
|
-
|
654
|
-
before(:example) { fixture.request = request_overrides }
|
655
|
-
|
656
|
-
it "overrides any defaults with values established in the stub" do
|
657
|
-
expect_stub_to_be_created_with(
|
658
|
-
request: {
|
659
|
-
uri: "/some/updated/uri",
|
660
|
-
headers: { "request_header_name_1" => "request header value 1",
|
661
|
-
"request_header_name_2" => "updated request header value 2",
|
662
|
-
"request_header_name_3" => "request header value 3" },
|
663
|
-
parameters: { "parameter_name_1" => "parameter value 1",
|
664
|
-
"parameter_name_2" => "updated parameter value 2",
|
665
|
-
"parameter_name_3" => "parameter value 3" },
|
666
|
-
body: "updated body value"
|
667
|
-
}
|
668
|
-
)
|
669
|
-
|
670
|
-
subject
|
671
|
-
end
|
672
|
-
|
673
|
-
end
|
674
|
-
|
675
|
-
describe "the built response payload" do
|
676
|
-
|
677
|
-
let(:response_overrides) do
|
678
|
-
{
|
679
|
-
status: 302,
|
680
|
-
headers: { "response_header_name_2" => "updated response header value 2",
|
681
|
-
"response_header_name_3" => "response header value 3" },
|
682
|
-
body: "updated body"
|
683
|
-
}
|
684
|
-
end
|
685
|
-
|
686
|
-
before(:example) { fixture.response = response_overrides }
|
687
|
-
|
688
|
-
it "overrides any defaults with values established in the stub" do
|
689
|
-
expect_stub_to_be_created_with(
|
690
|
-
response: {
|
691
|
-
status: 302,
|
692
|
-
headers: { "response_header_name_1" => "response header value 1",
|
693
|
-
"response_header_name_2" => "updated response header value 2",
|
694
|
-
"response_header_name_3" => "response header value 3" },
|
695
|
-
body: "updated body",
|
696
|
-
delay_in_seconds: 8
|
697
|
-
}
|
698
|
-
)
|
699
|
-
|
700
|
-
subject
|
701
|
-
end
|
702
|
-
|
703
|
-
end
|
704
|
-
|
705
|
-
describe "the built triggers payload" do
|
706
|
-
|
707
|
-
let(:trigger_scenarios) { (1..3).map { |i| "Trigger scenario #{i}" } }
|
708
|
-
let(:trigger_stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
|
709
|
-
let(:trigger_stub_builders) do
|
710
|
-
trigger_stubs.map { |stub| instance_double(described_class, build: stub) }
|
711
|
-
end
|
712
|
-
|
713
|
-
let(:triggers) { { scenarios: trigger_scenarios, stubs: trigger_stub_builders } }
|
714
|
-
|
715
|
-
it "combines any scenario defaults with values established in the stub" do
|
716
|
-
expect_stub_to_be_created_with_triggers(scenario_names: trigger_scenario_defaults + trigger_scenarios)
|
717
|
-
|
718
|
-
subject
|
719
|
-
end
|
720
|
-
|
721
|
-
it "combines any stub defaults with values established in the stub" do
|
722
|
-
expect_stub_to_be_created_with_triggers(stubs: trigger_stub_defaults + trigger_stubs)
|
723
|
-
|
724
|
-
subject
|
725
|
-
end
|
726
|
-
|
727
|
-
end
|
728
|
-
|
729
|
-
end
|
730
|
-
|
731
|
-
it "returns the created stub" do
|
732
|
-
expect(subject).to eql(stub)
|
733
|
-
end
|
734
|
-
|
735
|
-
end
|
736
|
-
|
737
|
-
def expect_stub_to_be_created_with(args)
|
738
|
-
expect(HttpStub::Configurer::Request::Stub).to receive(:new).with(hash_including(args))
|
739
|
-
end
|
740
|
-
|
741
|
-
def expect_stub_to_be_created_with_triggers(args)
|
742
|
-
expect_stub_to_be_created_with(triggers: hash_including(args))
|
743
|
-
end
|
744
|
-
|
745
|
-
end
|
746
|
-
|
747
|
-
end
|