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,98 +0,0 @@
|
|
1
|
-
describe HttpStub::Server::Stub::Response::Attribute::Body do
|
2
|
-
|
3
|
-
let(:body) { described_class.new(stub_body) }
|
4
|
-
|
5
|
-
describe "#with_values_from" do
|
6
|
-
|
7
|
-
let(:request) { HttpStub::Server::Request::Request }
|
8
|
-
|
9
|
-
subject { body.with_values_from(request) }
|
10
|
-
|
11
|
-
context "when a body is provided" do
|
12
|
-
|
13
|
-
let(:stub_body) { "some stub body" }
|
14
|
-
|
15
|
-
it "interpolates the stub body with values from the request" do
|
16
|
-
expect(HttpStub::Server::Stub::Response::Attribute::Interpolator).to(
|
17
|
-
receive(:interpolate).with(stub_body, request)
|
18
|
-
)
|
19
|
-
|
20
|
-
subject
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns the interpolation result" do
|
24
|
-
interpolated_body = "some interpolated body"
|
25
|
-
allow(HttpStub::Server::Stub::Response::Attribute::Interpolator).to(
|
26
|
-
receive(:interpolate).and_return(interpolated_body)
|
27
|
-
)
|
28
|
-
|
29
|
-
expect(subject).to eql(interpolated_body)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
context "when the body is nil" do
|
35
|
-
|
36
|
-
let(:stub_body) { nil }
|
37
|
-
|
38
|
-
it "returns nil" do
|
39
|
-
expect(subject).to eql(nil)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#provided?" do
|
47
|
-
|
48
|
-
subject { body.provided? }
|
49
|
-
|
50
|
-
context "when the provided body is not nil" do
|
51
|
-
|
52
|
-
let(:stub_body) { "" }
|
53
|
-
|
54
|
-
it "returns true" do
|
55
|
-
expect(subject).to eql(true)
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when the provided body is nil" do
|
61
|
-
|
62
|
-
let(:stub_body) { nil }
|
63
|
-
|
64
|
-
it "returns false" do
|
65
|
-
expect(subject).to eql(false)
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "#to_s" do
|
73
|
-
|
74
|
-
subject { body.to_s }
|
75
|
-
|
76
|
-
context "when a body is provided" do
|
77
|
-
|
78
|
-
let(:stub_body) { "some stub body" }
|
79
|
-
|
80
|
-
it "returns the stub body" do
|
81
|
-
expect(subject).to eql(stub_body)
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when the body is nil" do
|
87
|
-
|
88
|
-
let(:stub_body) { nil }
|
89
|
-
|
90
|
-
it "returns an empty string" do
|
91
|
-
expect(subject).to eql("")
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
describe HttpStub::Server::Stub::Response::Attribute::Headers do
|
2
|
-
|
3
|
-
let(:stub_headers) { (1..3).each_with_object({}) { |i, result| result["key#{i}"] = "value #{i}" } }
|
4
|
-
|
5
|
-
let(:headers) { described_class.new(stub_headers) }
|
6
|
-
|
7
|
-
describe "#with_values_from" do
|
8
|
-
|
9
|
-
let(:request) { HttpStub::Server::Request::Request }
|
10
|
-
|
11
|
-
let(:interpolated_headers) do
|
12
|
-
stub_headers.keys.each_with_object({}).with_index do |(name, result), i|
|
13
|
-
result[name] = "interpolated value #{i + 1}"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
subject { headers.with_values_from(request) }
|
18
|
-
|
19
|
-
it "interpolates each header value with values from the request" do
|
20
|
-
stub_headers.values.each do |header_value|
|
21
|
-
expect(HttpStub::Server::Stub::Response::Attribute::Interpolator).to(
|
22
|
-
receive(:interpolate).with(header_value, request)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
subject
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns a hash containing the interpolated values" do
|
30
|
-
stub_headers.values.zip(interpolated_headers.values).each do |header_value, interpolated_value|
|
31
|
-
allow(HttpStub::Server::Stub::Response::Attribute::Interpolator).to(
|
32
|
-
receive(:interpolate).with(header_value, anything).and_return(interpolated_value)
|
33
|
-
)
|
34
|
-
end
|
35
|
-
|
36
|
-
expect(subject).to eql(interpolated_headers)
|
37
|
-
end
|
38
|
-
|
39
|
-
context "when a header value is a number" do
|
40
|
-
|
41
|
-
let(:stub_headers) { (1..3).each_with_object({}) { |i, result| result["key#{i}"] = i } }
|
42
|
-
|
43
|
-
it "does not interpolate any values" do
|
44
|
-
expect(HttpStub::Server::Stub::Response::Attribute::Interpolator).to_not receive(:interpolate)
|
45
|
-
|
46
|
-
subject
|
47
|
-
end
|
48
|
-
|
49
|
-
it "returns a hash containing the values unchanged" do
|
50
|
-
expect(subject).to eql(stub_headers)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "#to_s" do
|
58
|
-
|
59
|
-
subject { headers.to_s }
|
60
|
-
|
61
|
-
it "returns a string with each header name and value separated by ':'" do
|
62
|
-
result = subject
|
63
|
-
|
64
|
-
stub_headers.each { |name, value| expect(result).to match(/#{name}:#{value}/) }
|
65
|
-
end
|
66
|
-
|
67
|
-
it "separates each header with comma for readability" do
|
68
|
-
expect(subject).to match(/key\d.value \d, key\d.value \d, key\d.value \d/)
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
describe HttpStub::Server::Stub::Response::Attribute::Interpolator::Headers do
|
2
|
-
|
3
|
-
describe "::interpolate" do
|
4
|
-
|
5
|
-
let(:request_headers) { instance_double(HttpStub::Server::Request::Headers) }
|
6
|
-
let(:request) { instance_double(HttpStub::Server::Request::Request, headers: request_headers) }
|
7
|
-
|
8
|
-
subject { described_class.interpolate(value, request) }
|
9
|
-
|
10
|
-
context "when the value has header references" do
|
11
|
-
|
12
|
-
let(:value) do
|
13
|
-
"control:request.headers[name1] some text control:request.parameters[name1] control:request.headers[name2]"
|
14
|
-
end
|
15
|
-
|
16
|
-
context "and the headers are present in the request" do
|
17
|
-
|
18
|
-
before(:example) do
|
19
|
-
allow(request_headers).to receive(:[]).with("name1").and_return("value1")
|
20
|
-
allow(request_headers).to receive(:[]).with("name2").and_return("value2")
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns the value with the header references interpolated" do
|
24
|
-
expect(subject).to eql("value1 some text control:request.parameters[name1] value2")
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context "and the headers are not present in the request" do
|
30
|
-
|
31
|
-
before(:example) { allow(request_headers).to receive(:[]).and_return(nil) }
|
32
|
-
|
33
|
-
it "returns the value with the header references removed" do
|
34
|
-
expect(subject).to eql(" some text control:request.parameters[name1] ")
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when the value does not have header references" do
|
42
|
-
|
43
|
-
let(:value) { "some value without header references control:request.parameters[name1]" }
|
44
|
-
|
45
|
-
it "returns the value unchanged" do
|
46
|
-
expect(subject).to eql(value)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
describe HttpStub::Server::Stub::Response::Attribute::Interpolator::Parameters do
|
2
|
-
|
3
|
-
describe "::interpolate" do
|
4
|
-
|
5
|
-
let(:request_parameters) { instance_double(HttpStub::Server::Request::Parameters) }
|
6
|
-
let(:request) { instance_double(HttpStub::Server::Request::Request, parameters: request_parameters) }
|
7
|
-
|
8
|
-
subject { described_class.interpolate(value, request) }
|
9
|
-
|
10
|
-
context "when the value has parameter references" do
|
11
|
-
|
12
|
-
let(:value) do
|
13
|
-
"control:request.parameters[name1] some text control:request.headers[name1] control:request.parameters[name2]"
|
14
|
-
end
|
15
|
-
|
16
|
-
context "and the parameters are present in the request" do
|
17
|
-
|
18
|
-
before(:example) do
|
19
|
-
allow(request_parameters).to receive(:[]).with("name1").and_return("value1")
|
20
|
-
allow(request_parameters).to receive(:[]).with("name2").and_return("value2")
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns the value with the parameter references interpolated" do
|
24
|
-
expect(subject).to eql("value1 some text control:request.headers[name1] value2")
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
context "and the parameters are not present in the request" do
|
30
|
-
|
31
|
-
before(:example) { allow(request_parameters).to receive(:[]).and_return(nil) }
|
32
|
-
|
33
|
-
it "returns the value with the parameter references removed" do
|
34
|
-
expect(subject).to eql(" some text control:request.headers[name1] ")
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when the value does not have parameter references" do
|
42
|
-
|
43
|
-
let(:value) { "some value without parameter references control:request.headers[name1]" }
|
44
|
-
|
45
|
-
it "returns the value unchanged" do
|
46
|
-
expect(subject).to eql(value)
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
describe HttpStub::Server::Stub::Response::Attribute::Interpolator do
|
2
|
-
|
3
|
-
describe "::interpolate" do
|
4
|
-
|
5
|
-
let(:value) { "some value" }
|
6
|
-
let(:request) { instance_double(HttpStub::Server::Request::Request) }
|
7
|
-
|
8
|
-
subject { described_class.interpolate(value, request) }
|
9
|
-
|
10
|
-
it "interpolates header references in the provided value" do
|
11
|
-
expect(HttpStub::Server::Stub::Response::Attribute::Interpolator::Headers).to(
|
12
|
-
receive(:interpolate).with(value, request).and_return("")
|
13
|
-
)
|
14
|
-
|
15
|
-
subject
|
16
|
-
end
|
17
|
-
|
18
|
-
it "combines the result of header interpolation to include parameter interpolation" do
|
19
|
-
value_with_header_interpolation = "some value with header interpolation"
|
20
|
-
allow(HttpStub::Server::Stub::Response::Attribute::Interpolator::Headers).to(
|
21
|
-
receive(:interpolate).and_return(value_with_header_interpolation)
|
22
|
-
)
|
23
|
-
expect(HttpStub::Server::Stub::Response::Attribute::Interpolator::Parameters).to(
|
24
|
-
receive(:interpolate).with(value_with_header_interpolation, request)
|
25
|
-
)
|
26
|
-
|
27
|
-
subject
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns the result of parameter interpolation as the overall result" do
|
31
|
-
overall_result = "overall_result"
|
32
|
-
allow(HttpStub::Server::Stub::Response::Attribute::Interpolator::Parameters).to(
|
33
|
-
receive(:interpolate).and_return(overall_result)
|
34
|
-
)
|
35
|
-
|
36
|
-
expect(subject).to eql(overall_result)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
@@ -1,217 +0,0 @@
|
|
1
|
-
describe HttpStub::Server::Stub::Response::Base do
|
2
|
-
|
3
|
-
let(:status) { 202 }
|
4
|
-
let(:headers) { nil }
|
5
|
-
let(:delay_in_seconds) { 18 }
|
6
|
-
let(:args) { { "status" => status, "headers" => headers, "delay_in_seconds" => delay_in_seconds } }
|
7
|
-
|
8
|
-
let(:testable_response_class) { Class.new(described_class) }
|
9
|
-
|
10
|
-
let(:response) { testable_response_class.new(args) }
|
11
|
-
|
12
|
-
describe "#status" do
|
13
|
-
|
14
|
-
context "when a value is provided in the arguments" do
|
15
|
-
|
16
|
-
context "that is an integer" do
|
17
|
-
|
18
|
-
it "returns the value provided" do
|
19
|
-
expect(response.status).to eql(status)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
context "that is an empty string" do
|
25
|
-
|
26
|
-
let(:status) { "" }
|
27
|
-
|
28
|
-
it "defaults to 200" do
|
29
|
-
expect(response.status).to eql(200)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when the status is not provided in the arguments" do
|
37
|
-
|
38
|
-
let(:args) { { "headers" => headers } }
|
39
|
-
|
40
|
-
it "defaults to 200" do
|
41
|
-
expect(response.status).to eql(200)
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#delay_in_seconds" do
|
49
|
-
|
50
|
-
context "when a value is provided in the arguments" do
|
51
|
-
|
52
|
-
context "that is an integer" do
|
53
|
-
|
54
|
-
it "returns the value" do
|
55
|
-
expect(response.delay_in_seconds).to eql(delay_in_seconds)
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
context "that is an empty string" do
|
61
|
-
|
62
|
-
let(:delay_in_seconds) { "" }
|
63
|
-
|
64
|
-
it "defaults to 0" do
|
65
|
-
expect(response.delay_in_seconds).to eql(0)
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
context "when a value is not provided in the arguments" do
|
73
|
-
|
74
|
-
let(:args) { { "status" => status } }
|
75
|
-
|
76
|
-
it "defaults to 0" do
|
77
|
-
expect(response.delay_in_seconds).to eql(0)
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "#headers" do
|
85
|
-
|
86
|
-
let(:response_header_hash) { response.headers.to_hash }
|
87
|
-
|
88
|
-
it "is interpolateable headers" do
|
89
|
-
expect(response.headers).to be_a(HttpStub::Server::Stub::Response::Attribute::Headers)
|
90
|
-
end
|
91
|
-
|
92
|
-
context "when default headers have been added" do
|
93
|
-
|
94
|
-
let(:default_headers) do
|
95
|
-
{ "a_default_header" => "a default value", "another_default_header" => "some other default value" }
|
96
|
-
end
|
97
|
-
|
98
|
-
before(:example) { testable_response_class.add_default_headers(default_headers) }
|
99
|
-
|
100
|
-
context "and headers are provided" do
|
101
|
-
|
102
|
-
context "that have some names matching the defaults" do
|
103
|
-
|
104
|
-
let(:headers) { { "a_default_header" => "an overridde value" } }
|
105
|
-
|
106
|
-
it "replaces the matching default values with those provided" do
|
107
|
-
expect(response_header_hash["a_default_header"]).to eql("an overridde value")
|
108
|
-
end
|
109
|
-
|
110
|
-
it "preserves the default values that do not match" do
|
111
|
-
expect(response_header_hash["another_default_header"]).to eql("some other default value")
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
context "that do not have names matching the defaults" do
|
117
|
-
|
118
|
-
let(:headers) do
|
119
|
-
{
|
120
|
-
"a_header" => "some header",
|
121
|
-
"another_header" => "another value",
|
122
|
-
"yet_another_header" => "yet another value"
|
123
|
-
}
|
124
|
-
end
|
125
|
-
|
126
|
-
it "returns the defaults headers combined with the provided headers" do
|
127
|
-
expect(response_header_hash).to eql(default_headers.merge(headers))
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
context "and no headers are provided" do
|
135
|
-
|
136
|
-
it "returns the default headers" do
|
137
|
-
expect(response_header_hash).to eql(default_headers)
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
context "when no default headers have been added" do
|
145
|
-
|
146
|
-
context "and headers are provided" do
|
147
|
-
|
148
|
-
let(:headers) do
|
149
|
-
{
|
150
|
-
"a_header" => "some header",
|
151
|
-
"another_header" => "another value",
|
152
|
-
"yet_another_header" => "yet another value"
|
153
|
-
}
|
154
|
-
end
|
155
|
-
|
156
|
-
it "returns the headers" do
|
157
|
-
expect(response_header_hash).to eql(headers)
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
context "and no headers are provided" do
|
163
|
-
|
164
|
-
let(:headers) { nil }
|
165
|
-
|
166
|
-
it "returns an empty hash" do
|
167
|
-
expect(response_header_hash).to eql({})
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "#type" do
|
177
|
-
|
178
|
-
class HttpStub::Server::Stub::Response::TestableBaseClass < HttpStub::Server::Stub::Response::Base
|
179
|
-
end
|
180
|
-
|
181
|
-
let(:testable_response_class) { HttpStub::Server::Stub::Response::TestableBaseClass }
|
182
|
-
|
183
|
-
it "returns the name of the concrete base instance underscored" do
|
184
|
-
expect(response.type).to eql("testable_base_class")
|
185
|
-
end
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
describe "#to_hash" do
|
190
|
-
|
191
|
-
subject { response.to_hash }
|
192
|
-
|
193
|
-
it "contains the responses status" do
|
194
|
-
expect(subject).to include(status: response.status)
|
195
|
-
end
|
196
|
-
|
197
|
-
it "contains the responses headers" do
|
198
|
-
expect(subject).to include(headers: response.headers)
|
199
|
-
end
|
200
|
-
|
201
|
-
it "contains the responses delay in seconds" do
|
202
|
-
expect(subject).to include(delay_in_seconds: response.delay_in_seconds)
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
describe "#to_json" do
|
208
|
-
|
209
|
-
subject { response.to_json }
|
210
|
-
|
211
|
-
it "is the JSON representation of the responses hash" do
|
212
|
-
expect(subject).to eql(response.to_hash.to_json)
|
213
|
-
end
|
214
|
-
|
215
|
-
end
|
216
|
-
|
217
|
-
end
|