http_stub 0.27.0 → 0.28.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/http_stub/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,75 @@
|
|
1
|
+
describe HttpStub::Client::Server do
|
2
|
+
|
3
|
+
let(:base_uri) { "http://some/base/uri" }
|
4
|
+
|
5
|
+
let(:server) { described_class.new(base_uri) }
|
6
|
+
|
7
|
+
describe "::submit!" do
|
8
|
+
|
9
|
+
let(:response_code) { "200" }
|
10
|
+
let(:response_message) { "some response message" }
|
11
|
+
let(:response) { instance_double(Net::HTTPResponse, code: response_code, message: response_message) }
|
12
|
+
|
13
|
+
let(:request_args) { { key: "some value" } }
|
14
|
+
let(:request_error_message_prefix) { "some error message prefix" }
|
15
|
+
let(:request) do
|
16
|
+
instance_double(HttpStub::Client::Request, submit: response, error_message_prefix: request_error_message_prefix)
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { server.submit!(request_args) }
|
20
|
+
|
21
|
+
before(:example) { allow(HttpStub::Client::Request).to receive(:new).and_return(request) }
|
22
|
+
|
23
|
+
it "creates a request with the servers base uri" do
|
24
|
+
expect(HttpStub::Client::Request).to receive(:new).with(hash_including(base_uri: base_uri))
|
25
|
+
|
26
|
+
subject
|
27
|
+
end
|
28
|
+
|
29
|
+
it "creates a request with the provided arguments" do
|
30
|
+
expect(HttpStub::Client::Request).to receive(:new).with(hash_including(request_args))
|
31
|
+
|
32
|
+
subject
|
33
|
+
end
|
34
|
+
|
35
|
+
it "submits the request" do
|
36
|
+
expect(request).to receive(:submit)
|
37
|
+
|
38
|
+
subject
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "and the responses code is 200" do
|
42
|
+
|
43
|
+
let(:response_code) { "200" }
|
44
|
+
|
45
|
+
it "executes without error" do
|
46
|
+
expect { subject }.not_to raise_error
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns the server response" do
|
50
|
+
expect(subject).to eql(response)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "and the responses code is non-200" do
|
56
|
+
|
57
|
+
let(:response_code) { "400" }
|
58
|
+
|
59
|
+
it "raises an exception that describes the request" do
|
60
|
+
expect { subject }.to raise_error(/#{request_error_message_prefix}/)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "raises an exception that contains the response code" do
|
64
|
+
expect { subject }.to raise_error(/#{response_code}/)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "raises an exception that contains the responses message" do
|
68
|
+
expect { subject }.to raise_error(/#{response_message}/)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
describe HttpStub::Client::Session do
|
2
|
+
|
3
|
+
let(:id) { "some_session_id" }
|
4
|
+
let(:server) { instance_double(HttpStub::Client::Server, submit!: nil) }
|
5
|
+
|
6
|
+
let(:session) { described_class.new(id, server) }
|
7
|
+
|
8
|
+
describe "#activate!" do
|
9
|
+
|
10
|
+
let(:scenario_names) { (1..3).map { |i| "Scenario name #{i}" } }
|
11
|
+
|
12
|
+
subject { session.activate!(*scenario_names) }
|
13
|
+
|
14
|
+
it "submits a post request" do
|
15
|
+
expect_request_submission_with(method: :post)
|
16
|
+
|
17
|
+
subject
|
18
|
+
end
|
19
|
+
|
20
|
+
it "submits a request to the scenario activation endpoint" do
|
21
|
+
expect_request_submission_with(path: "scenarios/activate")
|
22
|
+
|
23
|
+
subject
|
24
|
+
end
|
25
|
+
|
26
|
+
it "creates a request identifying the session via a parameter" do
|
27
|
+
expect_request_submission_with(parameters: hash_including(http_stub_session_id: id))
|
28
|
+
|
29
|
+
subject
|
30
|
+
end
|
31
|
+
|
32
|
+
it "submits a request with the scenario names as a parameter" do
|
33
|
+
expect_request_submission_with(parameters: hash_including("names[]" => scenario_names))
|
34
|
+
|
35
|
+
subject
|
36
|
+
end
|
37
|
+
|
38
|
+
it "describes the intent of the request as to activate the provided scenarios" do
|
39
|
+
scenario_names_description = scenario_names.map { |name| "'#{name}'" }.join(", ")
|
40
|
+
expect_request_submission_with(intent: a_string_including("activate scenarios #{scenario_names_description}"))
|
41
|
+
|
42
|
+
subject
|
43
|
+
end
|
44
|
+
|
45
|
+
it "the intent of the request includes the session affected" do
|
46
|
+
expect_request_submission_with(intent: a_string_including("session '#{id}'"))
|
47
|
+
|
48
|
+
subject
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#reset!" do
|
54
|
+
|
55
|
+
subject { session.reset! }
|
56
|
+
|
57
|
+
it "submits a post request" do
|
58
|
+
expect_request_submission_with(method: :post)
|
59
|
+
|
60
|
+
subject
|
61
|
+
end
|
62
|
+
|
63
|
+
it "submits a request to the stubs reset endpoint" do
|
64
|
+
expect_request_submission_with(path: "stubs/reset")
|
65
|
+
|
66
|
+
subject
|
67
|
+
end
|
68
|
+
|
69
|
+
it "submits a request identifying the session via a parameter" do
|
70
|
+
expect_request_submission_with(parameters: hash_including(http_stub_session_id: id))
|
71
|
+
|
72
|
+
subject
|
73
|
+
end
|
74
|
+
|
75
|
+
it "describes the intent of the request as to reset stubs in the session" do
|
76
|
+
expect_request_submission_with(intent: "reset stubs in session '#{id}'")
|
77
|
+
|
78
|
+
subject
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#delete!" do
|
84
|
+
|
85
|
+
subject { session.delete! }
|
86
|
+
|
87
|
+
it "submits a delete request" do
|
88
|
+
expect_request_submission_with(method: :delete)
|
89
|
+
|
90
|
+
subject
|
91
|
+
end
|
92
|
+
|
93
|
+
it "submits a request to the sessions endpoint" do
|
94
|
+
expect_request_submission_with(path: "sessions")
|
95
|
+
|
96
|
+
subject
|
97
|
+
end
|
98
|
+
|
99
|
+
it "submits a request identifying the session via a parameter" do
|
100
|
+
expect_request_submission_with(parameters: hash_including(http_stub_session_id: id))
|
101
|
+
|
102
|
+
subject
|
103
|
+
end
|
104
|
+
|
105
|
+
it "describes the intent of the request as to delete the session" do
|
106
|
+
expect_request_submission_with(intent: "delete session '#{id}'")
|
107
|
+
|
108
|
+
subject
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
def expect_request_submission_with(element)
|
114
|
+
expect(server).to receive(:submit!).with(hash_including(element))
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
describe HttpStub::Client do
|
2
|
+
|
3
|
+
describe "::create" do
|
4
|
+
|
5
|
+
let(:server_uri) { "http://some.server.uri" }
|
6
|
+
|
7
|
+
subject { described_class.create(server_uri) }
|
8
|
+
|
9
|
+
it "returns a client" do
|
10
|
+
expect(subject).to be_an_instance_of(HttpStub::Client::Client)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -1,19 +1,17 @@
|
|
1
|
-
describe HttpStub::
|
1
|
+
describe HttpStub::Configurator::EndpointTemplate do
|
2
2
|
|
3
|
-
let(:server)
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
let(:initial_block_verifier) { double("BlockVerifier") }
|
9
|
-
let(:block) { lambda { initial_block_verifier.verify } }
|
3
|
+
let(:server) { instance_double(HttpStub::Configurator::Server) }
|
4
|
+
let(:default_stub_template) { instance_double(HttpStub::Configurator::Stub::Template) }
|
5
|
+
let(:endpoint_stub_template) { instance_double(HttpStub::Configurator::Stub::Template) }
|
6
|
+
let(:initial_block_verifier) { double("BlockVerifier") }
|
7
|
+
let(:initial_block) { lambda { initial_block_verifier.verify } }
|
10
8
|
|
11
|
-
let(:server_endpoint_template) { described_class.new(server,
|
9
|
+
let(:server_endpoint_template) { described_class.new(server, default_stub_template, &initial_block) }
|
12
10
|
|
13
|
-
before(:
|
11
|
+
before(:example) { allow(HttpStub::Configurator::Stub::Template).to receive(:new).and_return(endpoint_stub_template) }
|
14
12
|
|
15
|
-
it "creates a
|
16
|
-
expect(
|
13
|
+
it "creates a stub template that is initialized with provided default stub template and block" do
|
14
|
+
expect(HttpStub::Configurator::Stub::Template).to receive(:new).with(default_stub_template).and_yield
|
17
15
|
expect(initial_block_verifier).to receive(:verify)
|
18
16
|
|
19
17
|
server_endpoint_template
|
@@ -25,8 +23,8 @@ describe HttpStub::Configurer::DSL::ServerEndpointTemplate do
|
|
25
23
|
|
26
24
|
subject { server_endpoint_template.match_requests(request_matching_rules) }
|
27
25
|
|
28
|
-
it "delegates to the
|
29
|
-
expect(
|
26
|
+
it "delegates to the endpoints stub template" do
|
27
|
+
expect(endpoint_stub_template).to receive(:match_requests).with(request_matching_rules)
|
30
28
|
|
31
29
|
subject
|
32
30
|
end
|
@@ -40,15 +38,15 @@ describe HttpStub::Configurer::DSL::ServerEndpointTemplate do
|
|
40
38
|
|
41
39
|
subject { server_endpoint_template.schema(type, definition) }
|
42
40
|
|
43
|
-
it "delegates to the
|
44
|
-
expect(
|
41
|
+
it "delegates to the endpoints stub template" do
|
42
|
+
expect(endpoint_stub_template).to receive(:schema).with(type, definition)
|
45
43
|
|
46
44
|
subject
|
47
45
|
end
|
48
46
|
|
49
47
|
it "returns the created schema" do
|
50
48
|
schema = { schema: :some_schema }
|
51
|
-
expect(
|
49
|
+
expect(endpoint_stub_template).to receive(:schema).and_return(schema)
|
52
50
|
|
53
51
|
expect(subject).to eql(schema)
|
54
52
|
end
|
@@ -61,8 +59,8 @@ describe HttpStub::Configurer::DSL::ServerEndpointTemplate do
|
|
61
59
|
|
62
60
|
subject { server_endpoint_template.respond_with(response_settings) }
|
63
61
|
|
64
|
-
it "delegates to the
|
65
|
-
expect(
|
62
|
+
it "delegates to the endpoints stub template" do
|
63
|
+
expect(endpoint_stub_template).to receive(:respond_with).with(response_settings)
|
66
64
|
|
67
65
|
subject
|
68
66
|
end
|
@@ -75,8 +73,8 @@ describe HttpStub::Configurer::DSL::ServerEndpointTemplate do
|
|
75
73
|
|
76
74
|
subject { server_endpoint_template.trigger(trigger_settings) }
|
77
75
|
|
78
|
-
it "delegates to the
|
79
|
-
expect(
|
76
|
+
it "delegates to the endpoints stub template" do
|
77
|
+
expect(endpoint_stub_template).to receive(:trigger).with(trigger_settings)
|
80
78
|
|
81
79
|
subject
|
82
80
|
end
|
@@ -90,8 +88,8 @@ describe HttpStub::Configurer::DSL::ServerEndpointTemplate do
|
|
90
88
|
|
91
89
|
subject { server_endpoint_template.invoke(&block) }
|
92
90
|
|
93
|
-
it "delegates to the
|
94
|
-
expect(
|
91
|
+
it "delegates to the endpoints stub template" do
|
92
|
+
expect(endpoint_stub_template).to receive(:invoke).and_yield
|
95
93
|
expect(block_verifier).to receive(:verify)
|
96
94
|
|
97
95
|
subject
|
@@ -107,8 +105,8 @@ describe HttpStub::Configurer::DSL::ServerEndpointTemplate do
|
|
107
105
|
|
108
106
|
subject { server_endpoint_template.build_stub(response_overrides, &block) }
|
109
107
|
|
110
|
-
it "delegates to the
|
111
|
-
expect(
|
108
|
+
it "delegates to the endpoints stub template" do
|
109
|
+
expect(endpoint_stub_template).to receive(:build_stub).with(response_overrides).and_yield
|
112
110
|
expect(block_verifier).to receive(:verify)
|
113
111
|
|
114
112
|
subject
|
@@ -116,48 +114,61 @@ describe HttpStub::Configurer::DSL::ServerEndpointTemplate do
|
|
116
114
|
|
117
115
|
end
|
118
116
|
|
119
|
-
describe "#
|
117
|
+
describe "#add_scenario!" do
|
120
118
|
|
119
|
+
let(:name) { "Some scenario name" }
|
121
120
|
let(:response_overrides) { { status: 201 } }
|
122
121
|
let(:block_verifier) { double("BlockVerifier") }
|
123
122
|
let(:block) { lambda { block_verifier.verify } }
|
124
123
|
|
125
|
-
|
124
|
+
let(:built_stub) { instance_double(HttpStub::Configurator::Stub::Stub) }
|
125
|
+
|
126
|
+
subject { server_endpoint_template.add_scenario!(name, response_overrides, &block) }
|
127
|
+
|
128
|
+
before(:example) do
|
129
|
+
allow(endpoint_stub_template).to receive(:build_stub).and_return(built_stub)
|
130
|
+
allow(server).to receive(:add_scenario_with_one_stub!)
|
131
|
+
end
|
126
132
|
|
127
|
-
it "
|
128
|
-
expect(
|
133
|
+
it "builds a stub using any provided response overrides and block" do
|
134
|
+
expect(endpoint_stub_template).to receive(:build_stub).with(response_overrides).and_yield
|
129
135
|
expect(block_verifier).to receive(:verify)
|
130
136
|
|
131
137
|
subject
|
132
138
|
end
|
133
139
|
|
140
|
+
it "adds a one stub scenario to the server with the provided name and built stub" do
|
141
|
+
expect(server).to receive(:add_scenario_with_one_stub!).with(name, built_stub)
|
142
|
+
|
143
|
+
subject
|
144
|
+
end
|
145
|
+
|
134
146
|
end
|
135
147
|
|
136
|
-
describe "#
|
148
|
+
describe "#add_stub!" do
|
137
149
|
|
138
|
-
let(:name) { "Some scenario name" }
|
139
150
|
let(:response_overrides) { { status: 201 } }
|
140
151
|
let(:block_verifier) { double("BlockVerifier") }
|
141
152
|
let(:block) { lambda { block_verifier.verify } }
|
142
153
|
|
143
|
-
let(:
|
154
|
+
let(:built_stub) { instance_double(HttpStub::Configurator::Stub::Stub) }
|
144
155
|
|
145
|
-
subject { server_endpoint_template.
|
156
|
+
subject { server_endpoint_template.add_stub!(response_overrides, &block) }
|
146
157
|
|
147
158
|
before(:example) do
|
148
|
-
allow(
|
149
|
-
allow(server).to receive(:
|
159
|
+
allow(endpoint_stub_template).to receive(:build_stub).and_return(built_stub)
|
160
|
+
allow(server).to receive(:add_stub!)
|
150
161
|
end
|
151
162
|
|
152
163
|
it "builds a stub using any provided response overrides and block" do
|
153
|
-
expect(
|
164
|
+
expect(endpoint_stub_template).to receive(:build_stub).with(response_overrides).and_yield
|
154
165
|
expect(block_verifier).to receive(:verify)
|
155
166
|
|
156
167
|
subject
|
157
168
|
end
|
158
169
|
|
159
|
-
it "adds
|
160
|
-
expect(server).to receive(:
|
170
|
+
it "adds the built stub to the server" do
|
171
|
+
expect(server).to receive(:add_stub!).with(built_stub)
|
161
172
|
|
162
173
|
subject
|
163
174
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
describe HttpStub::Configurator::Part do
|
2
|
+
|
3
|
+
let(:configurator) do
|
4
|
+
Class.new.tap { |configurator| configurator.send(:include, HttpStub::Configurator) }
|
5
|
+
end
|
6
|
+
|
7
|
+
let(:part_class) do
|
8
|
+
Class.new.tap { |part_class| part_class.send(:include, HttpStub::Configurator::Part) }
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:part) { part_class.new }
|
12
|
+
|
13
|
+
describe "#apply_to" do
|
14
|
+
|
15
|
+
subject { part.apply_to(configurator) }
|
16
|
+
|
17
|
+
shared_context "expect configuration methods to be automatically invoked" do
|
18
|
+
|
19
|
+
before(:example) do
|
20
|
+
configuration_method_names.each do |method_name|
|
21
|
+
part_class.send(:define_method, method_name) do
|
22
|
+
# Intentionally blank
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "invokes the configuration methods" do
|
28
|
+
configuration_method_names.each { |method_name| expect(part).to receive(method_name) }
|
29
|
+
|
30
|
+
subject
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when the part has configured stubs methods" do
|
36
|
+
|
37
|
+
let(:configuration_method_names) { (1..3).map { |i| "configure_resource_#{i}_stubs".to_sym } }
|
38
|
+
|
39
|
+
include_context "expect configuration methods to be automatically invoked"
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when the part has configured stub methods" do
|
44
|
+
|
45
|
+
let(:configuration_method_names) { (1..3).map { |i| "configure_resource_#{i}_stub".to_sym } }
|
46
|
+
|
47
|
+
include_context "expect configuration methods to be automatically invoked"
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when the part has configured scenarios methods" do
|
52
|
+
|
53
|
+
let(:configuration_method_names) { (1..3).map { |i| "configure_resource_#{i}_scenarios".to_sym } }
|
54
|
+
|
55
|
+
include_context "expect configuration methods to be automatically invoked"
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when the part has configured scenario methods" do
|
60
|
+
|
61
|
+
let(:configuration_method_names) { (1..3).map { |i| "configure_resource_#{i}_scenario".to_sym } }
|
62
|
+
|
63
|
+
include_context "expect configuration methods to be automatically invoked"
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when applied to a configurator" do
|
70
|
+
|
71
|
+
before(:example) { part.apply_to(configurator) }
|
72
|
+
|
73
|
+
describe "other methods on the part" do
|
74
|
+
|
75
|
+
context "when available on the configurator" do
|
76
|
+
|
77
|
+
it "are available on the part" do
|
78
|
+
expect(part.respond_to?(:stub_server)).to be(true)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "are delegated to the configurator" do
|
82
|
+
expect(part.stub_server).to eql(configurator.stub_server)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when not available on the configurator" do
|
88
|
+
|
89
|
+
it "are not available on the part" do
|
90
|
+
expect(part.respond_to?(:not_in_configurator)).to be(false)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "raise an error on the part when invoked" do
|
94
|
+
expect { part.not_in_configurator }.to raise_error(/#{part_class}/)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|