http_stub 0.25.1 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/http_stub.rb +32 -9
- data/lib/http_stub/configurer.rb +2 -10
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +13 -11
- data/lib/http_stub/configurer/dsl/server.rb +32 -43
- data/lib/http_stub/configurer/dsl/server_endpoint_template.rb +23 -0
- data/lib/http_stub/configurer/dsl/session.rb +55 -0
- data/lib/http_stub/configurer/dsl/session_endpoint_template.rb +22 -0
- data/lib/http_stub/configurer/dsl/session_factory.rb +34 -0
- data/lib/http_stub/configurer/dsl/stub_builder.rb +18 -8
- data/lib/http_stub/configurer/dsl/stub_builder_template.rb +26 -0
- data/lib/http_stub/configurer/request/http/basic.rb +9 -3
- data/lib/http_stub/configurer/request/http/factory.rb +7 -16
- data/lib/http_stub/configurer/request/http/multipart.rb +5 -7
- data/lib/http_stub/configurer/request/stub.rb +3 -3
- data/lib/http_stub/configurer/request/triggers.rb +25 -0
- data/lib/http_stub/configurer/server/command_processor.rb +8 -10
- data/lib/http_stub/configurer/server/configuration.rb +33 -0
- data/lib/http_stub/configurer/server/facade.rb +21 -43
- data/lib/http_stub/configurer/server/request_processor.rb +2 -2
- data/lib/http_stub/configurer/server/session_facade.rb +64 -0
- data/lib/http_stub/extensions/core/uri.rb +28 -0
- data/lib/http_stub/extensions/rack/handler.rb +1 -0
- data/lib/http_stub/extensions/sinatra/namespace.rb +9 -0
- data/lib/http_stub/rake/server_tasks.rb +1 -4
- data/lib/http_stub/server/application/application.rb +17 -98
- data/lib/http_stub/server/application/configuration.rb +38 -0
- data/lib/http_stub/server/application/cross_origin_support.rb +7 -5
- data/lib/http_stub/server/application/request_support.rb +38 -0
- data/lib/http_stub/server/application/response_support.rb +19 -0
- data/lib/http_stub/server/application/routes/memory.rb +37 -0
- data/lib/http_stub/server/application/routes/resource.rb +23 -0
- data/lib/http_stub/server/application/routes/scenario.rb +52 -0
- data/lib/http_stub/server/application/routes/session.rb +65 -0
- data/lib/http_stub/server/application/routes/stub.rb +75 -0
- data/lib/http_stub/server/application/session_uri_support.rb +15 -0
- data/lib/http_stub/server/memory/controller.rb +25 -0
- data/lib/http_stub/server/memory/memory.rb +32 -0
- data/lib/http_stub/server/registry.rb +25 -8
- data/lib/http_stub/server/request/factory.rb +23 -0
- data/lib/http_stub/server/request/parameters.rb +2 -2
- data/lib/http_stub/server/request/request.rb +6 -11
- data/lib/http_stub/server/request/sinatra_request.rb +26 -0
- data/lib/http_stub/server/scenario/controller.rb +16 -11
- data/lib/http_stub/server/scenario/not_found_error.rb +15 -0
- data/lib/http_stub/server/session.rb +14 -0
- data/lib/http_stub/server/session/configuration.rb +32 -0
- data/lib/http_stub/server/session/controller.rb +40 -0
- data/lib/http_stub/server/session/empty.rb +15 -0
- data/lib/http_stub/server/session/identifier_strategy.rb +24 -0
- data/lib/http_stub/server/session/registry.rb +38 -0
- data/lib/http_stub/server/session/session.rb +80 -0
- data/lib/http_stub/server/stub/controller.rb +18 -12
- data/lib/http_stub/server/stub/empty.rb +1 -1
- data/lib/http_stub/server/stub/match/controller.rb +9 -5
- data/lib/http_stub/server/stub/payload/response_body_modifier.rb +3 -1
- data/lib/http_stub/server/stub/registry.rb +6 -13
- data/lib/http_stub/server/stub/triggers.rb +11 -9
- data/lib/http_stub/server/views/_home.haml +2 -0
- data/lib/http_stub/server/views/_post_link_function.haml +26 -0
- data/lib/http_stub/server/views/_session.haml +16 -0
- data/lib/http_stub/server/views/_stub.haml +8 -2
- data/lib/http_stub/server/views/_stubs.haml +4 -0
- data/lib/http_stub/server/views/application.sass +4 -1
- data/lib/http_stub/server/views/layout.haml +1 -0
- data/lib/http_stub/server/views/scenario.haml +4 -3
- data/lib/http_stub/server/views/scenarios.haml +7 -6
- data/lib/http_stub/server/views/session.haml +3 -0
- data/lib/http_stub/server/views/sessions.haml +6 -0
- data/lib/http_stub/server/views/stubs.haml +1 -4
- data/lib/http_stub/server/views/transactional_session.haml +2 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/configurer_initialization_spec.rb +40 -51
- data/spec/acceptance/configurer_part_spec.rb +5 -7
- data/spec/acceptance/cross_origin_support_spec.rb +7 -13
- data/spec/acceptance/endpoint_template_spec.rb +2 -4
- data/spec/acceptance/request_reference_spec.rb +1 -3
- data/spec/acceptance/scenario_spec.rb +7 -9
- data/spec/acceptance/server_defaults_spec.rb +2 -4
- data/spec/acceptance/server_memory_spec.rb +20 -0
- data/spec/acceptance/session_spec.rb +125 -0
- data/spec/acceptance/stub_body_request_matching_spec.rb +2 -4
- data/spec/acceptance/stub_control_values_spec.rb +19 -18
- data/spec/acceptance/stub_match_last_spec.rb +0 -4
- data/spec/acceptance/stub_match_list_spec.rb +0 -4
- data/spec/acceptance/stub_miss_list_spec.rb +0 -4
- data/spec/acceptance/stub_spec.rb +11 -11
- data/spec/acceptance/stub_trigger_spec.rb +60 -13
- data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +83 -30
- data/spec/lib/http_stub/configurer/dsl/server_endpoint_template_spec.rb +167 -0
- data/spec/lib/http_stub/configurer/dsl/server_spec.rb +306 -176
- data/spec/lib/http_stub/configurer/dsl/session_endpoint_template_spec.rb +150 -0
- data/spec/lib/http_stub/configurer/dsl/session_factory_spec.rb +97 -0
- data/spec/lib/http_stub/configurer/dsl/session_spec.rb +222 -0
- data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +209 -48
- data/spec/lib/http_stub/configurer/dsl/stub_builder_template_spec.rb +203 -0
- data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +80 -4
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +115 -56
- data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +39 -6
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +50 -108
- data/spec/lib/http_stub/configurer/request/triggers_spec.rb +101 -0
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +11 -10
- data/spec/lib/http_stub/configurer/server/configuration_spec.rb +139 -0
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +65 -142
- data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +7 -6
- data/spec/lib/http_stub/configurer/server/session_facade_spec.rb +336 -0
- data/spec/lib/http_stub/configurer_spec.rb +105 -0
- data/spec/lib/http_stub/extensions/core/uri_spec.rb +75 -0
- data/spec/lib/http_stub/extensions/rack/handler_spec.rb +1 -1
- data/spec/lib/http_stub/extensions/sinatra/namespace_spec.rb +36 -0
- data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +4 -3
- data/spec/lib/http_stub/rake/server_tasks_spec.rb +47 -10
- data/spec/lib/http_stub/server/application/application_spec.rb +44 -301
- data/spec/lib/http_stub/server/application/configuration_spec.rb +59 -0
- data/spec/lib/http_stub/server/application/cross_origin_support_spec.rb +23 -20
- data/spec/lib/http_stub/server/application/request_support_integration_spec.rb +93 -0
- data/spec/lib/http_stub/server/application/request_support_spec.rb +61 -0
- data/spec/lib/http_stub/server/application/response_support_spec.rb +30 -0
- data/spec/lib/http_stub/server/application/routes/memory_spec.rb +41 -0
- data/spec/lib/http_stub/server/application/routes/resource_spec.rb +16 -0
- data/spec/lib/http_stub/server/application/routes/scenario_spec.rb +117 -0
- data/spec/lib/http_stub/server/application/routes/session_integration_spec.rb +46 -0
- data/spec/lib/http_stub/server/application/routes/session_spec.rb +186 -0
- data/spec/lib/http_stub/server/application/{application_integration_spec.rb → routes/stub_integration_spec.rb} +16 -38
- data/spec/lib/http_stub/server/application/routes/stub_spec.rb +202 -0
- data/spec/lib/http_stub/server/application/session_uri_support_spec.rb +48 -0
- data/spec/lib/http_stub/server/application/text_formatting_support_spec.rb +3 -3
- data/spec/lib/http_stub/server/memory/controller_spec.rb +47 -0
- data/spec/lib/http_stub/server/memory/memory_spec.rb +122 -0
- data/spec/lib/http_stub/server/registry_spec.rb +153 -34
- data/spec/lib/http_stub/server/request/factory_spec.rb +74 -0
- data/spec/lib/http_stub/server/request/parameters_spec.rb +5 -8
- data/spec/lib/http_stub/server/request/request_spec.rb +52 -52
- data/spec/lib/http_stub/server/request/sinatra_request_spec.rb +132 -0
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +121 -35
- data/spec/lib/http_stub/server/scenario/not_found_error_spec.rb +25 -0
- data/spec/lib/http_stub/server/session/configuration_spec.rb +94 -0
- data/spec/lib/http_stub/server/session/controller_spec.rb +106 -0
- data/spec/lib/http_stub/server/session/empty_spec.rb +13 -0
- data/spec/lib/http_stub/server/session/identifier_strategy_spec.rb +126 -0
- data/spec/lib/http_stub/server/session/registry_spec.rb +214 -0
- data/spec/lib/http_stub/server/session/session_spec.rb +444 -0
- data/spec/lib/http_stub/server/stub/controller_spec.rb +89 -37
- data/spec/lib/http_stub/server/stub/empty_spec.rb +2 -2
- data/spec/lib/http_stub/server/stub/match/controller_spec.rb +59 -16
- data/spec/lib/http_stub/server/stub/payload/response_body_modifier_spec.rb +7 -8
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +42 -15
- data/spec/lib/http_stub/server/stub/registry_spec.rb +38 -59
- data/spec/lib/http_stub/server/stub/triggers_spec.rb +93 -34
- data/spec/spec_helper.rb +13 -1
- data/spec/support/contain_file.rb +23 -0
- data/spec/support/cross_origin_server/application.rb +1 -1
- data/spec/support/cross_origin_server/index_page.rb +2 -2
- data/spec/support/cross_origin_server/integration.rb +3 -2
- data/spec/support/cross_origin_server/public/index.html +2 -1
- data/spec/support/http_stub/configurer_integration.rb +12 -14
- data/spec/support/http_stub/server/application/http_stub_rack_application_test.rb +47 -0
- data/spec/support/http_stub/server/driver.rb +56 -0
- data/spec/support/http_stub/server/memory_fixture.rb +17 -0
- data/spec/support/http_stub/server/request_fixture.rb +7 -6
- data/spec/support/http_stub/server/scenario_fixture.rb +13 -0
- data/spec/support/http_stub/server/session_fixture.rb +27 -0
- data/spec/support/http_stub/server_integration.rb +12 -17
- data/spec/support/http_stub/stub_fixture.rb +19 -6
- data/spec/support/include_in_json.rb +4 -4
- data/spec/support/rack/rack_application_test.rb +9 -0
- data/spec/support/rack/request_fixture.rb +13 -0
- data/spec/support/surpressed_output.rb +10 -0
- metadata +149 -36
- data/lib/http_stub/configurer/dsl/deprecated.rb +0 -60
- data/lib/http_stub/configurer/dsl/endpoint_template.rb +0 -38
- data/lib/http_stub/configurer/dsl/scenario_activator.rb +0 -15
- data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +0 -24
- data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +0 -21
- data/lib/http_stub/server/request.rb +0 -12
- data/lib/http_stub/server/scenario/activator.rb +0 -25
- data/lib/http_stub/server/views/_activate_scenario.haml +0 -23
- data/lib/http_stub/server/views/index.haml +0 -8
- data/spec/acceptance/activator_spec.rb +0 -81
- data/spec/lib/http_stub/configurer/dsl/deprecated_spec.rb +0 -240
- data/spec/lib/http_stub/configurer/dsl/endpoint_template_spec.rb +0 -255
- data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +0 -62
- data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +0 -120
- data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +0 -85
- data/spec/lib/http_stub/server/request_spec.rb +0 -24
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +0 -111
- data/spec/support/http_stub/server/scenario/scenario_fixture.rb +0 -15
@@ -0,0 +1,48 @@
|
|
1
|
+
describe HttpStub::Server::Application::SessionUriSupport do
|
2
|
+
|
3
|
+
class HttpStub::Server::Application::SessionUriSupport::TestApplication
|
4
|
+
include HttpStub::Server::Application::SessionUriSupport
|
5
|
+
|
6
|
+
def initialize(request)
|
7
|
+
@request = request
|
8
|
+
end
|
9
|
+
|
10
|
+
def http_stub_request
|
11
|
+
@request
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:session_id) { "some_session_id" }
|
17
|
+
let(:session) { instance_double(HttpStub::Server::Session::Session, id: session_id) }
|
18
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request, session: session) }
|
19
|
+
|
20
|
+
let(:application) { HttpStub::Server::Application::SessionUriSupport::TestApplication.new(request) }
|
21
|
+
|
22
|
+
describe "#session_uri" do
|
23
|
+
|
24
|
+
let(:uri) { "http://some/uri" }
|
25
|
+
|
26
|
+
subject { application.session_uri(uri) }
|
27
|
+
|
28
|
+
context "when the uri contains parameters" do
|
29
|
+
|
30
|
+
let(:uri) { "http://some/uri?parameter_name=parameter_value" }
|
31
|
+
|
32
|
+
it "adds a http_stub_session_id parameter to the uri containing the current session id" do
|
33
|
+
expect(subject).to eql("#{uri}&http_stub_session_id=some_session_id")
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when the uri does not contain parameters" do
|
39
|
+
|
40
|
+
it "adds a http_stub_session_id parameter to the uri containing the current session id" do
|
41
|
+
expect(subject).to eql("#{uri}?http_stub_session_id=some_session_id")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -2,19 +2,19 @@ describe HttpStub::Server::Application::TextFormattingSupport do
|
|
2
2
|
|
3
3
|
let(:text_formatting_support) { Class.new.extend(described_class) }
|
4
4
|
|
5
|
-
describe "
|
5
|
+
describe "#h" do
|
6
6
|
|
7
7
|
let(:text) { "<tag>Some text</tag>" }
|
8
8
|
|
9
9
|
subject { text_formatting_support.h(text) }
|
10
10
|
|
11
11
|
it "should escape the provided HTML" do
|
12
|
-
expect(subject).to
|
12
|
+
expect(subject).to eql("<tag>Some text</tag>")
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
16
16
|
|
17
|
-
describe "
|
17
|
+
describe "#pp" do
|
18
18
|
|
19
19
|
subject { text_formatting_support.pp(text) }
|
20
20
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
describe HttpStub::Server::Memory::Controller do
|
2
|
+
|
3
|
+
let(:session_configuration) { instance_double(HttpStub::Server::Session::Configuration) }
|
4
|
+
let(:server_memory) { instance_double(HttpStub::Server::Memory::Memory) }
|
5
|
+
|
6
|
+
let(:controller) { described_class.new(session_configuration, server_memory) }
|
7
|
+
|
8
|
+
describe "#find_stubs" do
|
9
|
+
|
10
|
+
let(:memorized_stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
11
|
+
|
12
|
+
subject { controller.find_stubs }
|
13
|
+
|
14
|
+
before(:example) { allow(server_memory).to receive(:stubs).and_return(memorized_stubs) }
|
15
|
+
|
16
|
+
it "returns the stubs within the servers memory" do
|
17
|
+
expect(subject).to eql(memorized_stubs)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#reset" do
|
23
|
+
|
24
|
+
let(:logger) { instance_double(Logger) }
|
25
|
+
|
26
|
+
subject { controller.reset(logger) }
|
27
|
+
|
28
|
+
before(:example) do
|
29
|
+
allow(session_configuration).to receive(:reset)
|
30
|
+
allow(server_memory).to receive(:reset)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "resets the servers session configuration" do
|
34
|
+
expect(session_configuration).to receive(:reset)
|
35
|
+
|
36
|
+
subject
|
37
|
+
end
|
38
|
+
|
39
|
+
it "resets the servers memory providing the logger" do
|
40
|
+
expect(server_memory).to receive(:reset).with(logger)
|
41
|
+
|
42
|
+
subject
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
describe HttpStub::Server::Memory::Memory do
|
2
|
+
|
3
|
+
let(:session_configuration) { instance_double(HttpStub::Server::Session::Configuration) }
|
4
|
+
|
5
|
+
let(:memory_session) { instance_double(HttpStub::Server::Session::Session) }
|
6
|
+
let(:scenario_registry) { instance_double(HttpStub::Server::Registry) }
|
7
|
+
let(:session_registry) { instance_double(HttpStub::Server::Session::Registry) }
|
8
|
+
|
9
|
+
let(:memory) { described_class.new(session_configuration) }
|
10
|
+
|
11
|
+
before(:example) do
|
12
|
+
allow(HttpStub::Server::Session::Session).to receive(:new).and_return(memory_session)
|
13
|
+
allow(HttpStub::Server::Registry).to receive(:new).and_return(scenario_registry)
|
14
|
+
allow(HttpStub::Server::Session::Registry).to receive(:new).and_return(session_registry)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "creates a simple scenario registry" do
|
18
|
+
expect(HttpStub::Server::Registry).to receive(:new).with("scenario")
|
19
|
+
|
20
|
+
memory
|
21
|
+
end
|
22
|
+
|
23
|
+
it "creates a memory session" do
|
24
|
+
expect(HttpStub::Server::Session::Session).to(
|
25
|
+
receive(:new).with(HttpStub::Server::Session::MEMORY_SESSION_ID, anything, anything)
|
26
|
+
)
|
27
|
+
|
28
|
+
memory
|
29
|
+
end
|
30
|
+
|
31
|
+
it "creates a memory session containing the scenario registry" do
|
32
|
+
expect(HttpStub::Server::Session::Session).to receive(:new).with(anything, scenario_registry, anything)
|
33
|
+
|
34
|
+
memory
|
35
|
+
end
|
36
|
+
|
37
|
+
it "creates a memory session containing an empty memory session" do
|
38
|
+
expect(HttpStub::Server::Session::Session).to(
|
39
|
+
receive(:new).with(anything, anything, HttpStub::Server::Session::Empty)
|
40
|
+
)
|
41
|
+
|
42
|
+
memory
|
43
|
+
end
|
44
|
+
|
45
|
+
it "creates a session registry containing the session configuration" do
|
46
|
+
expect(HttpStub::Server::Session::Registry).to receive(:new).with(session_configuration, anything, anything)
|
47
|
+
|
48
|
+
memory
|
49
|
+
end
|
50
|
+
|
51
|
+
it "creates a session registry containing the scenario registry" do
|
52
|
+
expect(HttpStub::Server::Session::Registry).to receive(:new).with(anything, scenario_registry, anything)
|
53
|
+
|
54
|
+
memory
|
55
|
+
end
|
56
|
+
|
57
|
+
it "creates a session registry initalised with the memory session" do
|
58
|
+
expect(HttpStub::Server::Session::Registry).to receive(:new).with(anything, anything, memory_session)
|
59
|
+
|
60
|
+
memory
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#scenarios" do
|
64
|
+
|
65
|
+
subject { memory.scenarios }
|
66
|
+
|
67
|
+
it "returns the servers scenario registry" do
|
68
|
+
expect(subject).to eql(scenario_registry)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#sessions" do
|
74
|
+
|
75
|
+
subject { memory.sessions }
|
76
|
+
|
77
|
+
it "returns the servers session registry" do
|
78
|
+
expect(subject).to eql(session_registry)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#stubs" do
|
84
|
+
|
85
|
+
let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
86
|
+
|
87
|
+
subject { memory.stubs }
|
88
|
+
|
89
|
+
before(:example) { allow(memory_session).to receive(:stubs).and_return(stubs) }
|
90
|
+
|
91
|
+
it "returns the stubs within the memory session" do
|
92
|
+
expect(subject).to eql(stubs)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#reset" do
|
98
|
+
|
99
|
+
let(:logger) { instance_double(Logger) }
|
100
|
+
|
101
|
+
subject { memory.reset(logger) }
|
102
|
+
|
103
|
+
before(:example) do
|
104
|
+
allow(scenario_registry).to receive(:clear)
|
105
|
+
allow(session_registry).to receive(:clear)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "clears the servers scenarios" do
|
109
|
+
expect(scenario_registry).to receive(:clear).with(logger)
|
110
|
+
|
111
|
+
subject
|
112
|
+
end
|
113
|
+
|
114
|
+
it "clears the servers sessions" do
|
115
|
+
expect(session_registry).to receive(:clear).with(logger)
|
116
|
+
|
117
|
+
subject
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -1,17 +1,65 @@
|
|
1
1
|
describe HttpStub::Server::Registry do
|
2
2
|
|
3
|
-
let(:
|
3
|
+
let(:model_name) { "a_model" }
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:logger) { instance_double(Logger, info: nil) }
|
6
6
|
|
7
|
-
|
7
|
+
let(:registry) { described_class.new(model_name) }
|
8
|
+
|
9
|
+
shared_context "multiple models" do
|
8
10
|
|
9
|
-
let(:models) { (1..3).map { |i| double("HttpStub::Server::Model#{i}",
|
11
|
+
let(:models) { (1..3).map { |i| double("HttpStub::Server::Model#{i}", matches?: false) } }
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_context "register multiple models" do
|
16
|
+
include_context "multiple models"
|
10
17
|
|
11
18
|
before(:example) { registry.concat(models, logger) }
|
12
19
|
|
13
20
|
end
|
14
21
|
|
22
|
+
shared_context "one model matches" do
|
23
|
+
|
24
|
+
let(:matching_model) { models[1] }
|
25
|
+
|
26
|
+
before(:example) { allow(matching_model).to receive(:matches?).and_return(true) }
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
shared_context "many models match" do
|
31
|
+
|
32
|
+
let(:matching_models) { [ models[0], models[2] ] }
|
33
|
+
|
34
|
+
before(:example) { matching_models.each { |model| allow(model).to receive(:matches?).and_return(true) } }
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "constructor" do
|
39
|
+
|
40
|
+
context "when models are provided" do
|
41
|
+
include_context "multiple models"
|
42
|
+
|
43
|
+
subject { described_class.new(model_name, models) }
|
44
|
+
|
45
|
+
it "creates a registry with the models" do
|
46
|
+
expect(subject.all).to eql(models)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when models are not provided" do
|
52
|
+
|
53
|
+
subject { described_class.new(model_name) }
|
54
|
+
|
55
|
+
it "creates a registy with no models" do
|
56
|
+
expect(subject.all).to eql([])
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
15
63
|
describe "#add" do
|
16
64
|
|
17
65
|
let(:model_string_representation) { "some model string" }
|
@@ -46,18 +94,69 @@ describe HttpStub::Server::Registry do
|
|
46
94
|
|
47
95
|
subject { registry.concat(models, logger) }
|
48
96
|
|
97
|
+
it "adds the models" do
|
98
|
+
subject
|
99
|
+
|
100
|
+
expect_registry_to_contain(models)
|
101
|
+
end
|
102
|
+
|
49
103
|
it "logs that the models have been registered" do
|
50
104
|
model_string_representations.each do |string_representation|
|
51
|
-
expect(logger).to receive(:info).with(
|
105
|
+
expect(logger).to receive(:info).with(/Registered.+#{string_representation}/)
|
52
106
|
end
|
53
107
|
|
54
108
|
subject
|
55
109
|
end
|
56
110
|
|
57
|
-
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#replace" do
|
114
|
+
|
115
|
+
let(:model_string_representations) { (1..3).map { |i| "model string ##{i}" } }
|
116
|
+
let(:models) do
|
117
|
+
model_string_representations.map do |string_representation|
|
118
|
+
double("HttpStub::Server::Model", to_s: string_representation)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
subject { registry.replace(models, logger) }
|
123
|
+
|
124
|
+
context "when no models had been added" do
|
125
|
+
|
126
|
+
it "establishes the models" do
|
127
|
+
subject
|
128
|
+
|
129
|
+
expect_registry_to_contain(models)
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
context "when models had been added" do
|
135
|
+
|
136
|
+
let(:original_models) { (1..3).map { double("HttpStub::Server::Model") } }
|
137
|
+
|
138
|
+
before(:example) { registry.concat(original_models, logger) }
|
139
|
+
|
140
|
+
it "replaces those models with the provided models" do
|
141
|
+
subject
|
142
|
+
|
143
|
+
expect_registry_to_contain(models)
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
it "logs that the models are being cleared" do
|
149
|
+
expect(logger).to receive(:info).with(/clearing a_model/i)
|
150
|
+
|
58
151
|
subject
|
152
|
+
end
|
153
|
+
|
154
|
+
it "logs that the models have been registered" do
|
155
|
+
model_string_representations.each do |string_representation|
|
156
|
+
expect(logger).to receive(:info).with(/Registered.+#{string_representation}/)
|
157
|
+
end
|
59
158
|
|
60
|
-
|
159
|
+
subject
|
61
160
|
end
|
62
161
|
|
63
162
|
end
|
@@ -78,10 +177,7 @@ describe HttpStub::Server::Registry do
|
|
78
177
|
end
|
79
178
|
|
80
179
|
describe "and one registered model matches the criteria" do
|
81
|
-
|
82
|
-
let(:matching_model) { models[1] }
|
83
|
-
|
84
|
-
before(:example) { allow(matching_model).to receive(:matches?).and_return(true) }
|
180
|
+
include_context "one model matches"
|
85
181
|
|
86
182
|
it "returns the model" do
|
87
183
|
expect(subject).to eql(matching_model)
|
@@ -100,11 +196,10 @@ describe HttpStub::Server::Registry do
|
|
100
196
|
end
|
101
197
|
|
102
198
|
describe "and multiple registered models satisfy the criteria" do
|
103
|
-
|
104
|
-
before(:example) { [0, 2].each { |i| allow(models[i]).to receive(:matches?).and_return(true) } }
|
199
|
+
include_context "many models match"
|
105
200
|
|
106
201
|
it "supports model overrides by returning the last model registered" do
|
107
|
-
expect(subject).to eql(
|
202
|
+
expect(subject).to eql(matching_models.last)
|
108
203
|
end
|
109
204
|
|
110
205
|
end
|
@@ -127,7 +222,7 @@ describe HttpStub::Server::Registry do
|
|
127
222
|
|
128
223
|
end
|
129
224
|
|
130
|
-
it "
|
225
|
+
it "logs model discovery diagnostics that include the complete details of the criteria" do
|
131
226
|
expect(logger).to receive(:info).with(/Criteria inspect result/)
|
132
227
|
|
133
228
|
subject
|
@@ -166,7 +261,7 @@ describe HttpStub::Server::Registry do
|
|
166
261
|
include_context "register multiple models"
|
167
262
|
|
168
263
|
it "returns the registered models in the order they were added" do
|
169
|
-
|
264
|
+
expect_registry_to_contain(models)
|
170
265
|
end
|
171
266
|
|
172
267
|
end
|
@@ -174,58 +269,78 @@ describe HttpStub::Server::Registry do
|
|
174
269
|
context "when no model has been registered" do
|
175
270
|
|
176
271
|
it "returns an empty list" do
|
177
|
-
|
272
|
+
expect_registry_to_contain([])
|
178
273
|
end
|
179
274
|
|
180
275
|
end
|
181
276
|
|
182
277
|
end
|
183
278
|
|
184
|
-
describe "#
|
279
|
+
describe "#delete" do
|
185
280
|
|
186
|
-
|
281
|
+
let(:criteria) { double("Criteria", inspect: "Criteria inspect result") }
|
187
282
|
|
188
|
-
|
283
|
+
subject { registry.delete(criteria, logger) }
|
284
|
+
|
285
|
+
context "when multiple models have been registered" do
|
189
286
|
include_context "register multiple models"
|
190
287
|
|
191
|
-
|
288
|
+
it "determines if the models satisfy the provided criteria" do
|
289
|
+
models.each { |model| expect(model).to receive(:matches?).with(criteria, logger).and_return(false) }
|
192
290
|
|
193
|
-
|
291
|
+
subject
|
292
|
+
end
|
293
|
+
|
294
|
+
context "when the criteria matches a model" do
|
295
|
+
include_context "one model matches"
|
194
296
|
|
195
|
-
it "the
|
297
|
+
it "deletes the matched model from the registry" do
|
196
298
|
subject
|
197
299
|
|
198
|
-
|
300
|
+
expect_registry_to_contain(models - [ matching_model ])
|
199
301
|
end
|
200
302
|
|
201
303
|
end
|
202
304
|
|
203
|
-
context "
|
305
|
+
context "when the criteria matches many models" do
|
306
|
+
include_context "many models match"
|
307
|
+
|
308
|
+
it "deletes all matching models" do
|
309
|
+
subject
|
204
310
|
|
205
|
-
|
311
|
+
expect_registry_to_contain(models - matching_models)
|
312
|
+
end
|
206
313
|
|
207
|
-
|
314
|
+
end
|
315
|
+
|
316
|
+
context "when the criteria does not match any model" do
|
317
|
+
|
318
|
+
it "does not delete any models" do
|
208
319
|
subject
|
209
320
|
|
210
|
-
|
321
|
+
expect_registry_to_contain(models)
|
211
322
|
end
|
212
323
|
|
213
324
|
end
|
214
325
|
|
215
326
|
end
|
216
327
|
|
217
|
-
context "when no
|
218
|
-
|
219
|
-
let(:model) { double("HttpStub::Server::Model") }
|
328
|
+
context "when no model has been registered" do
|
220
329
|
|
221
|
-
it "does not
|
330
|
+
it "does not delete any models" do
|
222
331
|
subject
|
223
332
|
|
224
|
-
|
333
|
+
expect_registry_to_contain([])
|
225
334
|
end
|
226
335
|
|
227
336
|
end
|
228
337
|
|
338
|
+
it "logs model deletion diagnostics that include the complete details of the criteria" do
|
339
|
+
expect(logger).to receive(:info).with(/Criteria inspect result/)
|
340
|
+
|
341
|
+
subject
|
342
|
+
end
|
343
|
+
|
229
344
|
end
|
230
345
|
|
231
346
|
describe "#clear" do
|
@@ -244,11 +359,15 @@ describe HttpStub::Server::Registry do
|
|
244
359
|
it "releases all knowledge of the models" do
|
245
360
|
subject
|
246
361
|
|
247
|
-
|
362
|
+
expect_registry_to_contain([])
|
248
363
|
end
|
249
364
|
|
250
365
|
end
|
251
366
|
|
252
367
|
end
|
253
368
|
|
369
|
+
def expect_registry_to_contain(models)
|
370
|
+
expect(registry.all).to eql(models.reverse)
|
371
|
+
end
|
372
|
+
|
254
373
|
end
|