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,444 @@
|
|
1
|
+
describe HttpStub::Server::Session::Session do
|
2
|
+
|
3
|
+
let(:id) { "Some session id" }
|
4
|
+
let(:scenario_registry) { instance_double(HttpStub::Server::Registry) }
|
5
|
+
let(:memory_session) { instance_double(HttpStub::Server::Session::Session) }
|
6
|
+
|
7
|
+
let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry) }
|
8
|
+
let(:stub_match_registry) { instance_double(HttpStub::Server::Registry) }
|
9
|
+
let(:stub_miss_registry) { instance_double(HttpStub::Server::Registry) }
|
10
|
+
|
11
|
+
let(:logger) { instance_double(Logger) }
|
12
|
+
|
13
|
+
let(:session) { described_class.new(id, scenario_registry, memory_session) }
|
14
|
+
|
15
|
+
before(:example) do
|
16
|
+
allow(HttpStub::Server::Stub::Registry).to receive(:new).and_return(stub_registry)
|
17
|
+
allow(HttpStub::Server::Registry).to receive(:new).with("stub match").and_return(stub_match_registry)
|
18
|
+
allow(HttpStub::Server::Registry).to receive(:new).with("stub miss").and_return(stub_miss_registry)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "uses a stub registry that is initialized with the provided memory session" do
|
22
|
+
expect(HttpStub::Server::Stub::Registry).to receive(:new).with(memory_session)
|
23
|
+
|
24
|
+
session
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#id" do
|
28
|
+
|
29
|
+
it "returns the provided id" do
|
30
|
+
expect(session.id).to eql(id)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#matches?" do
|
36
|
+
|
37
|
+
subject { session.matches?(provided_id, logger) }
|
38
|
+
|
39
|
+
context "when the provided id is equal to the session id" do
|
40
|
+
|
41
|
+
let(:provided_id) { id }
|
42
|
+
|
43
|
+
it "returns true" do
|
44
|
+
expect(subject).to be(true)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when the provided id is not equal to the session id" do
|
50
|
+
|
51
|
+
let(:provided_id) { "Another session id" }
|
52
|
+
|
53
|
+
it "returns false" do
|
54
|
+
expect(subject).to be(false)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "activate_scenario!" do
|
62
|
+
|
63
|
+
let(:scenario_name) { "Some scenario name" }
|
64
|
+
let(:scenario) { nil }
|
65
|
+
|
66
|
+
subject { session.activate_scenario!(scenario_name, logger) }
|
67
|
+
|
68
|
+
before(:example) { allow(scenario_registry).to receive(:find).with(scenario_name, anything).and_return(scenario) }
|
69
|
+
|
70
|
+
it "attempts to retrieve the scenario with the provided name from the scenario registry" do
|
71
|
+
expect(scenario_registry).to receive(:find).with(scenario_name, logger)
|
72
|
+
|
73
|
+
subject rescue nil
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when the scenario is found" do
|
77
|
+
|
78
|
+
let(:scenario_trigger_names) { (1..3).map { |i| "scenario trigger #{i}" } }
|
79
|
+
let(:scenario_triggers) do
|
80
|
+
scenario_trigger_names.map { |name| instance_double(HttpStub::Server::Scenario::Trigger, name: name) }
|
81
|
+
end
|
82
|
+
let(:triggered_scenarios) do
|
83
|
+
(1..3).map { instance_double(HttpStub::Server::Scenario::Scenario, triggered_scenarios: [], stubs: []) }
|
84
|
+
end
|
85
|
+
let(:scenario_stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
86
|
+
let(:scenario) do
|
87
|
+
instance_double(HttpStub::Server::Scenario::Scenario, triggered_scenarios: scenario_triggers,
|
88
|
+
stubs: scenario_stubs)
|
89
|
+
end
|
90
|
+
|
91
|
+
before(:example) do
|
92
|
+
scenario_trigger_names.zip(triggered_scenarios).each do |scenario_trigger_name, triggered_scenario|
|
93
|
+
allow(scenario_registry).to(
|
94
|
+
receive(:find).with(scenario_trigger_name, anything).and_return(triggered_scenario)
|
95
|
+
)
|
96
|
+
end
|
97
|
+
allow(stub_registry).to receive(:concat)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "triggers activation of the scenario triggers of the scenario" do
|
101
|
+
scenario_trigger_names.zip(triggered_scenarios).each do |scenario_trigger_name, triggered_scenario|
|
102
|
+
expect(scenario_registry).to receive(:find).with(scenario_trigger_name, logger).and_return(triggered_scenario)
|
103
|
+
end
|
104
|
+
|
105
|
+
subject
|
106
|
+
end
|
107
|
+
|
108
|
+
it "adds the scenarios stubs to the stub registry" do
|
109
|
+
expect(stub_registry).to receive(:concat).with(scenario_stubs, logger)
|
110
|
+
|
111
|
+
subject
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
context "when the scenario is not found" do
|
117
|
+
|
118
|
+
let(:scenario) { nil }
|
119
|
+
|
120
|
+
it "raises a scenario not found error with the provided name" do
|
121
|
+
expect { subject }.to raise_error(HttpStub::Server::Scenario::NotFoundError, /#{scenario_name}/)
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#add_stub" do
|
129
|
+
|
130
|
+
let(:the_stub) { instance_double(HttpStub::Server::Stub::Stub) }
|
131
|
+
|
132
|
+
subject { session.add_stub(the_stub, logger) }
|
133
|
+
|
134
|
+
it "adds the provided stub to the stub regsitry" do
|
135
|
+
expect(stub_registry).to receive(:add).with(the_stub, logger)
|
136
|
+
|
137
|
+
subject
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#find_stub" do
|
143
|
+
|
144
|
+
let(:id) { SecureRandom.uuid }
|
145
|
+
let(:the_stub) { instance_double(HttpStub::Server::Stub::Stub) }
|
146
|
+
|
147
|
+
subject { session.find_stub(id, logger) }
|
148
|
+
|
149
|
+
before(:example) { allow(stub_registry).to receive(:find).and_return(the_stub) }
|
150
|
+
|
151
|
+
it "finds the stub with the provided id in the stub regsitry" do
|
152
|
+
expect(stub_registry).to receive(:find).with(id, logger)
|
153
|
+
|
154
|
+
subject
|
155
|
+
end
|
156
|
+
|
157
|
+
it "returns any found stub in the stub regsitry" do
|
158
|
+
expect(subject).to eql(the_stub)
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "#stubs" do
|
164
|
+
|
165
|
+
let(:the_stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
166
|
+
|
167
|
+
subject { session.stubs }
|
168
|
+
|
169
|
+
before(:example) { allow(stub_registry).to receive(:all).and_return(the_stubs) }
|
170
|
+
|
171
|
+
it "finds all stubs in the stub regsitry" do
|
172
|
+
expect(stub_registry).to receive(:all)
|
173
|
+
|
174
|
+
subject
|
175
|
+
end
|
176
|
+
|
177
|
+
it "returns the stubs in the stub regsitry" do
|
178
|
+
expect(subject).to eql(the_stubs)
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "#match" do
|
184
|
+
|
185
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request) }
|
186
|
+
|
187
|
+
let(:matched_stub) { instance_double(HttpStub::Server::Stub::Stub) }
|
188
|
+
|
189
|
+
subject { session.match(request, logger) }
|
190
|
+
|
191
|
+
before(:example) { allow(stub_registry).to receive(:match).and_return(matched_stub) }
|
192
|
+
|
193
|
+
it "delegates to the stub registry to match the request with a stub" do
|
194
|
+
expect(stub_registry).to receive(:match).with(request, logger)
|
195
|
+
|
196
|
+
subject
|
197
|
+
end
|
198
|
+
|
199
|
+
it "returns any matched stub" do
|
200
|
+
expect(subject).to eql(matched_stub)
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
describe "#add_match" do
|
206
|
+
|
207
|
+
let(:triggered_scenario_names) { [] }
|
208
|
+
let(:triggered_stubs) { [] }
|
209
|
+
let(:match_stub_triggers) do
|
210
|
+
instance_double(HttpStub::Server::Stub::Triggers, scenario_names: triggered_scenario_names,
|
211
|
+
stubs: triggered_stubs)
|
212
|
+
end
|
213
|
+
let(:match_stub) do
|
214
|
+
instance_double(HttpStub::Server::Stub::Stub, triggers: match_stub_triggers)
|
215
|
+
end
|
216
|
+
let(:match) { instance_double(HttpStub::Server::Stub::Match::Match, stub: match_stub) }
|
217
|
+
|
218
|
+
subject { session.add_match(match, logger) }
|
219
|
+
|
220
|
+
before(:example) do
|
221
|
+
allow(stub_match_registry).to receive(:add)
|
222
|
+
end
|
223
|
+
|
224
|
+
it "adds the match to the match registry" do
|
225
|
+
expect(stub_match_registry).to receive(:add).with(match, logger)
|
226
|
+
|
227
|
+
subject
|
228
|
+
end
|
229
|
+
|
230
|
+
context "when scenarios are to be triggered by the stub" do
|
231
|
+
|
232
|
+
let(:triggered_scenario_names) { (1..3).map { |i| "triggered scenario #{i}" } }
|
233
|
+
|
234
|
+
it "activates the scenarios in the session" do
|
235
|
+
triggered_scenario_names.each do |scenario_name|
|
236
|
+
expect(session).to receive(:activate_scenario!).with(scenario_name, logger)
|
237
|
+
end
|
238
|
+
|
239
|
+
subject
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
context "when no scenarios are to be triggered by the stub" do
|
245
|
+
|
246
|
+
let(:triggered_scenario_names) { [] }
|
247
|
+
|
248
|
+
it "does not activate any scenarios in the session" do
|
249
|
+
expect(session).to_not receive(:activate_scenario!)
|
250
|
+
|
251
|
+
subject
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
context "when stubs are to be triggered by the stub" do
|
257
|
+
|
258
|
+
let(:triggered_stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
259
|
+
|
260
|
+
it "adds the stubs to the session" do
|
261
|
+
triggered_stubs.each { |triggered_stub| expect(session).to receive(:add_stub).with(triggered_stub, logger) }
|
262
|
+
|
263
|
+
subject
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
|
268
|
+
context "when no stubs are to be triggered by the stub" do
|
269
|
+
|
270
|
+
let(:triggered_stubs) { [] }
|
271
|
+
|
272
|
+
it "does not add any stubs to the session" do
|
273
|
+
expect(session).to_not receive(:add_stub)
|
274
|
+
|
275
|
+
subject
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
describe "#matches" do
|
283
|
+
|
284
|
+
let(:stub_matches) { (1..3).map { instance_double(HttpStub::Server::Stub::Match::Match) } }
|
285
|
+
|
286
|
+
subject { session.matches }
|
287
|
+
|
288
|
+
before(:example) { allow(stub_match_registry).to receive(:all).and_return(stub_matches) }
|
289
|
+
|
290
|
+
it "retrieves all the matches in the stub match registry" do
|
291
|
+
expect(stub_match_registry).to receive(:all)
|
292
|
+
|
293
|
+
subject
|
294
|
+
end
|
295
|
+
|
296
|
+
it "returns any matches" do
|
297
|
+
expect(subject).to eql(stub_matches)
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
describe "#last_match" do
|
303
|
+
|
304
|
+
let(:match_args) { { uri: "some uri", method: "some method" } }
|
305
|
+
|
306
|
+
let(:stub_match) { instance_double(HttpStub::Server::Stub::Match::Match) }
|
307
|
+
|
308
|
+
subject { session.last_match(match_args, logger) }
|
309
|
+
|
310
|
+
before(:example) { allow(stub_match_registry).to receive(:find).and_return(stub_match) }
|
311
|
+
|
312
|
+
it "retrieves the match for the provided URI and method via the stub match registry" do
|
313
|
+
expect(stub_match_registry).to receive(:find).with(match_args, logger)
|
314
|
+
|
315
|
+
subject
|
316
|
+
end
|
317
|
+
|
318
|
+
it "returns any match" do
|
319
|
+
expect(subject).to eql(stub_match)
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
describe "#add_miss" do
|
325
|
+
|
326
|
+
let(:stub_miss) { instance_double(HttpStub::Server::Stub::Match::Miss) }
|
327
|
+
|
328
|
+
subject { session.add_miss(stub_miss, logger) }
|
329
|
+
|
330
|
+
it "adds the miss to the stub miss registry" do
|
331
|
+
expect(stub_miss_registry).to receive(:add).with(stub_miss, logger)
|
332
|
+
|
333
|
+
subject
|
334
|
+
end
|
335
|
+
|
336
|
+
end
|
337
|
+
|
338
|
+
describe "#misses" do
|
339
|
+
|
340
|
+
let(:stub_misses) { (1..3).map { instance_double(HttpStub::Server::Stub::Match::Miss) } }
|
341
|
+
|
342
|
+
subject { session.misses }
|
343
|
+
|
344
|
+
before(:example) { allow(stub_miss_registry).to receive(:all).and_return(stub_misses) }
|
345
|
+
|
346
|
+
it "retrieves all the misses in the stub miss registry" do
|
347
|
+
expect(stub_miss_registry).to receive(:all)
|
348
|
+
|
349
|
+
subject
|
350
|
+
end
|
351
|
+
|
352
|
+
it "returns any misses" do
|
353
|
+
expect(subject).to eql(stub_misses)
|
354
|
+
end
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
describe "#reset" do
|
359
|
+
|
360
|
+
subject { session.reset(logger) }
|
361
|
+
|
362
|
+
before(:example) do
|
363
|
+
allow(stub_registry).to receive(:reset)
|
364
|
+
allow(stub_match_registry).to receive(:clear)
|
365
|
+
allow(stub_miss_registry).to receive(:clear)
|
366
|
+
end
|
367
|
+
|
368
|
+
it "resets the stub registry to revert it to its original state" do
|
369
|
+
expect(stub_registry).to receive(:reset).with(logger)
|
370
|
+
|
371
|
+
subject
|
372
|
+
end
|
373
|
+
|
374
|
+
it "clears the stub miss registry to revert it to its original state" do
|
375
|
+
expect(stub_miss_registry).to receive(:clear).with(logger)
|
376
|
+
|
377
|
+
subject
|
378
|
+
end
|
379
|
+
|
380
|
+
it "clears the stub match registry to revert it to its original state" do
|
381
|
+
expect(stub_match_registry).to receive(:clear).with(logger)
|
382
|
+
|
383
|
+
subject
|
384
|
+
end
|
385
|
+
|
386
|
+
it "clears stub misses before the resetting stubs" do
|
387
|
+
expect(stub_miss_registry).to receive(:clear).ordered
|
388
|
+
expect(stub_registry).to receive(:reset).ordered
|
389
|
+
|
390
|
+
subject
|
391
|
+
end
|
392
|
+
|
393
|
+
it "clears stub matches before the resetting stubs" do
|
394
|
+
expect(stub_match_registry).to receive(:clear).ordered
|
395
|
+
expect(stub_registry).to receive(:reset).ordered
|
396
|
+
|
397
|
+
subject
|
398
|
+
end
|
399
|
+
|
400
|
+
end
|
401
|
+
|
402
|
+
describe "#clear" do
|
403
|
+
|
404
|
+
subject { session.clear(logger) }
|
405
|
+
|
406
|
+
before(:example) do
|
407
|
+
[ stub_registry, stub_match_registry, stub_miss_registry ].each { |registry| allow(registry).to receive(:clear) }
|
408
|
+
end
|
409
|
+
|
410
|
+
it "clears the stub registry" do
|
411
|
+
expect(stub_registry).to receive(:clear).with(logger)
|
412
|
+
|
413
|
+
subject
|
414
|
+
end
|
415
|
+
|
416
|
+
it "clears the stub miss registry" do
|
417
|
+
expect(stub_miss_registry).to receive(:clear).with(logger)
|
418
|
+
|
419
|
+
subject
|
420
|
+
end
|
421
|
+
|
422
|
+
it "clears the stub match registry" do
|
423
|
+
expect(stub_match_registry).to receive(:clear).with(logger)
|
424
|
+
|
425
|
+
subject
|
426
|
+
end
|
427
|
+
|
428
|
+
it "clears stub misses before the stubs" do
|
429
|
+
expect(stub_miss_registry).to receive(:clear).ordered
|
430
|
+
expect(stub_registry).to receive(:clear).ordered
|
431
|
+
|
432
|
+
subject
|
433
|
+
end
|
434
|
+
|
435
|
+
it "clears stub matches before the stubs" do
|
436
|
+
expect(stub_match_registry).to receive(:clear).ordered
|
437
|
+
expect(stub_registry).to receive(:clear).ordered
|
438
|
+
|
439
|
+
subject
|
440
|
+
end
|
441
|
+
|
442
|
+
end
|
443
|
+
|
444
|
+
end
|
@@ -1,26 +1,27 @@
|
|
1
1
|
describe HttpStub::Server::Stub::Controller do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
|
7
|
-
let(:the_stub) { instance_double(HttpStub::Server::Stub::Stub, uri: stub_uri) }
|
8
|
-
|
9
|
-
let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
|
10
|
-
let(:match_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
|
11
|
-
let(:miss_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
|
12
|
-
|
13
|
-
let(:controller) { HttpStub::Server::Stub::Controller.new(stub_registry, match_registry, miss_registry) }
|
14
|
-
|
15
|
-
before(:example) do
|
16
|
-
allow(HttpStub::Server::Stub::Parser).to receive(:parse).and_return(payload)
|
17
|
-
allow(HttpStub::Server::Stub).to receive(:create).and_return(the_stub)
|
3
|
+
let(:request_parameters) { {} }
|
4
|
+
let(:session) { instance_double(HttpStub::Server::Session::Session) }
|
5
|
+
let(:request) do
|
6
|
+
instance_double(HttpStub::Server::Request::Request, parameters: request_parameters, session: session)
|
18
7
|
end
|
8
|
+
let(:logger) { instance_double(Logger) }
|
9
|
+
let(:payload) { HttpStub::StubFixture.new.server_payload }
|
10
|
+
let(:stub_uri) { "/some/stub/uri" }
|
11
|
+
let(:the_stub) { instance_double(HttpStub::Server::Stub::Stub, uri: stub_uri) }
|
12
|
+
|
13
|
+
let(:controller) { described_class.new }
|
19
14
|
|
20
15
|
describe "#register" do
|
21
16
|
|
22
17
|
subject { controller.register(request, logger) }
|
23
18
|
|
19
|
+
before(:example) do
|
20
|
+
allow(HttpStub::Server::Stub::Parser).to receive(:parse).and_return(payload)
|
21
|
+
allow(HttpStub::Server::Stub).to receive(:create).and_return(the_stub)
|
22
|
+
allow(session).to receive(:add_stub)
|
23
|
+
end
|
24
|
+
|
24
25
|
it "parses the payload from the request" do
|
25
26
|
expect(HttpStub::Server::Stub::Parser).to receive(:parse).with(request).and_return(payload)
|
26
27
|
|
@@ -33,8 +34,8 @@ describe HttpStub::Server::Stub::Controller do
|
|
33
34
|
subject
|
34
35
|
end
|
35
36
|
|
36
|
-
it "adds the stub to the
|
37
|
-
expect(
|
37
|
+
it "adds the stub to the users session" do
|
38
|
+
expect(session).to receive(:add_stub).with(the_stub, logger)
|
38
39
|
|
39
40
|
subject
|
40
41
|
end
|
@@ -56,20 +57,30 @@ describe HttpStub::Server::Stub::Controller do
|
|
56
57
|
|
57
58
|
describe "#match" do
|
58
59
|
|
60
|
+
let(:matched_stub) { nil }
|
61
|
+
|
59
62
|
let(:calculated_stub_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
60
63
|
|
61
64
|
subject { controller.match(request, logger) }
|
62
65
|
|
63
66
|
before(:example) do
|
64
|
-
allow(
|
67
|
+
allow(session).to receive(:match).and_return(matched_stub)
|
65
68
|
allow(the_stub).to receive(:response_for).and_return(calculated_stub_response)
|
66
69
|
end
|
67
70
|
|
68
|
-
|
71
|
+
it "evaluates the matching stub for the user" do
|
72
|
+
allow(session).to receive(:add_match)
|
73
|
+
allow(session).to receive(:add_miss)
|
74
|
+
expect(session).to receive(:match).with(request, logger)
|
75
|
+
|
76
|
+
subject
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "when a stub matches the request" do
|
69
80
|
|
70
81
|
let(:matched_stub) { the_stub }
|
71
82
|
|
72
|
-
before(:example) { allow(
|
83
|
+
before(:example) { allow(session).to receive(:add_match) }
|
73
84
|
|
74
85
|
it "calculates the stubs response based on the request" do
|
75
86
|
expect(the_stub).to receive(:response_for).with(request)
|
@@ -83,16 +94,16 @@ describe HttpStub::Server::Stub::Controller do
|
|
83
94
|
subject
|
84
95
|
end
|
85
96
|
|
86
|
-
it "adds the match to the
|
97
|
+
it "adds the match to the users session" do
|
87
98
|
match = instance_double(HttpStub::Server::Stub::Match::Match)
|
88
99
|
allow(HttpStub::Server::Stub::Match::Match).to receive(:new).and_return(match)
|
89
|
-
expect(
|
100
|
+
expect(session).to receive(:add_match).with(match, logger)
|
90
101
|
|
91
102
|
subject
|
92
103
|
end
|
93
104
|
|
94
|
-
it "does not add to the
|
95
|
-
expect(
|
105
|
+
it "does not add to the users session" do
|
106
|
+
expect(session).to_not receive(:add_miss)
|
96
107
|
|
97
108
|
subject
|
98
109
|
end
|
@@ -107,7 +118,7 @@ describe HttpStub::Server::Stub::Controller do
|
|
107
118
|
|
108
119
|
let(:matched_stub) { nil }
|
109
120
|
|
110
|
-
before(:example) { allow(
|
121
|
+
before(:example) { allow(session).to receive(:add_miss) }
|
111
122
|
|
112
123
|
it "returns a not found response" do
|
113
124
|
expect(subject).to eql(HttpStub::Server::Response::NOT_FOUND)
|
@@ -119,16 +130,16 @@ describe HttpStub::Server::Stub::Controller do
|
|
119
130
|
subject
|
120
131
|
end
|
121
132
|
|
122
|
-
it "adds the miss to the
|
133
|
+
it "adds the miss to the users session" do
|
123
134
|
miss = instance_double(HttpStub::Server::Stub::Match::Miss)
|
124
135
|
allow(HttpStub::Server::Stub::Match::Miss).to receive(:new).and_return(miss)
|
125
|
-
expect(
|
136
|
+
expect(session).to receive(:add_miss).with(miss, logger)
|
126
137
|
|
127
138
|
subject
|
128
139
|
end
|
129
140
|
|
130
|
-
it "does not add to the match
|
131
|
-
expect(
|
141
|
+
it "does not add to the match to the users session" do
|
142
|
+
expect(session).to_not receive(:add_match)
|
132
143
|
|
133
144
|
subject
|
134
145
|
end
|
@@ -137,24 +148,65 @@ describe HttpStub::Server::Stub::Controller do
|
|
137
148
|
|
138
149
|
end
|
139
150
|
|
140
|
-
describe "#
|
151
|
+
describe "#find" do
|
152
|
+
|
153
|
+
let(:id) { SecureRandom.uuid }
|
154
|
+
let(:request_parameters) { { stub_id: id } }
|
155
|
+
|
156
|
+
subject { controller.find(request, logger) }
|
157
|
+
|
158
|
+
before(:example) { allow(session).to receive(:find_stub).and_return(the_stub) }
|
159
|
+
|
160
|
+
it "finds the stub with the parameterized id in the user session" do
|
161
|
+
expect(session).to receive(:find_stub).with(id, logger)
|
162
|
+
|
163
|
+
subject
|
164
|
+
end
|
165
|
+
|
166
|
+
it "returns the found stub" do
|
167
|
+
expect(subject).to eql(the_stub)
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
141
171
|
|
142
|
-
|
172
|
+
describe "#find_all" do
|
143
173
|
|
144
|
-
|
145
|
-
|
174
|
+
let(:stubs) { (1..3).map { instance_double(HttpStub::Server::Stub::Stub) } }
|
175
|
+
|
176
|
+
subject { controller.find_all(request) }
|
177
|
+
|
178
|
+
before(:example) { allow(session).to receive(:stubs).and_return(stubs) }
|
179
|
+
|
180
|
+
it "retrieves all stubs from the users session" do
|
181
|
+
expect(session).to receive(:stubs)
|
146
182
|
|
147
183
|
subject
|
148
184
|
end
|
149
185
|
|
150
|
-
it "
|
151
|
-
expect(
|
186
|
+
it "returns the stubs" do
|
187
|
+
expect(subject).to eql(stubs)
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "#reset" do
|
193
|
+
|
194
|
+
subject { controller.reset(request, logger) }
|
195
|
+
|
196
|
+
it "resets the users session" do
|
197
|
+
expect(session).to receive(:reset).with(logger)
|
152
198
|
|
153
199
|
subject
|
154
200
|
end
|
155
201
|
|
156
|
-
|
157
|
-
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "#clear" do
|
205
|
+
|
206
|
+
subject { controller.clear(request, logger) }
|
207
|
+
|
208
|
+
it "clears the users session" do
|
209
|
+
expect(session).to receive(:clear).with(logger)
|
158
210
|
|
159
211
|
subject
|
160
212
|
end
|