http_stub 0.14.2 → 0.15.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/configurer/request/http/basic.rb +21 -0
- data/lib/http_stub/configurer/request/http/factory.rb +43 -0
- data/lib/http_stub/configurer/request/http/multipart.rb +33 -0
- data/lib/http_stub/configurer/request/stub.rb +24 -8
- data/lib/http_stub/configurer/request/stub_activator.rb +12 -8
- data/lib/http_stub/configurer/request/{stub_activator_payload_builder.rb → stub_activator_builder.rb} +4 -4
- data/lib/http_stub/configurer/request/stub_builder.rb +34 -0
- data/lib/http_stub/configurer/request/stub_response.rb +40 -0
- data/lib/http_stub/configurer/request/stub_response_file.rb +20 -0
- data/lib/http_stub/configurer/server/command.rb +5 -1
- data/lib/http_stub/configurer/server/command_processor.rb +1 -1
- data/lib/http_stub/configurer/server/dsl.rb +4 -4
- data/lib/http_stub/configurer/server/facade.rb +25 -11
- data/lib/http_stub/extensions/core/hash.rb +26 -0
- data/lib/http_stub/rake/server_daemon_tasks.rb +1 -1
- data/lib/http_stub/rake/server_tasks.rb +1 -1
- data/lib/http_stub/rake/task_generators.rb +3 -3
- data/lib/http_stub/server/application.rb +117 -0
- data/lib/http_stub/server/daemon.rb +39 -0
- data/lib/http_stub/{models → server}/exact_value_matcher.rb +1 -1
- data/lib/http_stub/{models → server}/hash_with_string_value_matchers.rb +2 -2
- data/lib/http_stub/{models → server}/headers.rb +1 -1
- data/lib/http_stub/{models → server}/omitted_value_matcher.rb +1 -1
- data/lib/http_stub/{models → server}/regexp_value_matcher.rb +1 -1
- data/lib/http_stub/{models → server}/registry.rb +10 -3
- data/lib/http_stub/{models → server}/request_header_parser.rb +1 -1
- data/lib/http_stub/server/response.rb +13 -0
- data/lib/http_stub/server/response_pipeline.rb +18 -0
- data/lib/http_stub/{models → server}/string_value_matcher.rb +4 -4
- data/lib/http_stub/server/stub.rb +37 -0
- data/lib/http_stub/{models → server}/stub_activator.rb +10 -2
- data/lib/http_stub/{controllers → server}/stub_activator_controller.rb +5 -5
- data/lib/http_stub/{controllers → server}/stub_controller.rb +4 -4
- data/lib/http_stub/server/stub_factory.rb +30 -0
- data/lib/http_stub/{models → server}/stub_headers.rb +4 -4
- data/lib/http_stub/{models → server}/stub_parameters.rb +2 -2
- data/lib/http_stub/{models → server}/stub_registry.rb +4 -4
- data/lib/http_stub/server/stub_response/base.rb +62 -0
- data/lib/http_stub/server/stub_response/file.rb +48 -0
- data/lib/http_stub/server/stub_response/text.rb +17 -0
- data/lib/http_stub/server/stub_response.rb +14 -0
- data/lib/http_stub/{models → server}/stub_triggers.rb +6 -2
- data/lib/http_stub/{models → server}/stub_uri.rb +2 -2
- data/lib/http_stub/{views → server/views}/_stub.haml +0 -0
- data/lib/http_stub/{views → server/views}/application.sass +0 -0
- data/lib/http_stub/{views → server/views}/layout.haml +0 -0
- data/lib/http_stub/{views → server/views}/stub_activators.haml +0 -0
- data/lib/http_stub/{views → server/views}/stubs.haml +0 -0
- data/lib/http_stub/version.rb +1 -1
- data/lib/http_stub.rb +41 -24
- data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +2 -2
- data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +15 -0
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +148 -0
- data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +74 -0
- data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +119 -0
- data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +24 -22
- data/spec/lib/http_stub/configurer/request/stub_builder_spec.rb +154 -0
- data/spec/lib/http_stub/configurer/request/stub_response_spec.rb +136 -0
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +238 -17
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +7 -3
- data/spec/lib/http_stub/configurer/server/command_spec.rb +7 -6
- data/spec/lib/http_stub/configurer/server/dsl_spec.rb +58 -94
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +56 -41
- data/spec/lib/http_stub/configurer_integration_spec.rb +180 -81
- data/spec/lib/http_stub/{hash_extensions_spec.rb → extensions/core/hash_spec.rb} +1 -1
- data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +1 -1
- data/spec/lib/http_stub/{server_integration_spec.rb → server/application_integration_spec.rb} +1 -1
- data/spec/lib/http_stub/server/application_spec.rb +205 -0
- data/spec/lib/http_stub/server/daemon_integration_spec.rb +7 -0
- data/spec/lib/http_stub/{server_daemon_spec.rb → server/daemon_spec.rb} +4 -4
- data/spec/lib/http_stub/{models → server}/exact_value_matcher_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/hash_with_string_value_matchers_spec.rb +5 -5
- data/spec/lib/http_stub/{models → server}/headers_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/omitted_value_matcher_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/regexp_value_matcher_spec.rb +2 -2
- data/spec/lib/http_stub/{models → server}/registry_spec.rb +52 -55
- data/spec/lib/http_stub/{models → server}/request_header_parser_spec.rb +4 -4
- data/spec/lib/http_stub/server/response_pipeline_spec.rb +29 -0
- data/spec/lib/http_stub/server/response_spec.rb +41 -0
- data/spec/lib/http_stub/{models → server}/string_value_matcher_spec.rb +11 -11
- data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +85 -0
- data/spec/lib/http_stub/server/stub_activator_spec.rb +124 -0
- data/spec/lib/http_stub/server/stub_controller_spec.rb +74 -0
- data/spec/lib/http_stub/server/stub_factory_spec.rb +117 -0
- data/spec/lib/http_stub/{models → server}/stub_headers_spec.rb +9 -9
- data/spec/lib/http_stub/{models → server}/stub_parameters_spec.rb +6 -6
- data/spec/lib/http_stub/{models → server}/stub_registry_integration_spec.rb +3 -3
- data/spec/lib/http_stub/{models → server}/stub_registry_spec.rb +15 -35
- data/spec/lib/http_stub/server/stub_response/base_spec.rb +225 -0
- data/spec/lib/http_stub/server/stub_response/file_spec.rb +140 -0
- data/spec/lib/http_stub/server/stub_response/text_spec.rb +103 -0
- data/spec/lib/http_stub/server/stub_response_spec.rb +49 -0
- data/spec/lib/http_stub/{models → server}/stub_spec.rb +34 -18
- data/spec/lib/http_stub/{models → server}/stub_triggers_spec.rb +26 -16
- data/spec/lib/http_stub/{models → server}/stub_uri_spec.rb +5 -5
- data/spec/resources/sample.pdf +0 -0
- data/spec/resources/sample.txt +1 -0
- data/spec/spec_helper.rb +13 -4
- data/spec/support/stub_fixture.rb +106 -0
- metadata +148 -102
- data/lib/http_stub/configurer/request/stub_payload_builder.rb +0 -46
- data/lib/http_stub/hash_extensions.rb +0 -22
- data/lib/http_stub/models/request_pipeline.rb +0 -13
- data/lib/http_stub/models/response.rb +0 -43
- data/lib/http_stub/models/stub.rb +0 -35
- data/lib/http_stub/server.rb +0 -114
- data/lib/http_stub/server_daemon.rb +0 -36
- data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +0 -103
- data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +0 -304
- data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +0 -94
- data/spec/lib/http_stub/controllers/stub_controller_spec.rb +0 -83
- data/spec/lib/http_stub/models/request_pipeline_spec.rb +0 -17
- data/spec/lib/http_stub/models/response_spec.rb +0 -206
- data/spec/lib/http_stub/models/stub_activator_spec.rb +0 -76
- data/spec/lib/http_stub/server_daemon_integration_spec.rb +0 -7
- data/spec/lib/http_stub/server_spec.rb +0 -234
- data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +0 -27
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
describe HttpStub::Configurer::Request::StubPayloadBuilder do
|
|
2
|
-
|
|
3
|
-
let(:response_defaults) { {} }
|
|
4
|
-
|
|
5
|
-
let(:builder) { HttpStub::Configurer::Request::StubPayloadBuilder.new(response_defaults) }
|
|
6
|
-
|
|
7
|
-
shared_context "triggers one stub" do
|
|
8
|
-
|
|
9
|
-
let(:trigger_payload) { { "trigger_key" => "trigger value" } }
|
|
10
|
-
let(:trigger_builder) do
|
|
11
|
-
instance_double(HttpStub::Configurer::Request::StubPayloadBuilder, build: trigger_payload)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
before(:example) { builder.trigger(trigger_builder) }
|
|
15
|
-
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
shared_context "triggers many stubs" do
|
|
19
|
-
|
|
20
|
-
let(:trigger_payloads) { (1..3).map { |i| { "trigger_#{i}_key" => "trigger #{i} value" } } }
|
|
21
|
-
let(:trigger_builders) do
|
|
22
|
-
trigger_payloads.map do |payload|
|
|
23
|
-
instance_double(HttpStub::Configurer::Request::StubPayloadBuilder, build: payload)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
before(:example) { builder.trigger(trigger_builders) }
|
|
28
|
-
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#respond_with" do
|
|
32
|
-
|
|
33
|
-
it "does not modify any provided response defaults" do
|
|
34
|
-
original_response_defaults = response_defaults.clone
|
|
35
|
-
|
|
36
|
-
builder.respond_with(status: 201)
|
|
37
|
-
|
|
38
|
-
expect(response_defaults).to eql(original_response_defaults)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe "#build" do
|
|
44
|
-
|
|
45
|
-
context "when provided a request match and response data" do
|
|
46
|
-
|
|
47
|
-
include_context "stub payload builder arguments"
|
|
48
|
-
|
|
49
|
-
subject { builder.build }
|
|
50
|
-
|
|
51
|
-
before(:example) do
|
|
52
|
-
allow(HttpStub::Configurer::Request::ControllableValue).to receive(:format)
|
|
53
|
-
|
|
54
|
-
builder.match_requests(uri, request_options)
|
|
55
|
-
builder.respond_with(response_options)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context "when request header is provided" do
|
|
59
|
-
|
|
60
|
-
it "formats the headers into control values" do
|
|
61
|
-
expect(HttpStub::Configurer::Request::ControllableValue).to receive(:format).with(request_headers)
|
|
62
|
-
|
|
63
|
-
subject
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
context "when no request header is provided" do
|
|
69
|
-
|
|
70
|
-
let(:request_headers) { nil }
|
|
71
|
-
|
|
72
|
-
it "formats an empty header hash" do
|
|
73
|
-
expect(HttpStub::Configurer::Request::ControllableValue).to receive(:format).with({})
|
|
74
|
-
|
|
75
|
-
subject
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
context "when a request parameter is provided" do
|
|
81
|
-
|
|
82
|
-
it "formats the request parameters into control values" do
|
|
83
|
-
expect(HttpStub::Configurer::Request::ControllableValue).to receive(:format).with(request_parameters)
|
|
84
|
-
|
|
85
|
-
subject
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
context "when no request parameter is provided" do
|
|
91
|
-
|
|
92
|
-
let(:request_parameters) { nil }
|
|
93
|
-
|
|
94
|
-
it "formats an empty parameter hash" do
|
|
95
|
-
expect(HttpStub::Configurer::Request::ControllableValue).to receive(:format).with({})
|
|
96
|
-
|
|
97
|
-
subject
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
context "when many triggers are added" do
|
|
103
|
-
|
|
104
|
-
include_context "triggers many stubs"
|
|
105
|
-
|
|
106
|
-
it "builds the payload for each trigger" do
|
|
107
|
-
trigger_builders.each { |trigger_builder| expect(trigger_builder).to receive(:build) }
|
|
108
|
-
|
|
109
|
-
subject
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
context "builds a request payload" do
|
|
115
|
-
|
|
116
|
-
it "has an entry containing the control value representation of the uri" do
|
|
117
|
-
allow(HttpStub::Configurer::Request::ControllableValue).to(
|
|
118
|
-
receive(:format).with(uri).and_return("uri as a string")
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
expect(subject).to include(uri: "uri as a string")
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it "has an entry for the method option" do
|
|
125
|
-
expect(subject).to include(method: stub_method)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it "has an entry containing the string representation of the request headers" do
|
|
129
|
-
allow(HttpStub::Configurer::Request::ControllableValue).to(
|
|
130
|
-
receive(:format).with(request_headers).and_return("request headers as string")
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
expect(subject).to include(headers: "request headers as string")
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it "has an entry containing the string representation of the request parameters" do
|
|
137
|
-
allow(HttpStub::Configurer::Request::ControllableValue).to(
|
|
138
|
-
receive(:format).with(request_parameters).and_return("request parameters as string")
|
|
139
|
-
)
|
|
140
|
-
|
|
141
|
-
expect(subject).to include(parameters: "request parameters as string")
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context "when a status response argument is provided" do
|
|
145
|
-
|
|
146
|
-
it "has a response entry for the argument" do
|
|
147
|
-
expect(subject[:response]).to include(status: response_status)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
context "when no status response argument is provided" do
|
|
153
|
-
|
|
154
|
-
let(:response_status) { nil }
|
|
155
|
-
|
|
156
|
-
it "has a response entry with an empty status code" do
|
|
157
|
-
expect(subject[:response]).to include(status: "")
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
context "when response headers are provided" do
|
|
163
|
-
|
|
164
|
-
let(:response_headers) { { response_header_name: "value" } }
|
|
165
|
-
|
|
166
|
-
it "has a headers response entry containing the the provided headers" do
|
|
167
|
-
expect(subject[:response]).to include(headers: response_headers)
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
context "when response headers are omitted" do
|
|
173
|
-
|
|
174
|
-
let (:response_headers) { nil }
|
|
175
|
-
|
|
176
|
-
it "has a headers response entry containing an empty hash" do
|
|
177
|
-
expect(subject[:response]).to include(headers: {})
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "has an entry for the response body argument" do
|
|
183
|
-
expect(subject[:response]).to include(body: response_body)
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
context "when a delay option is provided" do
|
|
187
|
-
|
|
188
|
-
it "has a response entry for the argument" do
|
|
189
|
-
expect(subject[:response]).to include(delay_in_seconds: response_delay_in_seconds)
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
context "when a delay option is omitted" do
|
|
195
|
-
|
|
196
|
-
let(:response_delay_in_seconds) { nil }
|
|
197
|
-
|
|
198
|
-
it "has a response entry with an empty delay" do
|
|
199
|
-
expect(subject[:response]).to include(delay_in_seconds: "")
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
context "when a trigger is added" do
|
|
205
|
-
|
|
206
|
-
include_context "triggers one stub"
|
|
207
|
-
|
|
208
|
-
it "has a triggers entry containing the stub trigger payload" do
|
|
209
|
-
expect(subject).to include(triggers: [ trigger_payload ])
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
context "when many triggers are added" do
|
|
215
|
-
|
|
216
|
-
include_context "triggers many stubs"
|
|
217
|
-
|
|
218
|
-
it "has a triggers entry containing the stub trigger payloads" do
|
|
219
|
-
expect(subject).to include(triggers: trigger_payloads)
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
context "when no triggers are added" do
|
|
225
|
-
|
|
226
|
-
it "has a triggers entry containing an empty hash" do
|
|
227
|
-
expect(subject).to include(triggers: [])
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
context "when a root level response attribute is defaulted" do
|
|
233
|
-
|
|
234
|
-
let(:response_defaults) { { status: 204 } }
|
|
235
|
-
|
|
236
|
-
context "and is not overridden" do
|
|
237
|
-
|
|
238
|
-
let(:response_options) { {} }
|
|
239
|
-
|
|
240
|
-
it "assumes the defaulted value" do
|
|
241
|
-
expect(subject[:response]).to include(status: 204)
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
context "and is overridden" do
|
|
247
|
-
|
|
248
|
-
let(:response_status) { 302 }
|
|
249
|
-
|
|
250
|
-
it "assumes the override value" do
|
|
251
|
-
expect(subject[:response]).to include(status: 302)
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
context "when a nested response attribute is defaulted" do
|
|
259
|
-
|
|
260
|
-
let(:response_defaults) { { headers: { response_header_name: "default value" } } }
|
|
261
|
-
|
|
262
|
-
context "and the attribute has no other values defined" do
|
|
263
|
-
|
|
264
|
-
let(:response_headers) { {} }
|
|
265
|
-
|
|
266
|
-
it "assumes the defaults attributes" do
|
|
267
|
-
expect(subject[:response]).to include(response_defaults)
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
context "and the attribute has additional values defined" do
|
|
273
|
-
|
|
274
|
-
let(:response_headers) { { additional_header_name: "additional value" } }
|
|
275
|
-
|
|
276
|
-
it "includes the defaults values" do
|
|
277
|
-
expect(subject[:response][:headers]).to include(response_defaults[:headers])
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
it "includes the additional values" do
|
|
281
|
-
expect(subject[:response][:headers]).to include(response_headers)
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
context "and the attributes default values have been overridden" do
|
|
287
|
-
|
|
288
|
-
let(:response_headers) { { response_header_name: "override value"} }
|
|
289
|
-
|
|
290
|
-
it "assumes the defaults attributes" do
|
|
291
|
-
expect(subject[:response]).to include(headers: response_headers)
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
end
|
|
303
|
-
|
|
304
|
-
end
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
describe HttpStub::Controllers::StubActivatorController do
|
|
2
|
-
|
|
3
|
-
let(:request_body) { "Some request body" }
|
|
4
|
-
let(:request) { double("HttpRequest", body: double("RequestBody", read: request_body)) }
|
|
5
|
-
let(:stub_activator_options) { double("StubActivatorOptions") }
|
|
6
|
-
let(:the_stub) { double(HttpStub::Models::Stub) }
|
|
7
|
-
let(:stub_activator) { double(HttpStub::Models::StubActivator, the_stub: the_stub) }
|
|
8
|
-
let(:stub_activator_registry) { double("HttpStub::Models::StubActivatorRegistry").as_null_object }
|
|
9
|
-
let(:stub_registry) { double("HttpStub::Models::StubRegistry").as_null_object }
|
|
10
|
-
let(:controller) { HttpStub::Controllers::StubActivatorController.new(stub_activator_registry, stub_registry) }
|
|
11
|
-
|
|
12
|
-
before(:example) { allow(JSON).to receive(:parse).and_return(stub_activator_options) }
|
|
13
|
-
|
|
14
|
-
describe "#register" do
|
|
15
|
-
|
|
16
|
-
before(:example) do
|
|
17
|
-
allow(HttpStub::Models::StubActivator).to receive(:new).and_return(stub_activator)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "parses an options hash from the JSON request body" do
|
|
21
|
-
expect(JSON).to receive(:parse).with(request_body).and_return(stub_activator_options)
|
|
22
|
-
|
|
23
|
-
controller.register(request)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "creates a stub activator from the parsed options" do
|
|
27
|
-
expect(HttpStub::Models::StubActivator).to receive(:new).with(stub_activator_options).and_return(stub_activator)
|
|
28
|
-
|
|
29
|
-
controller.register(request)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "adds the created activator to the activator registry" do
|
|
33
|
-
expect(stub_activator_registry).to receive(:add).with(stub_activator, request)
|
|
34
|
-
|
|
35
|
-
controller.register(request)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "returns a success response" do
|
|
39
|
-
expect(controller.register(request)).to eql(HttpStub::Models::Response::SUCCESS)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe "#activate" do
|
|
45
|
-
|
|
46
|
-
describe "when a stub activator has been registered that is activated by the request" do
|
|
47
|
-
|
|
48
|
-
before(:example) do
|
|
49
|
-
allow(stub_activator_registry).to receive(:find_for).with(request).and_return(stub_activator)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "adds the activators stub to the stub registry" do
|
|
53
|
-
expect(stub_registry).to receive(:add).with(the_stub, request)
|
|
54
|
-
|
|
55
|
-
controller.activate(request)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "returns a success response" do
|
|
59
|
-
expect(controller.activate(request)).to eql(HttpStub::Models::Response::SUCCESS)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "when no stub activator is activated by the request" do
|
|
65
|
-
|
|
66
|
-
before(:example) do
|
|
67
|
-
allow(stub_activator_registry).to receive(:find_for).with(request).and_return(nil)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "does not add a stub to the registry" do
|
|
71
|
-
expect(stub_registry).not_to receive(:add)
|
|
72
|
-
|
|
73
|
-
controller.activate(request)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it "returns an empty response" do
|
|
77
|
-
expect(controller.activate(request)).to eql(HttpStub::Models::Response::EMPTY)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
describe "#clear" do
|
|
85
|
-
|
|
86
|
-
it "clears the activator registry" do
|
|
87
|
-
expect(stub_activator_registry).to receive(:clear).with(request)
|
|
88
|
-
|
|
89
|
-
controller.clear(request)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
describe HttpStub::Controllers::StubController do
|
|
2
|
-
|
|
3
|
-
let(:request_body) { "Some request body" }
|
|
4
|
-
let(:stub_options) { double("StubOptions") }
|
|
5
|
-
let(:request) { double("HttpRequest", body: double("RequestBody", read: request_body)) }
|
|
6
|
-
let(:response) { double(HttpStub::Models::Response) }
|
|
7
|
-
let(:the_stub) { double(HttpStub::Models::Stub, response: response) }
|
|
8
|
-
let(:registry) { double(HttpStub::Models::Registry).as_null_object }
|
|
9
|
-
let(:controller) { HttpStub::Controllers::StubController.new(registry) }
|
|
10
|
-
|
|
11
|
-
before(:example) { allow(JSON).to receive(:parse).and_return(stub_options) }
|
|
12
|
-
|
|
13
|
-
describe "#register" do
|
|
14
|
-
|
|
15
|
-
before(:example) do
|
|
16
|
-
allow(HttpStub::Models::Stub).to receive(:new).and_return(the_stub)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "parses an options hash from the JSON request body" do
|
|
20
|
-
expect(JSON).to receive(:parse).with(request_body).and_return(stub_options)
|
|
21
|
-
|
|
22
|
-
controller.register(request)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "creates a stub from the parsed options" do
|
|
26
|
-
expect(HttpStub::Models::Stub).to receive(:new).with(stub_options).and_return(the_stub)
|
|
27
|
-
|
|
28
|
-
controller.register(request)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "adds the stub to the stub registry" do
|
|
32
|
-
expect(registry).to receive(:add).with(the_stub, request)
|
|
33
|
-
|
|
34
|
-
controller.register(request)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "returns a success response" do
|
|
38
|
-
expect(controller.register(request)).to eql(HttpStub::Models::Response::SUCCESS)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe "#replay" do
|
|
44
|
-
|
|
45
|
-
describe "when a stub has been registered that should be replayed for the request" do
|
|
46
|
-
|
|
47
|
-
before(:example) do
|
|
48
|
-
allow(registry).to receive(:find_for).with(request).and_return(the_stub)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "returns the stubs response" do
|
|
52
|
-
expect(the_stub).to receive(:response).and_return(response)
|
|
53
|
-
|
|
54
|
-
expect(controller.replay(request)).to eql(response)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
describe "when no stub should be replayed for the request" do
|
|
60
|
-
|
|
61
|
-
before(:example) do
|
|
62
|
-
allow(registry).to receive(:find_for).with(request).and_return(nil)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "returns an empty response" do
|
|
66
|
-
expect(controller.replay(request)).to eql(HttpStub::Models::Response::EMPTY)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
describe "#clear" do
|
|
74
|
-
|
|
75
|
-
it "clears the stub registry" do
|
|
76
|
-
expect(registry).to receive(:clear).with(request)
|
|
77
|
-
|
|
78
|
-
controller.clear(request)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
describe HttpStub::Models::RequestPipeline do
|
|
2
|
-
|
|
3
|
-
let(:request_pipeline) { HttpStub::Models::RequestPipeline }
|
|
4
|
-
|
|
5
|
-
describe ".before_halt" do
|
|
6
|
-
|
|
7
|
-
let(:response) { double(HttpStub::Models::Response, delay_in_seconds: 5) }
|
|
8
|
-
|
|
9
|
-
it "sleeps for specified duration" do
|
|
10
|
-
expect(request_pipeline).to receive(:sleep).with(5)
|
|
11
|
-
|
|
12
|
-
request_pipeline.before_halt(response)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
end
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
describe HttpStub::Models::Response do
|
|
2
|
-
|
|
3
|
-
let(:status) { 202 }
|
|
4
|
-
let(:headers) { nil }
|
|
5
|
-
let(:body) { "A response body" }
|
|
6
|
-
let(:delay_in_seconds) { 18 }
|
|
7
|
-
|
|
8
|
-
let(:response) do
|
|
9
|
-
HttpStub::Models::Response.new(
|
|
10
|
-
"status" => status, "headers" => headers, "body" => body, "delay_in_seconds" => delay_in_seconds
|
|
11
|
-
)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "::SUCCESS" do
|
|
15
|
-
|
|
16
|
-
let(:response) { HttpStub::Models::Response::SUCCESS }
|
|
17
|
-
|
|
18
|
-
it "has a status of 200" do
|
|
19
|
-
expect(response.status).to eql(200)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "has a body containing OK to visually indicate success to those interacting via a browser" do
|
|
23
|
-
expect(response.body).to match(/OK/)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe "::ERROR" do
|
|
29
|
-
|
|
30
|
-
let(:response) { HttpStub::Models::Response::ERROR }
|
|
31
|
-
|
|
32
|
-
it "has a status of 404" do
|
|
33
|
-
expect(response.status).to eql(404)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "has a body containing ERROR to visually indicate the error to those interacting via a browser" do
|
|
37
|
-
expect(response.body).to match(/ERROR/)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe "#status" do
|
|
43
|
-
|
|
44
|
-
context "when a value is provided in the arguments" do
|
|
45
|
-
|
|
46
|
-
context "that is an integer" do
|
|
47
|
-
|
|
48
|
-
it "returns the value provided" do
|
|
49
|
-
expect(response.status).to eql(status)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context "that is an empty string" do
|
|
55
|
-
|
|
56
|
-
let(:status) { "" }
|
|
57
|
-
|
|
58
|
-
it "returns 200" do
|
|
59
|
-
expect(response.status).to eql(200)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context "when the status is not provided in the arguments" do
|
|
67
|
-
|
|
68
|
-
let(:response) { HttpStub::Models::Response.new("body" => body, "delay_in_seconds" => delay_in_seconds) }
|
|
69
|
-
|
|
70
|
-
it "returns 200" do
|
|
71
|
-
expect(response.status).to eql(200)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe "#body" do
|
|
79
|
-
|
|
80
|
-
it "returns the value provided in the arguments" do
|
|
81
|
-
expect(response.body).to eql("A response body")
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe "#delay_in_seconds" do
|
|
87
|
-
|
|
88
|
-
context "when a value is provided in the arguments" do
|
|
89
|
-
|
|
90
|
-
context "that is an integer" do
|
|
91
|
-
|
|
92
|
-
it "returns the value" do
|
|
93
|
-
expect(response.delay_in_seconds).to eql(delay_in_seconds)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
context "that is an empty string" do
|
|
99
|
-
|
|
100
|
-
let(:delay_in_seconds) { "" }
|
|
101
|
-
|
|
102
|
-
it "returns 0" do
|
|
103
|
-
expect(response.delay_in_seconds).to eql(0)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
context "when a value is not provided in the arguments" do
|
|
111
|
-
|
|
112
|
-
let(:response) { HttpStub::Models::Response.new("status" => status, "body" => body) }
|
|
113
|
-
|
|
114
|
-
it "returns 0" do
|
|
115
|
-
expect(response.delay_in_seconds).to eql(0)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
describe "#headers" do
|
|
123
|
-
|
|
124
|
-
let(:response_header_hash) { response.headers.to_hash }
|
|
125
|
-
|
|
126
|
-
it "is Headers" do
|
|
127
|
-
expect(response.headers).to be_a(HttpStub::Models::Headers)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context "when headers are provided" do
|
|
131
|
-
|
|
132
|
-
context "that include a content type" do
|
|
133
|
-
|
|
134
|
-
let(:headers) do
|
|
135
|
-
{ "content-type" => "some/content/type", "some_header" => "some value", "another_header" => "another value" }
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it "returns headers including the provided headers" do
|
|
139
|
-
expect(response_header_hash).to eql(headers)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context "that do not include a content type" do
|
|
145
|
-
|
|
146
|
-
let(:headers) do
|
|
147
|
-
{
|
|
148
|
-
"some_header" => "some value",
|
|
149
|
-
"another_header" => "another value",
|
|
150
|
-
"yet_another_header" => "yet another value"
|
|
151
|
-
}
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
it "returns headers including the provided headers" do
|
|
155
|
-
expect(response_header_hash).to include(headers)
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
it "returns headers including json as the default response content type" do
|
|
159
|
-
expect(response_header_hash).to include("content-type" => "application/json")
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
context "when no headers are provided" do
|
|
167
|
-
|
|
168
|
-
let(:headers) { nil }
|
|
169
|
-
|
|
170
|
-
it "returns headers containing json as the default response content type" do
|
|
171
|
-
expect(response_header_hash).to eql("content-type" => "application/json")
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
describe "#empty?" do
|
|
179
|
-
|
|
180
|
-
context "when the response is EMPTY" do
|
|
181
|
-
|
|
182
|
-
it "returns true" do
|
|
183
|
-
expect(HttpStub::Models::Response::EMPTY).to be_empty
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
context "when the response is not EMPTY but contains no values" do
|
|
189
|
-
|
|
190
|
-
it "returns true" do
|
|
191
|
-
expect(HttpStub::Models::Response.new).to be_empty
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
context "when the response is not EMPTY" do
|
|
197
|
-
|
|
198
|
-
it "returns false" do
|
|
199
|
-
expect(HttpStub::Models::Response::SUCCESS).not_to be_empty
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
end
|