http_stub 0.19.1 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/lib/http_stub.rb +26 -21
- data/lib/http_stub/configurer/server/command_processor.rb +1 -0
- data/lib/http_stub/server/application.rb +24 -46
- data/lib/http_stub/server/formatted_hash.rb +18 -0
- data/lib/http_stub/server/header_parser.rb +17 -0
- data/lib/http_stub/server/registry.rb +9 -9
- data/lib/http_stub/server/request.rb +19 -0
- data/lib/http_stub/server/request_pipeline.rb +27 -0
- data/lib/http_stub/server/response.rb +7 -3
- data/lib/http_stub/server/scenario.rb +1 -1
- data/lib/http_stub/server/scenario/activator.rb +4 -4
- data/lib/http_stub/server/scenario/controller.rb +8 -8
- data/lib/http_stub/server/scenario/{request_parser.rb → parser.rb} +2 -2
- data/lib/http_stub/server/scenario/{instance.rb → scenario.rb} +2 -2
- data/lib/http_stub/server/stub.rb +1 -1
- data/lib/http_stub/server/stub/controller.rb +8 -8
- data/lib/http_stub/server/stub/empty.rb +34 -0
- data/lib/http_stub/server/stub/match/exact_value_matcher.rb +17 -0
- data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +26 -0
- data/lib/http_stub/server/stub/match/match.rb +20 -0
- data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +23 -0
- data/lib/http_stub/server/stub/match/regexp_value_matcher.rb +18 -0
- data/lib/http_stub/server/stub/match/rule/body.rb +49 -0
- data/lib/http_stub/server/stub/match/rule/headers.rb +31 -0
- data/lib/http_stub/server/stub/match/rule/json_body.rb +39 -0
- data/lib/http_stub/server/stub/match/rule/method.rb +27 -0
- data/lib/http_stub/server/stub/match/rule/parameters.rb +27 -0
- data/lib/http_stub/server/stub/match/rule/simple_body.rb +27 -0
- data/lib/http_stub/server/stub/match/rule/uri.rb +27 -0
- data/lib/http_stub/server/stub/match/string_value_matcher.rb +33 -0
- data/lib/http_stub/server/stub/match/truthy_matcher.rb +25 -0
- data/lib/http_stub/server/stub/{request_parser.rb → parser.rb} +2 -2
- data/lib/http_stub/server/stub/payload_file_consolidator.rb +1 -1
- data/lib/http_stub/server/stub/registry.rb +16 -8
- data/lib/http_stub/server/stub/response/base.rb +2 -2
- data/lib/http_stub/server/stub/stub.rb +44 -0
- data/lib/http_stub/server/stub/triggers.rb +2 -2
- data/lib/http_stub/server/views/_match.haml +20 -0
- data/lib/http_stub/server/views/matches.haml +3 -0
- data/lib/http_stub/server/views/stub.haml +1 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/stub_control_values_spec.rb +6 -3
- data/spec/acceptance/stub_match_spec.rb +142 -0
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +4 -0
- data/spec/lib/http_stub/server/application_integration_spec.rb +17 -18
- data/spec/lib/http_stub/server/application_spec.rb +81 -53
- data/spec/lib/http_stub/server/formatted_hash_spec.rb +54 -0
- data/spec/lib/http_stub/server/{stub/request_header_parser_spec.rb → header_parser_spec.rb} +9 -9
- data/spec/lib/http_stub/server/{request_file_consolidator_spec.rb → payload_file_consolidator_spec.rb} +4 -4
- data/spec/lib/http_stub/server/registry_spec.rb +13 -14
- data/spec/lib/http_stub/server/request_pipeline_spec.rb +80 -0
- data/spec/lib/http_stub/server/request_spec.rb +113 -0
- data/spec/lib/http_stub/server/response_spec.rb +46 -12
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +18 -18
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +18 -15
- data/spec/lib/http_stub/server/scenario/{request_parser_spec.rb → parser_spec.rb} +8 -8
- data/spec/lib/http_stub/server/scenario/{instance_spec.rb → scenario_spec.rb} +7 -5
- data/spec/lib/http_stub/server/scenario_spec.rb +3 -3
- data/spec/lib/http_stub/server/stub/controller_spec.rb +29 -14
- data/spec/lib/http_stub/server/stub/empty_spec.rb +68 -0
- data/spec/lib/http_stub/server/stub/{exact_value_matcher_spec.rb → match/exact_value_matcher_spec.rb} +2 -2
- data/spec/lib/http_stub/server/stub/{hash_with_string_value_matchers_spec.rb → match/hash_with_string_value_matchers_spec.rb} +27 -19
- data/spec/lib/http_stub/server/stub/match/match_spec.rb +40 -0
- data/spec/lib/http_stub/server/stub/{omitted_value_matcher_spec.rb → match/omitted_value_matcher_spec.rb} +2 -2
- data/spec/lib/http_stub/server/stub/{regexp_value_matcher_spec.rb → match/regexp_value_matcher_spec.rb} +2 -2
- data/spec/lib/http_stub/server/stub/{request_body_spec.rb → match/rule/body_spec.rb} +12 -12
- data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +90 -0
- data/spec/lib/http_stub/server/stub/{json_request_body_spec.rb → match/rule/json_body_spec.rb} +9 -10
- data/spec/lib/http_stub/server/stub/{method_spec.rb → match/rule/method_spec.rb} +6 -5
- data/spec/lib/http_stub/server/stub/{request_parameters_spec.rb → match/rule/parameters_spec.rb} +16 -10
- data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +46 -0
- data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +46 -0
- data/spec/lib/http_stub/server/stub/{string_value_matcher_spec.rb → match/string_value_matcher_spec.rb} +30 -26
- data/spec/lib/http_stub/server/stub/match/truthy_matcher_spec.rb +24 -0
- data/spec/lib/http_stub/server/stub/{request_parser_spec.rb → parser_spec.rb} +7 -7
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +5 -5
- data/spec/lib/http_stub/server/stub/registry_spec.rb +114 -43
- data/spec/lib/http_stub/server/stub/response/base_spec.rb +8 -2
- data/spec/lib/http_stub/server/stub/stub_spec.rb +294 -0
- data/spec/lib/http_stub/server/stub/triggers_spec.rb +4 -4
- data/spec/lib/http_stub/server/stub_spec.rb +3 -3
- data/spec/spec_helper.rb +7 -3
- data/spec/support/configurer_integration.rb +1 -0
- data/spec/support/http_stub/empty_configurer.rb +7 -0
- data/spec/support/{scenario_fixture.rb → http_stub/scenario_fixture.rb} +0 -0
- data/spec/support/http_stub/server/request_fixture.rb +25 -0
- data/spec/support/http_stub/server/scenario/scenario_fixture.rb +15 -0
- data/spec/support/http_stub/server/stub/match/match_fixture.rb +17 -0
- data/spec/support/{stub_fixture.rb → http_stub/stub_fixture.rb} +0 -0
- data/spec/support/server_integration.rb +1 -0
- metadata +315 -290
- data/lib/http_stub/server/stub/exact_value_matcher.rb +0 -15
- data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +0 -22
- data/lib/http_stub/server/stub/headers.rb +0 -19
- data/lib/http_stub/server/stub/instance.rb +0 -32
- data/lib/http_stub/server/stub/json_request_body.rb +0 -35
- data/lib/http_stub/server/stub/method.rb +0 -23
- data/lib/http_stub/server/stub/omitted_value_matcher.rb +0 -21
- data/lib/http_stub/server/stub/regexp_value_matcher.rb +0 -16
- data/lib/http_stub/server/stub/request_body.rb +0 -44
- data/lib/http_stub/server/stub/request_header_parser.rb +0 -19
- data/lib/http_stub/server/stub/request_headers.rb +0 -28
- data/lib/http_stub/server/stub/request_parameters.rb +0 -23
- data/lib/http_stub/server/stub/simple_request_body.rb +0 -23
- data/lib/http_stub/server/stub/string_value_matcher.rb +0 -31
- data/lib/http_stub/server/stub/truthy_request_matcher.rb +0 -23
- data/lib/http_stub/server/stub/uri.rb +0 -23
- data/spec/lib/http_stub/server/stub/headers_spec.rb +0 -51
- data/spec/lib/http_stub/server/stub/instance_spec.rb +0 -235
- data/spec/lib/http_stub/server/stub/request_headers_spec.rb +0 -68
- data/spec/lib/http_stub/server/stub/simple_request_body_spec.rb +0 -43
- data/spec/lib/http_stub/server/stub/truthy_request_matcher_spec.rb +0 -23
- data/spec/lib/http_stub/server/stub/uri_spec.rb +0 -43
@@ -4,21 +4,25 @@ describe HttpStub::Server::Application do
|
|
4
4
|
let(:response) { last_response }
|
5
5
|
let(:response_body) { response.body.to_s }
|
6
6
|
|
7
|
+
let(:match_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
|
7
8
|
let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
|
8
9
|
let(:scenario_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
|
9
10
|
|
10
11
|
let(:stub_controller) { instance_double(HttpStub::Server::Stub::Controller).as_null_object }
|
11
12
|
let(:scenario_controller) { instance_double(HttpStub::Server::Scenario::Controller).as_null_object }
|
12
13
|
|
14
|
+
let(:request_pipeline) { instance_double(HttpStub::Server::RequestPipeline, process: nil) }
|
13
15
|
let(:response_pipeline) { instance_double(HttpStub::Server::ResponsePipeline, process: nil) }
|
14
16
|
|
15
17
|
let(:app) { HttpStub::Server::Application.new! }
|
16
18
|
|
17
19
|
before(:example) do
|
18
|
-
allow(HttpStub::Server::
|
20
|
+
allow(HttpStub::Server::Registry).to receive(:new).with("match").and_return(match_registry)
|
19
21
|
allow(HttpStub::Server::Registry).to receive(:new).with("scenario").and_return(scenario_registry)
|
22
|
+
allow(HttpStub::Server::Stub::Registry).to receive(:new).and_return(stub_registry)
|
20
23
|
allow(HttpStub::Server::Stub::Controller).to receive(:new).and_return(stub_controller)
|
21
24
|
allow(HttpStub::Server::Scenario::Controller).to receive(:new).and_return(scenario_controller)
|
25
|
+
allow(HttpStub::Server::RequestPipeline).to receive(:new).and_return(request_pipeline)
|
22
26
|
allow(HttpStub::Server::ResponsePipeline).to receive(:new).and_return(response_pipeline)
|
23
27
|
end
|
24
28
|
|
@@ -46,6 +50,53 @@ describe HttpStub::Server::Application do
|
|
46
50
|
|
47
51
|
end
|
48
52
|
|
53
|
+
context "when a request to list the stubs is received" do
|
54
|
+
|
55
|
+
let(:found_stubs) { [ HttpStub::Server::Stub::Empty::INSTANCE ] }
|
56
|
+
|
57
|
+
subject { get "/stubs" }
|
58
|
+
|
59
|
+
it "retrieves the stubs from the registry" do
|
60
|
+
expect(stub_registry).to receive(:all).and_return(found_stubs)
|
61
|
+
|
62
|
+
subject
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when a request to show a stub is received" do
|
68
|
+
|
69
|
+
let(:stub_id) { SecureRandom.uuid }
|
70
|
+
let(:found_stub) { HttpStub::Server::Stub::Empty::INSTANCE }
|
71
|
+
|
72
|
+
subject { get "/stubs/#{stub_id}" }
|
73
|
+
|
74
|
+
it "retrieves the stub from the registry" do
|
75
|
+
expect(stub_registry).to receive(:find).with(stub_id, anything).and_return(found_stub)
|
76
|
+
|
77
|
+
subject
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when a request to clear the stubs is received" do
|
83
|
+
|
84
|
+
subject { delete "/stubs" }
|
85
|
+
|
86
|
+
it "delegates clearing to the stub controller" do
|
87
|
+
expect(stub_controller).to receive(:clear)
|
88
|
+
|
89
|
+
subject
|
90
|
+
end
|
91
|
+
|
92
|
+
it "responds with a 200 status code" do
|
93
|
+
subject
|
94
|
+
|
95
|
+
expect(response.status).to eql(200)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
49
100
|
context "when a request to commit the stubs to memory is received" do
|
50
101
|
|
51
102
|
subject { post "/stubs/memory" }
|
@@ -82,20 +133,16 @@ describe HttpStub::Server::Application do
|
|
82
133
|
|
83
134
|
end
|
84
135
|
|
85
|
-
context "when a request to
|
136
|
+
context "when a request to list the matches is received" do
|
86
137
|
|
87
|
-
|
138
|
+
let(:found_matches) { [ HttpStub::Server::Stub::Match::MatchFixture.empty ] }
|
88
139
|
|
89
|
-
|
90
|
-
expect(stub_controller).to receive(:clear)
|
140
|
+
subject { get "/stubs/matches" }
|
91
141
|
|
92
|
-
|
93
|
-
|
142
|
+
it "retrieves the matches from the registry" do
|
143
|
+
expect(match_registry).to receive(:all).and_return(found_matches)
|
94
144
|
|
95
|
-
it "responds with a 200 status code" do
|
96
145
|
subject
|
97
|
-
|
98
|
-
expect(response.status).to eql(200)
|
99
146
|
end
|
100
147
|
|
101
148
|
end
|
@@ -129,6 +176,20 @@ describe HttpStub::Server::Application do
|
|
129
176
|
|
130
177
|
end
|
131
178
|
|
179
|
+
context "when a request to list the scenarios is received" do
|
180
|
+
|
181
|
+
let(:found_scenarios) { [ HttpStub::Server::Scenario::ScenarioFixture.empty ] }
|
182
|
+
|
183
|
+
subject { get "/stubs/scenarios" }
|
184
|
+
|
185
|
+
it "retrieves the stubs from the registry" do
|
186
|
+
expect(scenario_registry).to receive(:all).and_return(found_scenarios)
|
187
|
+
|
188
|
+
subject
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
132
193
|
context "when a request to clear the scenarios has been received" do
|
133
194
|
|
134
195
|
subject { delete "/stubs/scenarios" }
|
@@ -149,57 +210,24 @@ describe HttpStub::Server::Application do
|
|
149
210
|
|
150
211
|
context "when another type of request is received" do
|
151
212
|
|
152
|
-
let(:
|
213
|
+
let(:request_pipeline_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
153
214
|
|
154
215
|
subject { get "/a_path" }
|
155
216
|
|
156
|
-
before(:example) { allow(
|
217
|
+
before(:example) { allow(request_pipeline).to receive(:process).and_return(request_pipeline_response) }
|
157
218
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
it "processes the response via the response pipeline" do
|
163
|
-
expect(response_pipeline).to receive(:process).with(stub_response)
|
164
|
-
|
165
|
-
subject
|
166
|
-
end
|
219
|
+
it "determines the response via the request pipeline" do
|
220
|
+
expect(request_pipeline).to(
|
221
|
+
receive(:process).with(an_instance_of(HttpStub::Server::Request), anything)
|
222
|
+
)
|
167
223
|
|
224
|
+
subject
|
168
225
|
end
|
169
226
|
|
170
|
-
|
171
|
-
|
172
|
-
let(:scenario_response) { double(HttpStub::Server::Stub::Response::Base, serve_on: nil) }
|
173
|
-
|
174
|
-
before(:example) do
|
175
|
-
allow(stub_response).to receive(:empty?).and_return(true)
|
176
|
-
allow(scenario_controller).to receive(:activate).and_return(scenario_response)
|
177
|
-
end
|
178
|
-
|
179
|
-
context "but the scenario controller activates a scenario" do
|
180
|
-
|
181
|
-
before(:each) { allow(scenario_response).to receive(:empty?).and_return(false) }
|
182
|
-
|
183
|
-
it "processes the scenario response via the response pipeline" do
|
184
|
-
expect(response_pipeline).to receive(:process).with(scenario_response)
|
185
|
-
|
186
|
-
subject
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
context "and the scenario controller does not activate a scenario" do
|
192
|
-
|
193
|
-
before(:each) { allow(scenario_response).to receive(:empty?).and_return(true) }
|
194
|
-
|
195
|
-
it "processes an error response via the response pipeline" do
|
196
|
-
expect(response_pipeline).to receive(:process).with(HttpStub::Server::Response::ERROR)
|
197
|
-
|
198
|
-
subject
|
199
|
-
end
|
200
|
-
|
201
|
-
end
|
227
|
+
it "processes the response via the response pipeline" do
|
228
|
+
expect(response_pipeline).to receive(:process).with(request_pipeline_response)
|
202
229
|
|
230
|
+
subject
|
203
231
|
end
|
204
232
|
|
205
233
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
describe HttpStub::Server::FormattedHash do
|
2
|
+
|
3
|
+
let(:underlying_hash) { {} }
|
4
|
+
let(:key_value_delimiter) { "=" }
|
5
|
+
|
6
|
+
let(:formatted_hash) { described_class.new(underlying_hash, key_value_delimiter) }
|
7
|
+
|
8
|
+
it "is a Hash" do
|
9
|
+
expect(formatted_hash).to be_a(Hash)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#to_s" do
|
13
|
+
|
14
|
+
subject { formatted_hash.to_s }
|
15
|
+
|
16
|
+
describe "when a hash with multiple entires is provided" do
|
17
|
+
|
18
|
+
let(:underlying_hash) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
|
19
|
+
|
20
|
+
it "returns a string containing keys and values delimited by the provided delimiter" do
|
21
|
+
result = subject
|
22
|
+
|
23
|
+
underlying_hash.each { |key, value| expect(result).to match(/#{key}#{key_value_delimiter}#{value}/) }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "comma delimits the entries" do
|
27
|
+
expect(subject).to match(/key\d.value\d\, key\d.value\d\, key\d.value\d/)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when an empty hash is provided" do
|
33
|
+
|
34
|
+
let(:underlying_hash) { {} }
|
35
|
+
|
36
|
+
it "returns an empty string" do
|
37
|
+
expect(subject).to eql("")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "when a nil hash is provided" do
|
43
|
+
|
44
|
+
let(:underlying_hash) { nil }
|
45
|
+
|
46
|
+
it "returns an empty string" do
|
47
|
+
expect(subject).to eql("")
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe HttpStub::Server::
|
1
|
+
describe HttpStub::Server::HeaderParser do
|
2
2
|
|
3
3
|
let(:non_header_env_elements) do
|
4
4
|
{
|
@@ -10,16 +10,18 @@ describe HttpStub::Server::Stub::RequestHeaderParser do
|
|
10
10
|
let(:env) { non_header_env_elements.merge(header_env_elements) }
|
11
11
|
let(:request) { instance_double(Rack::Request, env: env) }
|
12
12
|
|
13
|
+
let(:header_parser) { described_class }
|
14
|
+
|
13
15
|
describe "::parse" do
|
14
16
|
|
17
|
+
subject { header_parser.parse(request) }
|
18
|
+
|
15
19
|
describe "when the request contains environment entries in upper case" do
|
16
20
|
|
17
21
|
let(:header_env_elements) { { "KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3" } }
|
18
22
|
|
19
23
|
it "returns a hash containing those entries" do
|
20
|
-
expect(
|
21
|
-
"KEY_2" => "value2",
|
22
|
-
"KEY_3" => "value3")
|
24
|
+
expect(subject).to eql("KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3")
|
23
25
|
end
|
24
26
|
|
25
27
|
end
|
@@ -29,9 +31,7 @@ describe HttpStub::Server::Stub::RequestHeaderParser do
|
|
29
31
|
let(:header_env_elements) { { "HTTP_KEY_1" => "value1", "HTTP_KEY_2" => "value2", "HTTP_KEY_3" => "value3" } }
|
30
32
|
|
31
33
|
it "returns a hash containing those entries with the prefix removed" do
|
32
|
-
expect(
|
33
|
-
"KEY_2" => "value2",
|
34
|
-
"KEY_3" => "value3")
|
34
|
+
expect(subject).to include("KEY_1" => "value1", "KEY_2" => "value2", "KEY_3" => "value3")
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
@@ -41,9 +41,9 @@ describe HttpStub::Server::Stub::RequestHeaderParser do
|
|
41
41
|
let(:header_env_elements) { {} }
|
42
42
|
|
43
43
|
it "returns an empty hash" do
|
44
|
-
expect(
|
44
|
+
expect(subject).to eql({})
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
@@ -4,8 +4,8 @@ describe HttpStub::Server::Stub::PayloadFileConsolidator do
|
|
4
4
|
|
5
5
|
describe "::consolidate!" do
|
6
6
|
|
7
|
-
let(:
|
8
|
-
let(:request)
|
7
|
+
let(:parameters) { {} }
|
8
|
+
let(:request) { instance_double(HttpStub::Server::Request, parameters: parameters) }
|
9
9
|
|
10
10
|
subject { consolidator.consolidate!(payload, request) }
|
11
11
|
|
@@ -13,7 +13,7 @@ describe HttpStub::Server::Stub::PayloadFileConsolidator do
|
|
13
13
|
|
14
14
|
let(:payload_fixture) { HttpStub::StubFixture.new.with_file_response! }
|
15
15
|
let(:payload) { payload_fixture.server_payload }
|
16
|
-
let(:
|
16
|
+
let(:parameters) { { "response_file_#{payload_fixture.id}" => payload_fixture.file_parameter } }
|
17
17
|
|
18
18
|
it "returns the payload with a response body that contains the file parameter value" do
|
19
19
|
expected_payload = payload.clone.tap { |hash| hash["response"]["body"] = payload_fixture.file_parameter }
|
@@ -41,7 +41,7 @@ describe HttpStub::Server::Stub::PayloadFileConsolidator do
|
|
41
41
|
context "and the trigger payloads contain a response file with corresponding file parameters" do
|
42
42
|
|
43
43
|
let(:trigger_fixtures) { (1..3).map { HttpStub::StubFixture.new.with_file_response! } }
|
44
|
-
let(:
|
44
|
+
let(:parameters) do
|
45
45
|
trigger_fixtures.reduce({}) do |result, fixture|
|
46
46
|
result.merge("response_file_#{fixture.id}" => fixture.file_parameter)
|
47
47
|
end
|
@@ -1,15 +1,14 @@
|
|
1
1
|
describe HttpStub::Server::Registry do
|
2
2
|
|
3
|
-
let(:logger) {
|
4
|
-
let(:request) { instance_double(Rack::Request, logger: logger) }
|
3
|
+
let(:logger) { instance_double(Logger, info: nil) }
|
5
4
|
|
6
5
|
let(:registry) { HttpStub::Server::Registry.new("a_model") }
|
7
6
|
|
8
7
|
shared_context "register multiple models" do
|
9
8
|
|
10
|
-
let(:models) { (1..3).map { |i| double("HttpStub::Server::Model#{i}", :
|
9
|
+
let(:models) { (1..3).map { |i| double("HttpStub::Server::Model#{i}", :matches? => false) } }
|
11
10
|
|
12
|
-
before(:example) { registry.concat(models,
|
11
|
+
before(:example) { registry.concat(models, logger) }
|
13
12
|
|
14
13
|
end
|
15
14
|
|
@@ -18,7 +17,7 @@ describe HttpStub::Server::Registry do
|
|
18
17
|
let(:model_string_representation) { "some model string" }
|
19
18
|
let(:model) { double("HttpStub::Server::Model", to_s: model_string_representation) }
|
20
19
|
|
21
|
-
subject { registry.add(model,
|
20
|
+
subject { registry.add(model, logger) }
|
22
21
|
|
23
22
|
before(:example) { allow(logger).to receive(:info) }
|
24
23
|
|
@@ -45,7 +44,7 @@ describe HttpStub::Server::Registry do
|
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
|
-
subject { registry.concat(models,
|
47
|
+
subject { registry.concat(models, logger) }
|
49
48
|
|
50
49
|
it "logs that the models have been registered" do
|
51
50
|
model_string_representations.each do |string_representation|
|
@@ -67,23 +66,23 @@ describe HttpStub::Server::Registry do
|
|
67
66
|
|
68
67
|
let(:criteria) { double("Criteria", inspect: "Criteria inspect result") }
|
69
68
|
|
70
|
-
subject { registry.find(criteria
|
69
|
+
subject { registry.find(criteria, logger) }
|
71
70
|
|
72
71
|
describe "when multiple models have been registered" do
|
73
72
|
|
74
73
|
include_context "register multiple models"
|
75
74
|
|
76
75
|
it "determines if the models satisfy the provided criteria" do
|
77
|
-
models.each { |model| expect(model).to receive(:
|
76
|
+
models.each { |model| expect(model).to receive(:matches?).with(criteria, logger).and_return(false) }
|
78
77
|
|
79
78
|
subject
|
80
79
|
end
|
81
80
|
|
82
|
-
describe "and one registered model
|
81
|
+
describe "and one registered model matches the criteria" do
|
83
82
|
|
84
83
|
let(:matching_model) { models[1] }
|
85
84
|
|
86
|
-
before(:example) { allow(matching_model).to receive(:
|
85
|
+
before(:example) { allow(matching_model).to receive(:matches?).and_return(true) }
|
87
86
|
|
88
87
|
it "returns the model" do
|
89
88
|
expect(subject).to eql(matching_model)
|
@@ -91,7 +90,7 @@ describe HttpStub::Server::Registry do
|
|
91
90
|
|
92
91
|
describe "and the registry is subsequently cleared" do
|
93
92
|
|
94
|
-
before(:example) { registry.clear(
|
93
|
+
before(:example) { registry.clear(logger) }
|
95
94
|
|
96
95
|
it "returns nil" do
|
97
96
|
expect(subject).to be_nil
|
@@ -103,7 +102,7 @@ describe HttpStub::Server::Registry do
|
|
103
102
|
|
104
103
|
describe "and multiple registered models satisfy the criteria" do
|
105
104
|
|
106
|
-
before(:example) { [0, 2].each { |i| allow(models[i]).to receive(:
|
105
|
+
before(:example) { [0, 2].each { |i| allow(models[i]).to receive(:matches?).and_return(true) } }
|
107
106
|
|
108
107
|
it "supports model overrides by returning the last model registered" do
|
109
108
|
expect(subject).to eql(models[2])
|
@@ -153,7 +152,7 @@ describe HttpStub::Server::Registry do
|
|
153
152
|
|
154
153
|
let(:model) { double("HttpStub::Server::Model") }
|
155
154
|
|
156
|
-
before(:example) { registry.add(model,
|
155
|
+
before(:example) { registry.add(model, logger) }
|
157
156
|
|
158
157
|
it "returns the model" do
|
159
158
|
expect(registry.last).to eql(model)
|
@@ -235,7 +234,7 @@ describe HttpStub::Server::Registry do
|
|
235
234
|
|
236
235
|
describe "#clear" do
|
237
236
|
|
238
|
-
subject { registry.clear(
|
237
|
+
subject { registry.clear(logger) }
|
239
238
|
|
240
239
|
it "logs that the models are being cleared" do
|
241
240
|
expect(logger).to receive(:info).with(/clearing a_model/i)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
describe HttpStub::Server::RequestPipeline do
|
2
|
+
|
3
|
+
let(:stub_controller) { instance_double(HttpStub::Server::Stub::Controller).as_null_object }
|
4
|
+
let(:scenario_controller) { instance_double(HttpStub::Server::Scenario::Controller).as_null_object }
|
5
|
+
let(:match_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
|
6
|
+
|
7
|
+
let(:request_pipeline) { described_class.new(stub_controller, scenario_controller, match_registry) }
|
8
|
+
|
9
|
+
describe "#process" do
|
10
|
+
|
11
|
+
let(:request) { instance_double(HttpStub::Server::Request) }
|
12
|
+
let(:logger) { instance_double(Logger) }
|
13
|
+
|
14
|
+
let(:stub_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
15
|
+
|
16
|
+
subject { request_pipeline.process(request, logger) }
|
17
|
+
|
18
|
+
before(:example) { allow(stub_controller).to receive(:replay).and_return(stub_response) }
|
19
|
+
|
20
|
+
context "when the stub controller replays a response" do
|
21
|
+
|
22
|
+
before(:example) { allow(stub_response).to receive(:empty?).and_return(false) }
|
23
|
+
|
24
|
+
it "returns the replayed response" do
|
25
|
+
expect(subject).to eql(stub_response)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when the stub controller does not replay a response" do
|
31
|
+
|
32
|
+
let(:scenario_response) { double(HttpStub::Server::Stub::Response::Base, serve_on: nil) }
|
33
|
+
|
34
|
+
before(:example) do
|
35
|
+
allow(stub_response).to receive(:empty?).and_return(true)
|
36
|
+
allow(scenario_controller).to receive(:activate).and_return(scenario_response)
|
37
|
+
end
|
38
|
+
|
39
|
+
context "but the scenario controller activates a scenario" do
|
40
|
+
|
41
|
+
before(:each) { allow(scenario_response).to receive(:empty?).and_return(false) }
|
42
|
+
|
43
|
+
it "returns the scenario response" do
|
44
|
+
expect(subject).to eql(scenario_response)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "and the scenario controller does not activate a scenario" do
|
50
|
+
|
51
|
+
let(:stub_match) { instance_double(HttpStub::Server::Stub::Match::Match) }
|
52
|
+
|
53
|
+
before(:each) do
|
54
|
+
allow(HttpStub::Server::Stub::Match::Match).to receive(:new).and_return(stub_match)
|
55
|
+
allow(scenario_response).to receive(:empty?).and_return(true)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "creates a match with no stub to indicate their was no match" do
|
59
|
+
expect(HttpStub::Server::Stub::Match::Match).to receive(:new).with(nil, request)
|
60
|
+
|
61
|
+
subject
|
62
|
+
end
|
63
|
+
|
64
|
+
it "registers the created match in the match registry" do
|
65
|
+
expect(match_registry).to receive(:add).with(stub_match, logger)
|
66
|
+
|
67
|
+
subject
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns a not found response" do
|
71
|
+
expect(subject).to eql(HttpStub::Server::Response::NOT_FOUND)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|