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,4 +1,4 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Configurator::Stub::Template do
|
2
2
|
|
3
3
|
let(:parent_uri) { "/some/parent/uri" }
|
4
4
|
let(:parent_template) do
|
@@ -10,31 +10,31 @@ describe HttpStub::Configurer::DSL::StubBuilderTemplate do
|
|
10
10
|
let(:initial_request_method) { :put }
|
11
11
|
let(:initial_block) { lambda { |stub| stub.match_requests(method: initial_request_method) } }
|
12
12
|
|
13
|
-
let(:
|
13
|
+
let(:template) { described_class.new }
|
14
14
|
|
15
|
-
shared_context "mocked stub
|
15
|
+
shared_context "mocked stub" do
|
16
16
|
|
17
|
-
let(:
|
17
|
+
let(:templates_stub) { instance_double(HttpStub::Configurator::Stub::Stub) }
|
18
18
|
|
19
|
-
before(:example) { allow(HttpStub::
|
19
|
+
before(:example) { allow(HttpStub::Configurator::Stub::Stub).to receive(:new).and_return(templates_stub) }
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
it "creates a stub
|
24
|
-
allow(HttpStub::
|
23
|
+
it "creates a stub to hold values established on the template" do
|
24
|
+
allow(HttpStub::Configurator::Stub::Stub).to receive(:new)
|
25
25
|
|
26
|
-
|
26
|
+
template
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#match_requests" do
|
30
|
-
include_context "mocked stub
|
30
|
+
include_context "mocked stub"
|
31
31
|
|
32
32
|
let(:request_matching_rules) { { uri: "/some/stub/uri", method: :get } }
|
33
33
|
|
34
|
-
subject {
|
34
|
+
subject { template.match_requests(request_matching_rules) }
|
35
35
|
|
36
|
-
it "delegates to the templates stub
|
37
|
-
expect(
|
36
|
+
it "delegates to the templates stub" do
|
37
|
+
expect(templates_stub).to receive(:match_requests).with(request_matching_rules)
|
38
38
|
|
39
39
|
subject
|
40
40
|
end
|
@@ -42,22 +42,22 @@ describe HttpStub::Configurer::DSL::StubBuilderTemplate do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe "#schema" do
|
45
|
-
include_context "mocked stub
|
45
|
+
include_context "mocked stub"
|
46
46
|
|
47
47
|
let(:type) { :some_schema_type }
|
48
48
|
let(:definition) { "some schema definition" }
|
49
49
|
|
50
|
-
subject {
|
50
|
+
subject { template.schema(type, definition) }
|
51
51
|
|
52
|
-
it "delegates to the templates stub
|
53
|
-
expect(
|
52
|
+
it "delegates to the templates stub" do
|
53
|
+
expect(templates_stub).to receive(:schema).with(type, definition)
|
54
54
|
|
55
55
|
subject
|
56
56
|
end
|
57
57
|
|
58
58
|
it "returns the created schema" do
|
59
59
|
schema = { schema: :some_schema }
|
60
|
-
expect(
|
60
|
+
expect(templates_stub).to receive(:schema).and_return(schema)
|
61
61
|
|
62
62
|
expect(subject).to eql(schema)
|
63
63
|
end
|
@@ -65,14 +65,14 @@ describe HttpStub::Configurer::DSL::StubBuilderTemplate do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
describe "#respond_with" do
|
68
|
-
include_context "mocked stub
|
68
|
+
include_context "mocked stub"
|
69
69
|
|
70
70
|
let(:response_settings) { { status: 204 } }
|
71
71
|
|
72
|
-
subject {
|
72
|
+
subject { template.respond_with(response_settings) }
|
73
73
|
|
74
|
-
it "delegates to the templates stub
|
75
|
-
expect(
|
74
|
+
it "delegates to the templates stub" do
|
75
|
+
expect(templates_stub).to receive(:respond_with).with(response_settings)
|
76
76
|
|
77
77
|
subject
|
78
78
|
end
|
@@ -80,14 +80,14 @@ describe HttpStub::Configurer::DSL::StubBuilderTemplate do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
describe "#trigger" do
|
83
|
-
include_context "mocked stub
|
83
|
+
include_context "mocked stub"
|
84
84
|
|
85
85
|
let(:trigger_settings) { { scenario: "some scenario name" } }
|
86
86
|
|
87
|
-
subject {
|
87
|
+
subject { template.trigger(trigger_settings) }
|
88
88
|
|
89
|
-
it "delegates to the templates stub
|
90
|
-
expect(
|
89
|
+
it "delegates to the templates stub" do
|
90
|
+
expect(templates_stub).to receive(:trigger).with(trigger_settings)
|
91
91
|
|
92
92
|
subject
|
93
93
|
end
|
@@ -95,7 +95,7 @@ describe HttpStub::Configurer::DSL::StubBuilderTemplate do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
describe "#invoke" do
|
98
|
-
include_context "mocked stub
|
98
|
+
include_context "mocked stub"
|
99
99
|
|
100
100
|
let(:block_verifier) { double("BlockVerifier") }
|
101
101
|
let(:block) do
|
@@ -105,16 +105,16 @@ describe HttpStub::Configurer::DSL::StubBuilderTemplate do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
let(:
|
108
|
+
let(:templates_stub) { HttpStub::Configurator::Stub::Stub.new }
|
109
109
|
|
110
|
-
subject {
|
110
|
+
subject { template.invoke(&block) }
|
111
111
|
|
112
112
|
it "invokes the block with the templates stub builder" do
|
113
113
|
expect(block_verifier).to receive(:verify)
|
114
114
|
|
115
115
|
subject
|
116
116
|
|
117
|
-
expect(@yielded_stub).to eql(
|
117
|
+
expect(@yielded_stub).to eql(templates_stub)
|
118
118
|
end
|
119
119
|
|
120
120
|
end
|
@@ -130,70 +130,72 @@ describe HttpStub::Configurer::DSL::StubBuilderTemplate do
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
let(:
|
133
|
+
let(:template) { described_class.new(parent_template) }
|
134
|
+
|
135
|
+
let(:built_stub_hash) { subject.to_hash }
|
134
136
|
|
135
|
-
subject {
|
137
|
+
subject { template.build_stub }
|
136
138
|
|
137
139
|
context "when a parent template had been provided" do
|
138
140
|
|
139
141
|
it "creates a stub capable of containing values established in the parent template" do
|
140
|
-
expect(
|
142
|
+
expect(built_stub_hash[:match_rules][:uri]).to eql(parent_uri)
|
141
143
|
end
|
142
144
|
|
143
145
|
end
|
144
146
|
|
145
147
|
context "when an initial block had been provided" do
|
146
148
|
|
147
|
-
let(:
|
149
|
+
let(:template) { described_class.new(&initial_block) }
|
148
150
|
|
149
151
|
it "creates a stub capable of containing values established in the initial block" do
|
150
|
-
expect(
|
152
|
+
expect(built_stub_hash[:match_rules][:method]).to eql(initial_request_method)
|
151
153
|
end
|
152
154
|
|
153
155
|
end
|
154
156
|
|
155
157
|
context "when response overrides are provided upon building the stub" do
|
156
158
|
|
157
|
-
subject {
|
159
|
+
subject { template.build_stub(response_overrides) }
|
158
160
|
|
159
161
|
it "creates a stub containing the overrides" do
|
160
|
-
expect(
|
162
|
+
expect(built_stub_hash[:response][:status]).to eql(201)
|
161
163
|
end
|
162
164
|
|
163
165
|
it "overrides any values initially established" do
|
164
|
-
expect(
|
166
|
+
expect(built_stub_hash[:response][:body]).to eql("response overrides body")
|
165
167
|
end
|
166
168
|
|
167
169
|
end
|
168
170
|
|
169
171
|
context "when a block is provided upon building the stub" do
|
170
172
|
|
171
|
-
subject {
|
173
|
+
subject { template.build_stub(&block) }
|
172
174
|
|
173
175
|
it "creates a stub that is modified by the block" do
|
174
|
-
expect(
|
176
|
+
expect(built_stub_hash[:match_rules][:uri]).to eql("/some/block/uri")
|
175
177
|
end
|
176
178
|
|
177
179
|
it "overrides any values initially established" do
|
178
|
-
expect(
|
180
|
+
expect(built_stub_hash[:response][:body]).to eql("block body")
|
179
181
|
end
|
180
182
|
|
181
183
|
end
|
182
184
|
|
183
185
|
context "when both response overrides and a block are provided" do
|
184
186
|
|
185
|
-
subject {
|
187
|
+
subject { template.build_stub(response_overrides, &block) }
|
186
188
|
|
187
189
|
it "creates a stub containing response overrides" do
|
188
|
-
expect(
|
190
|
+
expect(built_stub_hash[:response][:status]).to eql(201)
|
189
191
|
end
|
190
192
|
|
191
193
|
it "creates a stub that is modified by the block" do
|
192
|
-
expect(
|
194
|
+
expect(built_stub_hash[:match_rules][:uri]).to eql("/some/block/uri")
|
193
195
|
end
|
194
196
|
|
195
197
|
it "creates a stub with values established in the block taking precedence over response overrides" do
|
196
|
-
expect(
|
198
|
+
expect(built_stub_hash[:response][:body]).to eql("block body")
|
197
199
|
end
|
198
200
|
|
199
201
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe HttpStub::Configurator::Stub do
|
2
|
+
|
3
|
+
describe "::create" do
|
4
|
+
|
5
|
+
let(:name) { "some stub name" }
|
6
|
+
let(:block_verifier) { double("BlockVerifier") }
|
7
|
+
let(:block) { lambda { block_verifier.verify } }
|
8
|
+
|
9
|
+
subject { described_class.create(name, &block) }
|
10
|
+
|
11
|
+
it "creates a stub with the provided arguments" do
|
12
|
+
expect(HttpStub::Configurator::Stub::Stub).to receive(:new).with(name).and_yield
|
13
|
+
expect(block_verifier).to receive(:verify)
|
14
|
+
|
15
|
+
subject
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns the created stub" do
|
19
|
+
created_stub = instance_double(HttpStub::Configurator::Stub::Stub)
|
20
|
+
allow(HttpStub::Configurator::Stub::Stub).to receive(:new).and_return(created_stub)
|
21
|
+
|
22
|
+
expect(subject).to eql(created_stub)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
describe HttpStub::Configurator do
|
2
|
+
|
3
|
+
let(:configurator_class) { Class.new { include HttpStub::Configurator } }
|
4
|
+
let(:configurator) { configurator_class.new }
|
5
|
+
|
6
|
+
describe "::state" do
|
7
|
+
|
8
|
+
subject { configurator_class.state }
|
9
|
+
|
10
|
+
it "creates state for the configurator" do
|
11
|
+
expect(HttpStub::Configurator::State).to receive(:new)
|
12
|
+
|
13
|
+
subject
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the created state" do
|
17
|
+
state = HttpStub::Configurator::State.new
|
18
|
+
allow(HttpStub::Configurator::State).to receive(:new).and_return(state)
|
19
|
+
|
20
|
+
expect(subject).to eql(state)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "reuses the state in subsequent requests" do
|
24
|
+
expect(subject).to be(configurator_class.state)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "::stub_server" do
|
30
|
+
|
31
|
+
subject { configurator_class.stub_server }
|
32
|
+
|
33
|
+
it "creates a server" do
|
34
|
+
expect(HttpStub::Configurator::Server).to receive(:new)
|
35
|
+
|
36
|
+
subject
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns the created server" do
|
40
|
+
server = instance_double(HttpStub::Configurator::Server)
|
41
|
+
allow(HttpStub::Configurator::Server).to receive(:new).and_return(server)
|
42
|
+
|
43
|
+
expect(subject).to eql(server)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "reuses the stub server in subsequent requests" do
|
47
|
+
expect(subject).to be(configurator_class.stub_server)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "::parts=" do
|
53
|
+
|
54
|
+
class HttpStub::Configurator::TestablePart
|
55
|
+
include HttpStub::Configurator::Part
|
56
|
+
|
57
|
+
attr_reader :configurator_class
|
58
|
+
|
59
|
+
def apply_to(configurator_class)
|
60
|
+
@configurator_class = configurator_class
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:parts) { (1..3).map { HttpStub::Configurator::TestablePart.new } }
|
66
|
+
|
67
|
+
subject do
|
68
|
+
configurator_class.parts = { part_1: parts[0], part_2: parts[1], part_3: parts[2] }
|
69
|
+
end
|
70
|
+
|
71
|
+
it "allows each part to be accessed on the configurator by name" do
|
72
|
+
subject
|
73
|
+
|
74
|
+
parts_on_configurator = [ configurator.part_1, configurator.part_2, configurator.part_3 ]
|
75
|
+
expect(parts_on_configurator).to eql(parts)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "allows each part to be accessed on the configurator class by name" do
|
79
|
+
subject
|
80
|
+
|
81
|
+
parts_on_configurator_class = [ configurator_class.part_1, configurator_class.part_2, configurator_class.part_3 ]
|
82
|
+
expect(parts_on_configurator_class).to eql(parts)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "applies the parts to the configurator" do
|
86
|
+
subject
|
87
|
+
|
88
|
+
expect(parts.map(&:configurator_class)).to eql([ configurator_class ] * 3)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#state" do
|
94
|
+
|
95
|
+
subject { configurator.state }
|
96
|
+
|
97
|
+
it "returns the same state as the class method" do
|
98
|
+
expect(subject).to be(configurator_class.state)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#stub_server" do
|
104
|
+
|
105
|
+
subject { configurator.stub_server }
|
106
|
+
|
107
|
+
it "returns the same server as the class method" do
|
108
|
+
expect(subject).to be(configurator_class.stub_server)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -4,9 +4,9 @@ describe HttpStub::Extensions::Core::Hash do
|
|
4
4
|
|
5
5
|
subject { hash.underscore_keys }
|
6
6
|
|
7
|
-
|
7
|
+
context "when the hash contains keys which are strings" do
|
8
8
|
|
9
|
-
|
9
|
+
context "and keys contain underscores and hyphens" do
|
10
10
|
|
11
11
|
let(:hash) do
|
12
12
|
{ "has_underscore" => 1, "has-hypen" => 2, "has_underscore_and-hypen" => 3 }
|
@@ -20,7 +20,7 @@ describe HttpStub::Extensions::Core::Hash do
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
context "when the hash contains keys which are not strings" do
|
24
24
|
|
25
25
|
let(:hash) do
|
26
26
|
{ 1 => 2, :symbol => 3, nil => 4 }
|
@@ -0,0 +1,29 @@
|
|
1
|
+
describe HttpStub::Extensions::Core::Object do
|
2
|
+
|
3
|
+
it "patches ::Object" do
|
4
|
+
expect(::Object.included_modules).to include(described_class)
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#short_class_name" do
|
8
|
+
|
9
|
+
subject { object.short_class_name }
|
10
|
+
|
11
|
+
context "when a class name is a single word" do
|
12
|
+
|
13
|
+
it "returns the name in lower case" do
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when a class name contains many words" do
|
20
|
+
|
21
|
+
it "combines the words with an underscore" do
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -1,27 +1,32 @@
|
|
1
1
|
describe HttpStub::Rake::ServerDaemonTasks do
|
2
|
+
include_context "surpressed output"
|
2
3
|
include Rake::DSL
|
3
4
|
|
4
|
-
before(:context)
|
5
|
+
before(:context) do
|
6
|
+
@server_name_in_rakefile = :example_server_daemon
|
7
|
+
@port_in_rakefile = 8001
|
8
|
+
HttpStub::Rake::ServerDaemonTasks.new(
|
9
|
+
name: @server_name_in_rakefile,
|
10
|
+
configurator: HttpStub::ConfiguratorFixture.create(port: @port_in_rakefile)
|
11
|
+
)
|
12
|
+
end
|
5
13
|
|
6
14
|
describe "start task" do
|
7
15
|
|
8
16
|
context "when invoked" do
|
9
17
|
|
10
|
-
before(:context) { @exit_flag =
|
18
|
+
before(:context) { @exit_flag = system "rake #{@server_name_in_rakefile}:start > /dev/null" }
|
11
19
|
|
12
|
-
after(:context) {
|
20
|
+
after(:context) { system "rake #{@server_name_in_rakefile}:stop > /dev/null" }
|
13
21
|
|
14
22
|
it "exits with a status code of 0" do
|
15
|
-
expect(@exit_flag).to
|
23
|
+
expect(@exit_flag).to be(true)
|
16
24
|
end
|
17
25
|
|
18
26
|
it "starts a stub server that responds to stub requests" do
|
19
|
-
|
20
|
-
request.body = { response: { status: 302, body: "Some Body" } }.to_json
|
21
|
-
|
22
|
-
response = Net::HTTP.new("localhost", 8002).start { |http| http.request(request) }
|
27
|
+
response = HTTParty.get("http://localhost:#{@port_in_rakefile}/http_stub/stubs")
|
23
28
|
|
24
|
-
expect(response.code).to eql(
|
29
|
+
expect(response.code).to eql(200)
|
25
30
|
end
|
26
31
|
|
27
32
|
end
|