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
@@ -42,8 +42,10 @@ describe HttpStub::Server::Registry do
|
|
42
42
|
|
43
43
|
subject { described_class.new(model_name, models) }
|
44
44
|
|
45
|
-
it "creates a registry with the models" do
|
46
|
-
|
45
|
+
it "creates a registry with the models in reverse order as the registry operates akin to a stack" do
|
46
|
+
registry = subject
|
47
|
+
|
48
|
+
expect(registry.all).to eql(models.reverse)
|
47
49
|
end
|
48
50
|
|
49
51
|
end
|
@@ -230,6 +232,59 @@ describe HttpStub::Server::Registry do
|
|
230
232
|
|
231
233
|
end
|
232
234
|
|
235
|
+
describe "#find_all" do
|
236
|
+
|
237
|
+
subject { registry.find_all(&condition) }
|
238
|
+
|
239
|
+
context "when multiple models have been registered" do
|
240
|
+
include_context "register multiple models"
|
241
|
+
|
242
|
+
let(:condition) { lambda { |model| matching_models.include?(model) } }
|
243
|
+
|
244
|
+
context "when many models match the condition" do
|
245
|
+
|
246
|
+
let(:matching_models) { [ models.first, models.last ] }
|
247
|
+
|
248
|
+
it "returns the models preserving stack order" do
|
249
|
+
expect(subject).to eql(matching_models.reverse)
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
context "when one model matches the condition" do
|
255
|
+
|
256
|
+
let(:matching_models) { [ models[1] ] }
|
257
|
+
|
258
|
+
it "returns an array containing the model" do
|
259
|
+
expect(subject).to eql(matching_models)
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
context "when no model matches the condition" do
|
265
|
+
|
266
|
+
let(:matching_models) { [] }
|
267
|
+
|
268
|
+
it "returns an empty array" do
|
269
|
+
expect(subject).to eql([])
|
270
|
+
end
|
271
|
+
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
|
276
|
+
context "when no models have been registered" do
|
277
|
+
|
278
|
+
let(:condition) { lambda { |_| true } }
|
279
|
+
|
280
|
+
it "returns an empty array" do
|
281
|
+
expect(subject).to eql([])
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
233
288
|
describe "#last" do
|
234
289
|
|
235
290
|
context "when multiple models have been registered" do
|
@@ -1,19 +1,21 @@
|
|
1
1
|
describe HttpStub::Server::Request::Factory do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:session_registry)
|
5
|
-
let(:server_memory)
|
3
|
+
let(:session_identifier_setting) { nil }
|
4
|
+
let(:session_registry) { instance_double(HttpStub::Server::Session::Registry) }
|
5
|
+
let(:server_memory) do
|
6
|
+
instance_double(HttpStub::Server::Memory::Memory, session_registry: session_registry)
|
7
|
+
end
|
6
8
|
|
7
9
|
let(:session_identifier_strategy) { instance_double(HttpStub::Server::Session::IdentifierStrategy) }
|
8
10
|
|
9
|
-
let(:factory) { described_class.new(
|
11
|
+
let(:factory) { described_class.new(session_identifier_setting, server_memory) }
|
10
12
|
|
11
13
|
before(:example) do
|
12
14
|
allow(HttpStub::Server::Session::IdentifierStrategy).to receive(:new).and_return(session_identifier_strategy)
|
13
15
|
end
|
14
16
|
|
15
|
-
it "creates a session identifier strategy based on the session
|
16
|
-
expect(HttpStub::Server::Session::IdentifierStrategy).to receive(:new).with(
|
17
|
+
it "creates a session identifier strategy based on the session identifier setting" do
|
18
|
+
expect(HttpStub::Server::Session::IdentifierStrategy).to receive(:new).with(session_identifier_setting)
|
17
19
|
|
18
20
|
factory
|
19
21
|
end
|
@@ -7,7 +7,7 @@ describe HttpStub::Server::Response do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it "has a body containing OK to visually indicate success to those interacting via a browser" do
|
10
|
-
expect(subject.body).to include("OK")
|
10
|
+
expect(subject.body.to_s).to include("OK")
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
@@ -20,20 +20,42 @@ describe HttpStub::Server::Response do
|
|
20
20
|
|
21
21
|
context "when options are provided" do
|
22
22
|
|
23
|
-
let(:headers)
|
24
|
-
let(:body)
|
25
|
-
let(:
|
23
|
+
let(:headers) { { response_header_key: "response header value" } }
|
24
|
+
let(:body) { "response body" }
|
25
|
+
let(:delay_in_seconds) { "response body" }
|
26
|
+
let(:opts) { { headers: headers, body: body, delay_in_seconds: delay_in_seconds } }
|
26
27
|
|
27
|
-
subject {
|
28
|
+
subject { described_class.ok(opts) }
|
28
29
|
|
29
30
|
it "establishes any headers provided" do
|
30
|
-
expect(subject.headers).to eql(headers)
|
31
|
+
expect(subject.headers.to_json).to eql(headers.to_json)
|
31
32
|
end
|
32
33
|
|
33
34
|
it "establishes any body provided" do
|
34
|
-
expect(subject.body).to eql(body)
|
35
|
+
expect(subject.body.to_s).to eql(body)
|
35
36
|
end
|
36
37
|
|
38
|
+
it "establishes any delay provided" do
|
39
|
+
expect(subject.delay_in_seconds).to eql(delay_in_seconds)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "::invalid_request" do
|
47
|
+
|
48
|
+
let(:cause_message) { "Some error message" }
|
49
|
+
let(:cause) { StandardError.new(cause_message) }
|
50
|
+
|
51
|
+
subject { described_class.invalid_request(cause) }
|
52
|
+
|
53
|
+
it "has a status of 400" do
|
54
|
+
expect(subject.status).to eql(400)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "has a body containing the message of the cause" do
|
58
|
+
expect(subject.body.to_s).to include(cause_message)
|
37
59
|
end
|
38
60
|
|
39
61
|
end
|
@@ -55,7 +77,7 @@ describe HttpStub::Server::Response do
|
|
55
77
|
end
|
56
78
|
|
57
79
|
it "has a body containing NOT FOUND to visually indicate the response to those interacting via a browser" do
|
58
|
-
expect(subject.body).to include("NOT FOUND")
|
80
|
+
expect(subject.body.to_s).to include("NOT FOUND")
|
59
81
|
end
|
60
82
|
|
61
83
|
end
|
@@ -68,8 +90,8 @@ describe HttpStub::Server::Response do
|
|
68
90
|
expect(subject.status).to eql(200)
|
69
91
|
end
|
70
92
|
|
71
|
-
it "has
|
72
|
-
expect(subject.body.
|
93
|
+
it "has an empty body" do
|
94
|
+
expect(subject.body.to_s).to be_empty
|
73
95
|
end
|
74
96
|
|
75
97
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
describe HttpStub::Server::Scenario::Controller do
|
2
2
|
|
3
3
|
let(:scenario_registry) { instance_double(HttpStub::Server::Registry) }
|
4
|
-
let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory,
|
4
|
+
let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory, scenario_registry: scenario_registry) }
|
5
5
|
|
6
6
|
let(:request_uri) { "/some/request/path" }
|
7
7
|
let(:request_parameters) { {} }
|
@@ -12,47 +12,12 @@ describe HttpStub::Server::Scenario::Controller do
|
|
12
12
|
session: session)
|
13
13
|
end
|
14
14
|
let(:logger) { instance_double(Logger) }
|
15
|
-
let(:payload) { HttpStub::ScenarioFixture.new.server_payload }
|
16
15
|
let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
17
16
|
let(:scenario) { instance_double(HttpStub::Server::Scenario::Scenario, stubs: stubs) }
|
18
17
|
let(:activator) { instance_double(HttpStub::Server::Scenario::Activator).as_null_object }
|
19
18
|
|
20
19
|
let(:controller) { described_class.new(server_memory) }
|
21
20
|
|
22
|
-
describe "#register" do
|
23
|
-
|
24
|
-
subject { controller.register(request, logger) }
|
25
|
-
|
26
|
-
before(:example) do
|
27
|
-
allow(HttpStub::Server::Scenario::Parser).to receive(:parse).and_return(payload)
|
28
|
-
allow(HttpStub::Server::Scenario).to receive(:create).and_return(scenario)
|
29
|
-
allow(scenario_registry).to receive(:add)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "parses the payload from the request" do
|
33
|
-
expect(HttpStub::Server::Scenario::Parser).to receive(:parse).with(request).and_return(payload)
|
34
|
-
|
35
|
-
subject
|
36
|
-
end
|
37
|
-
|
38
|
-
it "creates a scenario with the parsed payload" do
|
39
|
-
expect(HttpStub::Server::Scenario).to receive(:create).with(payload).and_return(scenario)
|
40
|
-
|
41
|
-
subject
|
42
|
-
end
|
43
|
-
|
44
|
-
it "adds the created scenario to the servers scenario registry with the provided logger" do
|
45
|
-
expect(scenario_registry).to receive(:add).with(scenario, logger)
|
46
|
-
|
47
|
-
subject
|
48
|
-
end
|
49
|
-
|
50
|
-
it "returns an ok response" do
|
51
|
-
expect(subject).to eql(HttpStub::Server::Response::OK)
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
21
|
describe "#find" do
|
57
22
|
|
58
23
|
let(:name) { URI.encode_www_form_component("Some scenario name") }
|
@@ -82,7 +47,7 @@ describe HttpStub::Server::Scenario::Controller do
|
|
82
47
|
|
83
48
|
describe "#find_all" do
|
84
49
|
|
85
|
-
let(:scenarios) { (1..3).map { |i| HttpStub::Server::ScenarioFixture.create("#{4 - i}") } }
|
50
|
+
let(:scenarios) { (1..3).map { |i| HttpStub::Server::ScenarioFixture.create(name: "#{4 - i}") } }
|
86
51
|
|
87
52
|
subject { controller.find_all }
|
88
53
|
|
@@ -123,8 +88,12 @@ describe HttpStub::Server::Scenario::Controller do
|
|
123
88
|
)
|
124
89
|
end
|
125
90
|
|
126
|
-
it "returns a
|
127
|
-
expect(subject).to eql(
|
91
|
+
it "returns a response indicating the request was invalid" do
|
92
|
+
expect(subject.status).to eql(400)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns a response whose body includes the scenario name" do
|
96
|
+
expect(subject.body.to_s).to include(scenario_name)
|
128
97
|
end
|
129
98
|
|
130
99
|
end
|
@@ -156,8 +125,12 @@ describe HttpStub::Server::Scenario::Controller do
|
|
156
125
|
)
|
157
126
|
end
|
158
127
|
|
159
|
-
it "returns a
|
160
|
-
expect(subject).to eql(
|
128
|
+
it "returns a response indicating the request was invalid" do
|
129
|
+
expect(subject.status).to eql(400)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns a response whose body includes the name of the not found scenario" do
|
133
|
+
expect(subject.body.to_s).to include(scenario_name_not_found)
|
161
134
|
end
|
162
135
|
|
163
136
|
end
|
@@ -178,16 +151,4 @@ describe HttpStub::Server::Scenario::Controller do
|
|
178
151
|
|
179
152
|
end
|
180
153
|
|
181
|
-
describe "#clear" do
|
182
|
-
|
183
|
-
subject { controller.clear(logger) }
|
184
|
-
|
185
|
-
it "clears the servers scenario registry" do
|
186
|
-
expect(scenario_registry).to receive(:clear).with(logger)
|
187
|
-
|
188
|
-
subject
|
189
|
-
end
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
154
|
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
describe HttpStub::Server::Scenario::Registry do
|
2
|
+
|
3
|
+
let(:scenarios) { (1..3).map { HttpStub::Server::ScenarioFixture.create } }
|
4
|
+
|
5
|
+
let(:logger) { HttpStub::Server::SilentLogger }
|
6
|
+
|
7
|
+
let(:scenario_registry) { described_class.new(scenarios) }
|
8
|
+
|
9
|
+
shared_context "mocked underlying registry" do
|
10
|
+
|
11
|
+
let(:underlying_scenario_registry) { instance_double(HttpStub::Server::Registry) }
|
12
|
+
|
13
|
+
before(:example) { allow(HttpStub::Server::Registry).to receive(:new).and_return(underlying_scenario_registry) }
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
it "uses an underlying simple registry that is initialised with the provided scenarios" do
|
18
|
+
expect(HttpStub::Server::Registry).to receive(:new).with("scenario", scenarios)
|
19
|
+
|
20
|
+
scenario_registry
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#find" do
|
24
|
+
include_context "mocked underlying registry"
|
25
|
+
|
26
|
+
let(:name) { "some scenario name" }
|
27
|
+
|
28
|
+
let(:found_scenario) { scenarios.last }
|
29
|
+
|
30
|
+
subject { scenario_registry.find(name, logger) }
|
31
|
+
|
32
|
+
before(:example) { allow(underlying_scenario_registry).to receive(:find).and_return(found_scenario) }
|
33
|
+
|
34
|
+
it "delegates to an underlying simple registry" do
|
35
|
+
expect(underlying_scenario_registry).to receive(:find).with(name, logger)
|
36
|
+
|
37
|
+
subject
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns any found scenario" do
|
41
|
+
expect(subject).to eql(found_scenario)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#find_all" do
|
47
|
+
|
48
|
+
subject { scenario_registry.find_all { |scenario| matching_scenarios.include?(scenario) } }
|
49
|
+
|
50
|
+
context "when some scenarios match" do
|
51
|
+
|
52
|
+
let(:matching_scenarios) { [ scenarios.first, scenarios.last ] }
|
53
|
+
|
54
|
+
it "returns the matching scenarios" do
|
55
|
+
expect(subject).to contain_exactly(*matching_scenarios)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when no scenarios match" do
|
61
|
+
|
62
|
+
let(:matching_scenarios) { [] }
|
63
|
+
|
64
|
+
it "returns an empty array" do
|
65
|
+
expect(subject).to eql([])
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#all" do
|
73
|
+
include_context "mocked underlying registry"
|
74
|
+
|
75
|
+
let(:all_scenarios) { (1..3).map { HttpStub::Server::ScenarioFixture.create } }
|
76
|
+
|
77
|
+
subject { scenario_registry.all }
|
78
|
+
|
79
|
+
before(:example) { allow(underlying_scenario_registry).to receive(:all).and_return(all_scenarios) }
|
80
|
+
|
81
|
+
it "delegates to an underlying simple registry" do
|
82
|
+
expect(underlying_scenario_registry).to receive(:all)
|
83
|
+
|
84
|
+
subject
|
85
|
+
end
|
86
|
+
|
87
|
+
it "returns the result from the underlying registry" do
|
88
|
+
expect(subject).to eql(all_scenarios)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#stubs_activated_by" do
|
94
|
+
|
95
|
+
let(:scenario) do
|
96
|
+
HttpStub::Server::ScenarioFixture.with_stubs(
|
97
|
+
triggered_scenario_names: scenarios_triggered_names
|
98
|
+
)
|
99
|
+
end
|
100
|
+
let(:other_scenarios) { (1..3).map { HttpStub::Server::ScenarioFixture.with_stubs } }
|
101
|
+
|
102
|
+
subject { scenario_registry.stubs_activated_by(scenario, logger) }
|
103
|
+
|
104
|
+
context "when the scenario has no triggers" do
|
105
|
+
|
106
|
+
let(:scenarios) { [ scenario ] + other_scenarios }
|
107
|
+
let(:scenarios_triggered_names) { [] }
|
108
|
+
|
109
|
+
it "returns the scenario's stubs" do
|
110
|
+
expect(subject).to eql(scenario.stubs)
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
context "when the scenario has triggers which are nested" do
|
116
|
+
|
117
|
+
let(:scenarios_triggered_names) { (1..3).map { |i| "trigger_#{i}" } }
|
118
|
+
let(:nested_scenario_triggered_names) { (1..3).map { |i| (1..3).map { |j| "nested_trigger_#{i}_#{j}" } } }
|
119
|
+
|
120
|
+
let(:scenarios_triggered) do
|
121
|
+
scenarios_triggered_names.each_with_index.map do |trigger_name, i|
|
122
|
+
HttpStub::Server::ScenarioFixture.with_stubs(
|
123
|
+
name: trigger_name,
|
124
|
+
triggered_scenario_names: nested_scenario_triggered_names[i]
|
125
|
+
)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
let(:nested_scenarios_triggered) do
|
130
|
+
nested_scenario_triggered_names.map do |trigger_names|
|
131
|
+
trigger_names.map { |trigger_name| HttpStub::Server::ScenarioFixture.with_stubs(name: trigger_name) }
|
132
|
+
end.flatten
|
133
|
+
end
|
134
|
+
|
135
|
+
let(:scenarios) { [ scenario ] + other_scenarios + scenarios_triggered + nested_scenarios_triggered }
|
136
|
+
|
137
|
+
it "returns the stubs from the scenario and all triggered scenario's" do
|
138
|
+
active_scenarios = [ scenario, scenarios_triggered, nested_scenarios_triggered ].flatten
|
139
|
+
|
140
|
+
expect(subject).to contain_exactly(*active_scenarios.map(&:stubs).flatten)
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
@@ -12,15 +12,15 @@ describe HttpStub::Server::Scenario::Scenario do
|
|
12
12
|
(1..number_of_triggered_scenario_names).map { instance_double(HttpStub::Server::Scenario::Trigger) }
|
13
13
|
end
|
14
14
|
|
15
|
-
let(:
|
16
|
-
HttpStub::
|
15
|
+
let(:scenario_hash) do
|
16
|
+
HttpStub::Configurator::ScenarioBuilder.new.
|
17
17
|
with_name!(name).
|
18
18
|
with_stubs!(number_of_stubs).
|
19
19
|
with_triggered_scenario_names!(triggered_scenario_names).
|
20
|
-
|
20
|
+
build_hash
|
21
21
|
end
|
22
22
|
|
23
|
-
let(:scenario) { described_class.new(
|
23
|
+
let(:scenario) { described_class.new(scenario_hash) }
|
24
24
|
|
25
25
|
describe "#constructor" do
|
26
26
|
|
@@ -31,7 +31,7 @@ describe HttpStub::Server::Scenario::Scenario do
|
|
31
31
|
let(:number_of_stubs) { 3 }
|
32
32
|
|
33
33
|
it "creates an underlying stub for each stub payload provided" do
|
34
|
-
|
34
|
+
scenario_hash[:stubs].each { |stub_args| expect(HttpStub::Server::Stub).to receive(:create).with(stub_args) }
|
35
35
|
|
36
36
|
subject
|
37
37
|
end
|
@@ -43,7 +43,7 @@ describe HttpStub::Server::Scenario::Scenario do
|
|
43
43
|
let(:number_of_stubs) { 1 }
|
44
44
|
|
45
45
|
it "creates an underlying stub for the stub payload provided" do
|
46
|
-
expect(HttpStub::Server::Stub).to receive(:create).with(
|
46
|
+
expect(HttpStub::Server::Stub).to receive(:create).with(scenario_hash[:stubs].first)
|
47
47
|
|
48
48
|
subject
|
49
49
|
end
|
@@ -159,10 +159,8 @@ describe HttpStub::Server::Scenario::Scenario do
|
|
159
159
|
|
160
160
|
describe "#to_s" do
|
161
161
|
|
162
|
-
it "returns the string representation of the
|
163
|
-
expect(
|
164
|
-
|
165
|
-
expect(scenario.to_s).to eql("scenario string representation")
|
162
|
+
it "returns the string representation of the provided hash" do
|
163
|
+
expect(scenario.to_s).to eql(scenario_hash.to_s)
|
166
164
|
end
|
167
165
|
|
168
166
|
end
|