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
@@ -2,46 +2,37 @@ describe HttpStub::Server::Stub::Response do
|
|
2
2
|
|
3
3
|
describe "::create" do
|
4
4
|
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
it "creates a text response" do
|
14
|
-
expect(HttpStub::Server::Stub::Response::Text).to receive(:new).with(response_args)
|
15
|
-
|
16
|
-
subject
|
17
|
-
end
|
18
|
-
|
19
|
-
it "returns the created response" do
|
20
|
-
response = instance_double(HttpStub::Server::Stub::Response::Text)
|
21
|
-
allow(HttpStub::Server::Stub::Response::Text).to receive(:new).and_return(response)
|
22
|
-
|
23
|
-
expect(subject).to eql(response)
|
24
|
-
end
|
25
|
-
|
5
|
+
let(:status) { 201 }
|
6
|
+
let(:headers) { HttpStub::HeadersFixture.many }
|
7
|
+
let(:body) { "some text" }
|
8
|
+
let(:delay_in_seconds) { 8 }
|
9
|
+
let(:blocks) { HttpStub::Server::Stub::Response::BlocksFixture.many }
|
10
|
+
let(:args) do
|
11
|
+
{ status: 201, headers: headers, body: body, delay_in_seconds: delay_in_seconds, blocks: blocks }
|
26
12
|
end
|
27
13
|
|
28
|
-
|
14
|
+
let(:primitive_response) { JSON.parse(subject.to_json).symbolize_keys }
|
29
15
|
|
30
|
-
|
16
|
+
subject { HttpStub::Server::Stub::Response.create(args) }
|
31
17
|
|
32
|
-
|
33
|
-
|
18
|
+
it "creates a response with the provided status" do
|
19
|
+
expect(primitive_response).to include(status: status)
|
20
|
+
end
|
34
21
|
|
35
|
-
|
36
|
-
|
22
|
+
it "creates a response with the provided headers" do
|
23
|
+
expect(primitive_response).to include(headers: headers)
|
24
|
+
end
|
37
25
|
|
38
|
-
|
39
|
-
|
40
|
-
|
26
|
+
it "creates a response with the provided body" do
|
27
|
+
expect(primitive_response).to include(body: body)
|
28
|
+
end
|
41
29
|
|
42
|
-
|
43
|
-
|
30
|
+
it "creates a response with the provided delay in seconds" do
|
31
|
+
expect(primitive_response).to include(delay_in_seconds: delay_in_seconds)
|
32
|
+
end
|
44
33
|
|
34
|
+
it "creates a response with the provided blocks" do
|
35
|
+
expect(primitive_response[:blocks]).to eql(blocks.map(&:source))
|
45
36
|
end
|
46
37
|
|
47
38
|
end
|
@@ -1,41 +1,37 @@
|
|
1
1
|
describe HttpStub::Server::Stub::Stub do
|
2
2
|
|
3
|
-
let(:base_uri) { "http://base.uri:8888" }
|
4
3
|
let(:stub_id) { SecureRandom.uuid }
|
5
4
|
let(:trigger_payload) do
|
6
5
|
{
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
"
|
15
|
-
"body" => "Triggered body"
|
6
|
+
uri: "/a_triggered_path",
|
7
|
+
method: "post",
|
8
|
+
headers: { trigger_header: "triggered_header_value" },
|
9
|
+
parameters: { trigger_parameter: "triggered_parameter_value" },
|
10
|
+
body: { schema: { type: "json", definition: "trigger schema definition" } },
|
11
|
+
response: {
|
12
|
+
status: 203,
|
13
|
+
body: "triggered body"
|
16
14
|
}
|
17
15
|
}
|
18
16
|
end
|
19
|
-
let(:stub_payload)
|
17
|
+
let(:stub_payload) do
|
20
18
|
{
|
21
|
-
|
22
|
-
"
|
23
|
-
|
24
|
-
"
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
"
|
30
|
-
"body" => "Some body"
|
19
|
+
id: stub_id,
|
20
|
+
uri: "/a_path",
|
21
|
+
method: :get,
|
22
|
+
headers: { header: "header value" },
|
23
|
+
parameters: { parameter: "parameter value" },
|
24
|
+
body: { schema: { type: :json, definition: "stub schema definition" } },
|
25
|
+
response: {
|
26
|
+
status: 201,
|
27
|
+
body: "some body"
|
31
28
|
},
|
32
|
-
|
29
|
+
triggers: [ trigger_payload ]
|
33
30
|
}
|
34
31
|
end
|
35
|
-
let(:match_rules)
|
36
|
-
let(:
|
37
|
-
let(:
|
38
|
-
let(:triggers) { instance_double(HttpStub::Server::Stub::Triggers) }
|
32
|
+
let(:match_rules) { instance_double(HttpStub::Server::Stub::Match::Rules, matches?: true) }
|
33
|
+
let(:response) { HttpStub::Server::Stub::ResponseFixture.create }
|
34
|
+
let(:triggers) { instance_double(HttpStub::Server::Stub::Triggers) }
|
39
35
|
|
40
36
|
let(:the_stub) { HttpStub::Server::Stub::Stub.new(stub_payload) }
|
41
37
|
|
@@ -121,7 +117,7 @@ describe HttpStub::Server::Stub::Stub do
|
|
121
117
|
end
|
122
118
|
|
123
119
|
it "returns the response with replaced values" do
|
124
|
-
response_with_replaced_values =
|
120
|
+
response_with_replaced_values = HttpStub::Server::Stub::ResponseFixture.create
|
125
121
|
allow(response).to receive(:with_values_from).and_return(response_with_replaced_values)
|
126
122
|
|
127
123
|
expect(subject).to eql(response_with_replaced_values)
|
@@ -129,24 +125,22 @@ describe HttpStub::Server::Stub::Stub do
|
|
129
125
|
|
130
126
|
end
|
131
127
|
|
132
|
-
describe "#
|
133
|
-
|
134
|
-
subject { the_stub.uri }
|
128
|
+
describe "#stub_id" do
|
135
129
|
|
136
|
-
|
137
|
-
|
138
|
-
it "returns a absolute uri on the server that includes the id" do
|
139
|
-
expect(subject).to eql("#{base_uri}/http_stub/stubs/#{stub_id}")
|
140
|
-
end
|
130
|
+
subject { the_stub.stub_id }
|
141
131
|
|
132
|
+
it "returns the provided id" do
|
133
|
+
expect(subject).to eql(stub_id)
|
142
134
|
end
|
143
135
|
|
144
|
-
|
136
|
+
end
|
145
137
|
|
146
|
-
|
147
|
-
|
148
|
-
|
138
|
+
describe "#uri" do
|
139
|
+
|
140
|
+
subject { the_stub.uri }
|
149
141
|
|
142
|
+
it "returns a relative uri to the stub that includes the id" do
|
143
|
+
expect(subject).to eql("/http_stub/stubs/#{stub_id}")
|
150
144
|
end
|
151
145
|
|
152
146
|
end
|
@@ -2,7 +2,7 @@ describe HttpStub::Server::Stub::Triggers do
|
|
2
2
|
|
3
3
|
let(:scenario_names) { (1..3).map { |i| "Scenario trigger #{i}" } }
|
4
4
|
let(:stub_payloads) { (1..3).map { |i| "Stub trigger payload #{i}" } }
|
5
|
-
let(:args) { {
|
5
|
+
let(:args) { { scenario_names: scenario_names, stubs: stub_payloads } }
|
6
6
|
|
7
7
|
let(:stubs) { (1..stub_payloads.length).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
8
8
|
|
@@ -30,10 +30,24 @@ describe HttpStub::Server::Stub::Triggers do
|
|
30
30
|
|
31
31
|
context "when scenario names are provided" do
|
32
32
|
|
33
|
-
|
33
|
+
context "as a symbolised arg" do
|
34
|
+
|
35
|
+
let(:args) { { scenario_names: scenario_names } }
|
36
|
+
|
37
|
+
it "establishes the scenario names" do
|
38
|
+
expect(subject.scenario_names).to eql(scenario_names)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
context "as a string arg" do
|
44
|
+
|
45
|
+
let(:args) { { "scenario_names" => scenario_names } }
|
46
|
+
|
47
|
+
it "establishes the scenario names" do
|
48
|
+
expect(subject.scenario_names).to eql(scenario_names)
|
49
|
+
end
|
34
50
|
|
35
|
-
it "establishes the scenario names" do
|
36
|
-
expect(subject.scenario_names).to eql(scenario_names)
|
37
51
|
end
|
38
52
|
|
39
53
|
end
|
@@ -50,18 +64,39 @@ describe HttpStub::Server::Stub::Triggers do
|
|
50
64
|
|
51
65
|
context "when stubs are provided" do
|
52
66
|
|
53
|
-
|
67
|
+
context "as a symbolised arg" do
|
68
|
+
|
69
|
+
let(:args) { { stubs: stub_payloads } }
|
54
70
|
|
55
|
-
|
56
|
-
|
71
|
+
it "creates a stub for each provided stub payload" do
|
72
|
+
stub_payloads.each { |payload| expect(HttpStub::Server::Stub).to receive(:create).with(payload) }
|
73
|
+
|
74
|
+
subject
|
75
|
+
end
|
76
|
+
|
77
|
+
it "estalishes the created stubs" do
|
78
|
+
expect(subject.stubs).to eql(stubs)
|
79
|
+
end
|
57
80
|
|
58
|
-
subject
|
59
81
|
end
|
60
82
|
|
61
|
-
|
62
|
-
|
83
|
+
context "as a string arg" do
|
84
|
+
|
85
|
+
let(:args) { { "stubs" => stub_payloads } }
|
86
|
+
|
87
|
+
it "creates a stub for each provided stub payload" do
|
88
|
+
stub_payloads.each { |payload| expect(HttpStub::Server::Stub).to receive(:create).with(payload) }
|
89
|
+
|
90
|
+
subject
|
91
|
+
end
|
92
|
+
|
93
|
+
it "estalishes the created stubs" do
|
94
|
+
expect(subject.stubs).to eql(stubs)
|
95
|
+
end
|
96
|
+
|
63
97
|
end
|
64
98
|
|
99
|
+
|
65
100
|
end
|
66
101
|
|
67
102
|
context "when stubs are not provided" do
|
@@ -117,10 +152,10 @@ describe HttpStub::Server::Stub::Triggers do
|
|
117
152
|
|
118
153
|
context "when scenario names and stubs are provided" do
|
119
154
|
|
120
|
-
let(:args) { {
|
155
|
+
let(:args) { { scenario_names: scenario_names, stubs: stubs } }
|
121
156
|
|
122
157
|
it "returns a string representation of the arguments provided to the triggers" do
|
123
|
-
expect(subject).to eql(
|
158
|
+
expect(subject).to eql({ "scenario_names" => scenario_names, "stubs" => stubs }.to_s)
|
124
159
|
end
|
125
160
|
|
126
161
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module HttpStub
|
2
|
+
module Extensions
|
3
|
+
|
4
|
+
module Random
|
5
|
+
|
6
|
+
def self.included(mod)
|
7
|
+
mod.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def string
|
13
|
+
"string #{rand(100_000)}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
::Random.send(:include, HttpStub::Extensions::Random)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module HttpStub
|
2
|
+
module Configurator
|
3
|
+
|
4
|
+
class ScenarioBuilder
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@name = "Some Scenario Name"
|
8
|
+
@stub_builders = []
|
9
|
+
@triggered_scenario_names = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def with_name!(name)
|
13
|
+
self.tap { @name = name }
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_stubs!(number)
|
17
|
+
self.tap { @stub_builders.concat((1..number).map { HttpStub::Configurator::StubBuilder.new }) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def with_triggered_scenario_names!(names)
|
21
|
+
self.tap { @triggered_scenario_names.concat(names) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_hash
|
25
|
+
{
|
26
|
+
name: @name,
|
27
|
+
stubs: @stub_builders.map(&:build_hash),
|
28
|
+
triggered_scenario_names: @triggered_scenario_names
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module HttpStub
|
2
|
+
module Configurator
|
3
|
+
|
4
|
+
class ScenarioFixture
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def create_hash(args={})
|
9
|
+
hash = { activated: false, stubs: [], triggered_scenario_names: [] }.merge(args)
|
10
|
+
hash[:name] ||= next_name
|
11
|
+
hash
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(args={})
|
15
|
+
hash = self.create_hash(args)
|
16
|
+
HttpStub::Configurator::Scenario.new(hash[:name], nil).tap do |scenario|
|
17
|
+
scenario.add_stubs!(hash[:stubs])
|
18
|
+
scenario.activate_scenarios!(hash[:triggered_scenario_names])
|
19
|
+
scenario.activate! if hash[:activated]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def many
|
24
|
+
(1..3).map { self.create }
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def next_name
|
30
|
+
@next_id ||= 0
|
31
|
+
"scenario #{@next_id += 1}"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module HttpStub
|
2
|
+
module Configurator
|
3
|
+
|
4
|
+
class StubBuilder
|
5
|
+
|
6
|
+
attr_reader :match_rules, :response, :triggers
|
7
|
+
|
8
|
+
class Part
|
9
|
+
|
10
|
+
attr_writer :hash
|
11
|
+
|
12
|
+
def initialize(hash)
|
13
|
+
@hash = hash.with_indifferent_access
|
14
|
+
end
|
15
|
+
|
16
|
+
def merge!(options)
|
17
|
+
@hash.merge!(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def http_method
|
21
|
+
@hash[:method]
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_hash
|
25
|
+
@hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(name, *args)
|
29
|
+
if name.to_s.end_with?("=")
|
30
|
+
attribute_name = name.to_s[0..-2].to_sym
|
31
|
+
@hash[attribute_name] = args.first
|
32
|
+
else
|
33
|
+
@hash[name]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
@unique_value = SecureRandom.uuid
|
41
|
+
@match_rules = HttpStub::Configurator::StubBuilder::Part.new(
|
42
|
+
uri: "/stub/uri/#{@unique_value}",
|
43
|
+
method: "some #{@unique_value} method",
|
44
|
+
headers: { "request_header_name" => "request header value #{@unique_value}" },
|
45
|
+
parameters: { "parameter_name" => "parameter value #{@unique_value}" },
|
46
|
+
body: "some body"
|
47
|
+
)
|
48
|
+
@response = HttpStub::Configurator::StubBuilder::Part.new(
|
49
|
+
status: 500,
|
50
|
+
headers: { "response_header_name" => "response header value #{@unique_value}" },
|
51
|
+
body: "body #{@unique_value}",
|
52
|
+
delay_in_seconds: 8,
|
53
|
+
blocks: []
|
54
|
+
)
|
55
|
+
@triggers = {
|
56
|
+
scenarios: [],
|
57
|
+
stubs: []
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def match_rules=(options)
|
62
|
+
self.tap { @match_rules.hash = options }
|
63
|
+
end
|
64
|
+
|
65
|
+
def response=(options)
|
66
|
+
self.tap { @response.hash = options }
|
67
|
+
end
|
68
|
+
|
69
|
+
def with_response!(options)
|
70
|
+
self.tap { @response.merge!(options) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def with_response_block!
|
74
|
+
block = lambda do |request|
|
75
|
+
{ headers: { header_name: "header value #{request.headers[:some_header]}" } }
|
76
|
+
end
|
77
|
+
with_response!(blocks: [ block ])
|
78
|
+
end
|
79
|
+
|
80
|
+
def with_text_response!
|
81
|
+
with_response!(body: "payload #{@unique_value} text response")
|
82
|
+
end
|
83
|
+
|
84
|
+
def with_file_response!
|
85
|
+
with_response!(body: { file: { path: "payload/#{@unique_value}/file.path",
|
86
|
+
name: "payload_#{@unique_value}_file.name" } })
|
87
|
+
end
|
88
|
+
|
89
|
+
def with_triggered_scenarios!(scenario_names=[ "scenario name", "another scenario name" ])
|
90
|
+
self.tap { @triggers[:scenarios].concat(scenario_names) }
|
91
|
+
end
|
92
|
+
|
93
|
+
def with_triggered_stubs!(stubs=[ HttpStub::Configurator::Stub.create, HttpStub::Configurator::Stub.create ])
|
94
|
+
self.tap { @triggers[:stubs].concat(stubs) }
|
95
|
+
end
|
96
|
+
|
97
|
+
def build_hash
|
98
|
+
build.to_hash
|
99
|
+
end
|
100
|
+
|
101
|
+
def build
|
102
|
+
HttpStub::Configurator::Stub.create do |stub|
|
103
|
+
stub.match_requests(@match_rules.to_hash)
|
104
|
+
stub.respond_with(@response.to_hash)
|
105
|
+
stub.trigger(@triggers)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|