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,37 +1,17 @@
|
|
1
1
|
describe "Stub trigger acceptance" do
|
2
|
-
include_context "
|
2
|
+
include_context "server integration"
|
3
3
|
|
4
|
-
let(:
|
4
|
+
let(:configurator) { HttpStub::Examples::ConfiguratorWithStubTriggers }
|
5
5
|
|
6
|
-
context "when a stub
|
6
|
+
context "when a stub has triggers" do
|
7
7
|
|
8
8
|
context "that trigger scenarios" do
|
9
9
|
|
10
|
-
let(:triggered_scenario_names) do
|
11
|
-
(1..3).map do |scenario_number|
|
12
|
-
"Triggered Scenario #{scenario_number}".tap do |scenario_name|
|
13
|
-
stub_server.add_scenario_with_one_stub!(scenario_name) do |stub|
|
14
|
-
stub.match_requests(uri: "/triggered_scenario_#{scenario_number}", method: :get)
|
15
|
-
stub.respond_with(status: 200 + scenario_number, body: "Triggered scenario body #{scenario_number}")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
before(:example) do
|
22
|
-
stub_server.add_stub! do |stub|
|
23
|
-
stub.match_requests(uri: "/triggers_scenarios", method: :get)
|
24
|
-
stub.respond_with(body: "Stub triggering scenarios body")
|
25
|
-
stub.trigger(scenarios: triggered_scenario_names)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
10
|
context "and a request is made matching the stub" do
|
30
11
|
|
31
12
|
before(:example) { @stub_with_triggers_response = HTTParty.get("#{server_uri}/triggers_scenarios") }
|
32
13
|
|
33
14
|
it "replays the stubbed response" do
|
34
|
-
expect(@stub_with_triggers_response.code).to eql(200)
|
35
15
|
expect(@stub_with_triggers_response.body).to eql("Stub triggering scenarios body")
|
36
16
|
end
|
37
17
|
|
@@ -55,30 +35,12 @@ describe "Stub trigger acceptance" do
|
|
55
35
|
end
|
56
36
|
|
57
37
|
context "that trigger stubs" do
|
58
|
-
|
59
|
-
let(:triggered_stubs) do
|
60
|
-
(1..3).map do |trigger_number|
|
61
|
-
stub_server.build_stub do |stub|
|
62
|
-
stub.match_requests(uri: "/triggered_stub_#{trigger_number}", method: :get)
|
63
|
-
stub.respond_with(status: 200 + trigger_number, body: "Triggered stub body #{trigger_number}")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
before(:example) do
|
69
|
-
stub_server.add_stub! do |stub|
|
70
|
-
stub.match_requests(uri: "/triggers_stubs", method: :get)
|
71
|
-
stub.respond_with(body: "Stub triggering stubs body")
|
72
|
-
stub.trigger(stubs: triggered_stubs)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
38
|
+
|
76
39
|
context "and a request is made matching the stub" do
|
77
40
|
|
78
41
|
before(:example) { @stub_with_triggers_response = HTTParty.get("#{server_uri}/triggers_stubs") }
|
79
42
|
|
80
43
|
it "replays the stubbed response" do
|
81
|
-
expect(@stub_with_triggers_response.code).to eql(200)
|
82
44
|
expect(@stub_with_triggers_response.body).to eql("Stub triggering stubs body")
|
83
45
|
end
|
84
46
|
|
@@ -101,80 +63,41 @@ describe "Stub trigger acceptance" do
|
|
101
63
|
|
102
64
|
end
|
103
65
|
|
104
|
-
context "that
|
105
|
-
|
106
|
-
let(:pdf_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/sample.pdf" }
|
107
|
-
let(:pdf_file_trigger) do
|
108
|
-
stub_server.build_stub do |stub|
|
109
|
-
stub.match_requests(uri: "/triggered_stub_pdf_file", method: :get)
|
110
|
-
stub.respond_with(
|
111
|
-
headers: { "content-type" => "application/pdf" },
|
112
|
-
body: { file: { path: pdf_file_path, name: ::File.basename(pdf_file_path) } }
|
113
|
-
)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
let(:text_body) { "Sample trigger stub body" }
|
118
|
-
let(:text_trigger) do
|
119
|
-
stub_server.build_stub do |stub|
|
120
|
-
stub.match_requests(uri: "/triggered_stub_text", method: :get)
|
121
|
-
stub.respond_with(status: 201, body: "Sample trigger stub body")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
let(:txt_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/sample.txt" }
|
126
|
-
let(:txt_file_trigger) do
|
127
|
-
stub_server.build_stub do |stub|
|
128
|
-
stub.match_requests(uri: "/triggered_stub_txt_file", method: :get)
|
129
|
-
stub.respond_with(
|
130
|
-
headers: { "content-type" => "text/plain" },
|
131
|
-
body: { file: { path: txt_file_path, name: ::File.basename(txt_file_path) } }
|
132
|
-
)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
let(:triggered_stubs) { [ pdf_file_trigger, text_trigger, txt_file_trigger ] }
|
137
|
-
|
138
|
-
before(:example) do
|
139
|
-
stub_server.add_stub! do |stub|
|
140
|
-
stub.match_requests(uri: "/stub_with_triggers", method: :get)
|
141
|
-
stub.respond_with(body: "Trigger stub body")
|
142
|
-
stub.trigger(stubs: triggered_stubs)
|
143
|
-
end
|
144
|
-
end
|
66
|
+
context "that contains a mix of text and file responses" do
|
145
67
|
|
146
68
|
context "and a request is made matching the stub" do
|
147
69
|
|
148
|
-
before(:example) { HTTParty.get("#{server_uri}/
|
70
|
+
before(:example) { HTTParty.get("#{server_uri}/stub_with_mixed_response_triggers") }
|
149
71
|
|
150
72
|
context "and then a request matching a triggered stub returning a PDF file is made" do
|
151
73
|
|
74
|
+
let(:pdf_file_path) { HttpStub::Examples::ConfiguratorWithStubTriggers::PDF_FILE_PATH }
|
75
|
+
|
152
76
|
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_pdf_file") }
|
153
77
|
|
154
78
|
it "replays the triggered response" do
|
155
|
-
expect(response.code).to eql(200)
|
156
79
|
expect(response).to contain_file(pdf_file_path)
|
157
80
|
end
|
158
81
|
|
159
82
|
end
|
160
83
|
|
161
|
-
context "and then a request matching a triggered stub returning
|
84
|
+
context "and then a request matching a triggered stub returning text is made" do
|
162
85
|
|
163
86
|
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_text") }
|
164
87
|
|
165
88
|
it "replays the triggered response" do
|
166
|
-
expect(response.
|
167
|
-
expect(response.body).to eql(text_body)
|
89
|
+
expect(response.body).to eql("Sample trigger stub body")
|
168
90
|
end
|
169
91
|
|
170
92
|
end
|
171
93
|
|
172
94
|
context "and then a request matching a triggered stub returning a text file is made" do
|
173
95
|
|
96
|
+
let(:txt_file_path) { HttpStub::Examples::ConfiguratorWithStubTriggers::TXT_FILE_PATH }
|
97
|
+
|
174
98
|
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_txt_file") }
|
175
99
|
|
176
100
|
it "replays the triggered response" do
|
177
|
-
expect(response.code).to eql(200)
|
178
101
|
expect(response.parsed_response).to eql(::File.read(txt_file_path))
|
179
102
|
end
|
180
103
|
|
data/spec/helper.rb
CHANGED
@@ -2,18 +2,24 @@ require 'bundler'
|
|
2
2
|
Bundler.require(:development)
|
3
3
|
|
4
4
|
SimpleCov.start do
|
5
|
+
coverage_dir "tmp/coverage"
|
6
|
+
|
5
7
|
add_filter "/spec/"
|
6
8
|
add_filter "/vendor/"
|
7
9
|
|
10
|
+
add_filter "/examples/configurator_with_response_blocks"
|
11
|
+
|
8
12
|
minimum_coverage 100
|
9
13
|
refuse_coverage_drop
|
10
14
|
end if ENV["coverage"]
|
11
15
|
|
12
16
|
require 'http_server_manager/test_support'
|
13
17
|
|
18
|
+
require_relative '../lib/http_stub/configurator'
|
19
|
+
require_relative '../lib/http_stub/client'
|
14
20
|
require_relative '../lib/http_stub/rake/task_generators'
|
15
|
-
require_relative '../lib/http_stub'
|
16
21
|
|
22
|
+
require_relative '../examples/stub_builder'
|
17
23
|
Dir[File.expand_path('../../examples/**/*.rb', __FILE__)].each { |file| require file }
|
18
24
|
|
19
25
|
HttpStub::Server::Daemon.log_dir = ::File.expand_path('../../tmp/log', __FILE__)
|
@@ -23,8 +29,8 @@ HttpServerManager.logger = HttpServerManager::Test::SilentLogger
|
|
23
29
|
|
24
30
|
module HttpStub
|
25
31
|
|
26
|
-
module
|
27
|
-
RESOURCES_DIR = ::File.expand_path('
|
32
|
+
module Examples
|
33
|
+
RESOURCES_DIR = ::File.expand_path('../../examples/resources', __FILE__)
|
28
34
|
end
|
29
35
|
|
30
36
|
end
|
@@ -32,27 +38,43 @@ end
|
|
32
38
|
require_relative 'support/include_in_json'
|
33
39
|
require_relative 'support/contain_file'
|
34
40
|
require_relative 'support/surpressed_output'
|
41
|
+
require_relative 'support/object_convertable_to_json'
|
42
|
+
require_relative 'support/extensions/core/random'
|
35
43
|
require_relative 'support/rack/request_fixture'
|
36
44
|
require_relative 'support/rack/rack_application_test'
|
37
45
|
require_relative 'support/cross_origin_server/integration'
|
38
46
|
require_relative 'support/cross_origin_server/index_page'
|
47
|
+
require_relative 'support/http_stub/port'
|
48
|
+
require_relative 'support/http_stub/headers_fixture'
|
49
|
+
require_relative 'support/http_stub/configurator/stub_builder'
|
50
|
+
require_relative 'support/http_stub/configurator/stub_fixture'
|
51
|
+
require_relative 'support/http_stub/configurator/scenario_builder'
|
52
|
+
require_relative 'support/http_stub/configurator/scenario_fixture'
|
53
|
+
require_relative 'support/http_stub/configurator_fixture'
|
54
|
+
require_relative 'support/http_stub/server/silent_logger'
|
55
|
+
require_relative 'support/http_stub/server/simple_request'
|
56
|
+
require_relative 'support/http_stub/server/request/sinatra_request_fixture'
|
39
57
|
require_relative 'support/http_stub/server/request_fixture'
|
40
58
|
require_relative 'support/http_stub/server/session_fixture'
|
41
59
|
require_relative 'support/http_stub/server/scenario_fixture'
|
42
60
|
require_relative 'support/http_stub/server/memory_fixture'
|
43
61
|
require_relative 'support/http_stub/server/stub/match/match_fixture'
|
44
62
|
require_relative 'support/http_stub/server/stub/match/miss_fixture'
|
45
|
-
require_relative 'support/http_stub/
|
46
|
-
require_relative 'support/http_stub/
|
63
|
+
require_relative 'support/http_stub/server/stub/response/file_body_fixture'
|
64
|
+
require_relative 'support/http_stub/server/stub/response/text_body_fixture'
|
65
|
+
require_relative 'support/http_stub/server/stub/response/blocks_fixture'
|
66
|
+
require_relative 'support/http_stub/server/stub/response_builder'
|
67
|
+
require_relative 'support/http_stub/server/stub/response_fixture'
|
68
|
+
require_relative 'support/http_stub/server/stub_fixture'
|
47
69
|
require_relative 'support/http_stub/server/application/http_stub_rack_application_test'
|
48
|
-
require_relative 'support/http_stub/empty_configurer'
|
49
70
|
require_relative 'support/http_stub/server/driver'
|
50
71
|
require_relative 'support/http_stub/server_integration'
|
51
|
-
require_relative 'support/http_stub/
|
52
|
-
require_relative 'support/http_stub/
|
72
|
+
require_relative 'support/http_stub/configurator_with_stub_builder_and_requester'
|
73
|
+
require_relative 'support/http_stub/stub_requester'
|
74
|
+
|
53
75
|
require_relative 'support/html_helpers'
|
54
|
-
require_relative 'support/http_stub/
|
55
|
-
require_relative 'support/http_stub/
|
76
|
+
require_relative 'support/http_stub/html_view_including_a_stub_request'
|
77
|
+
require_relative 'support/http_stub/html_view_excluding_a_stub_request'
|
56
78
|
require_relative 'support/http_stub/selenium/browser'
|
57
79
|
require_relative 'support/browser_integration'
|
58
80
|
|
@@ -0,0 +1,109 @@
|
|
1
|
+
describe HttpStub::Client::Client do
|
2
|
+
|
3
|
+
let(:server_uri) { "/some/server/uri" }
|
4
|
+
|
5
|
+
let(:server) { instance_double(HttpStub::Client::Server) }
|
6
|
+
let(:default_session) { instance_double(HttpStub::Client::Session) }
|
7
|
+
|
8
|
+
let(:client) { described_class.new(server_uri) }
|
9
|
+
|
10
|
+
before(:example) do
|
11
|
+
allow(HttpStub::Client::Server).to receive(:new).and_return(server)
|
12
|
+
allow(HttpStub::Client::Session).to receive(:new).and_return(default_session)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "creates a server for the requests issued by the client supplying the server URI" do
|
16
|
+
expect(HttpStub::Client::Server).to receive(:new).with(server_uri)
|
17
|
+
|
18
|
+
client
|
19
|
+
end
|
20
|
+
|
21
|
+
it "creates a default session which the client uses when sessions are not used" do
|
22
|
+
expect(HttpStub::Client::Session).to receive(:new)
|
23
|
+
|
24
|
+
client
|
25
|
+
end
|
26
|
+
|
27
|
+
it "creates a default session identified as the transactional session" do
|
28
|
+
expect(HttpStub::Client::Session).to receive(:new).with("http_stub_transactional", anything)
|
29
|
+
|
30
|
+
client
|
31
|
+
end
|
32
|
+
|
33
|
+
it "creates a default session that uses the server to issue requests" do
|
34
|
+
expect(HttpStub::Client::Session).to receive(:new).with(anything, server)
|
35
|
+
|
36
|
+
client
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#session" do
|
40
|
+
|
41
|
+
let(:session_id) { "some session id" }
|
42
|
+
|
43
|
+
let(:session) { instance_double(HttpStub::Client::Session) }
|
44
|
+
|
45
|
+
subject { client.session(session_id) }
|
46
|
+
|
47
|
+
before(:example) { allow(HttpStub::Client::Session).to receive(:new).and_return(session) }
|
48
|
+
|
49
|
+
it "creates a session for the provided ID" do
|
50
|
+
expect(HttpStub::Client::Session).to receive(:new).with(session_id, anything)
|
51
|
+
|
52
|
+
subject
|
53
|
+
end
|
54
|
+
|
55
|
+
it "creates a session that uses the server to issue requests" do
|
56
|
+
expect(HttpStub::Client::Session).to receive(:new).with(anything, server)
|
57
|
+
|
58
|
+
subject
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns the created session" do
|
62
|
+
expect(subject).to eql(session)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#activate!" do
|
68
|
+
|
69
|
+
let(:scenario_name) { "Some scenario name" }
|
70
|
+
|
71
|
+
subject { client.activate!(scenario_name) }
|
72
|
+
|
73
|
+
it "delegates to the default session" do
|
74
|
+
expect(default_session).to receive(:activate!).with(scenario_name)
|
75
|
+
|
76
|
+
subject
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#reset!" do
|
82
|
+
|
83
|
+
let(:request) { instance_double(HttpStub::Client::Request::Basic) }
|
84
|
+
|
85
|
+
subject { client.reset! }
|
86
|
+
|
87
|
+
before(:example) { allow(server).to receive(:submit!) }
|
88
|
+
|
89
|
+
it "submits a delete request" do
|
90
|
+
expect(server).to receive(:submit!).with(hash_including(method: :delete))
|
91
|
+
|
92
|
+
subject
|
93
|
+
end
|
94
|
+
|
95
|
+
it "submits a request to the sessions endpoint" do
|
96
|
+
expect(server).to receive(:submit!).with(hash_including(path: "sessions"))
|
97
|
+
|
98
|
+
subject
|
99
|
+
end
|
100
|
+
|
101
|
+
it "describes the intent of the request as to reset the server" do
|
102
|
+
expect(server).to receive(:submit!).with(hash_including(intent: "reset server"))
|
103
|
+
|
104
|
+
subject
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
describe HttpStub::Client::Request, "integrating with a server" do
|
2
|
+
|
3
|
+
let(:request_intent) { "some request intent" }
|
4
|
+
let(:request_args_overrides) { {} }
|
5
|
+
let(:request_args) do
|
6
|
+
{
|
7
|
+
method: :post,
|
8
|
+
base_uri: server_uri,
|
9
|
+
path: "stubs/reset",
|
10
|
+
intent: request_intent,
|
11
|
+
http_options: { open_timeout: 1 }
|
12
|
+
}.merge(request_args_overrides)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:request) { described_class.new(request_args) }
|
16
|
+
|
17
|
+
describe "#submit" do
|
18
|
+
|
19
|
+
subject { request.submit }
|
20
|
+
|
21
|
+
context "when a server is running" do
|
22
|
+
include_context "server integration"
|
23
|
+
|
24
|
+
context "and a valid request is submitted" do
|
25
|
+
|
26
|
+
it "executes without error" do
|
27
|
+
expect { subject }.not_to raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns a response that indicates the request was issued" do
|
31
|
+
expect(subject.code).to eql("200")
|
32
|
+
end
|
33
|
+
|
34
|
+
context "that contains parameters" do
|
35
|
+
|
36
|
+
let(:request_args_overrides) do
|
37
|
+
{
|
38
|
+
path: "scenarios/activate",
|
39
|
+
parameters: { "names[]" => [ "invalid_scenario" ] }
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
it "executes without error" do
|
44
|
+
expect { subject }.not_to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns a response that indicates the request honoured the parameters" do
|
48
|
+
expect(subject.body).to include("invalid_scenario")
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when a request is submitted to an unavailable server" do
|
58
|
+
|
59
|
+
let(:request_args_overrides) do
|
60
|
+
{
|
61
|
+
base_uri: "http://localhost:#{HttpStub::Port.free_port}",
|
62
|
+
path: "does/not/exist"
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "raises an exception" do
|
67
|
+
expect { subject }.to raise_error(StandardError)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
describe HttpStub::Client::Request do
|
2
|
+
|
3
|
+
let(:request_method) { :post }
|
4
|
+
let(:request_intent) { "some intent" }
|
5
|
+
let(:request_args) do
|
6
|
+
{
|
7
|
+
method: request_method,
|
8
|
+
base_uri: "http://some/base/uri",
|
9
|
+
path: "some/path",
|
10
|
+
intent: request_intent
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:request) { described_class.new(request_args) }
|
15
|
+
|
16
|
+
describe "#submit" do
|
17
|
+
|
18
|
+
subject { request.submit }
|
19
|
+
|
20
|
+
context "when an invalid method is provided" do
|
21
|
+
|
22
|
+
let(:request_method) { :invalid }
|
23
|
+
|
24
|
+
it "raises an error describing the intent of the request" do
|
25
|
+
expect { subject }.to raise_error(/#{request_intent}/)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|