http_stub 0.13.5 → 0.14.0.rc1
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 +13 -4
- data/lib/http_stub/configurer.rb +9 -63
- data/lib/http_stub/configurer/deprecated_dsl.rb +57 -0
- data/lib/http_stub/configurer/request/stub.rb +7 -13
- data/lib/http_stub/configurer/request/stub_activator.rb +8 -4
- data/lib/http_stub/configurer/request/stub_activator_payload_builder.rb +25 -0
- data/lib/http_stub/configurer/request/stub_payload_builder.rb +44 -0
- data/lib/http_stub/configurer/server/buffered_command_processor.rb +24 -0
- data/lib/http_stub/configurer/server/command.rb +18 -0
- data/lib/http_stub/configurer/server/command_processor.rb +38 -0
- data/lib/http_stub/configurer/server/dsl.rb +56 -0
- data/lib/http_stub/configurer/server/facade.rb +57 -0
- data/lib/http_stub/configurer/server/request_processor.rb +30 -0
- data/lib/http_stub/models/registry.rb +4 -0
- data/lib/http_stub/models/stub.rb +2 -1
- data/lib/http_stub/models/stub_registry.rb +29 -0
- data/lib/http_stub/models/stub_triggers.rb +23 -0
- data/lib/http_stub/rake/server_tasks.rb +2 -5
- data/lib/http_stub/server.rb +14 -4
- data/lib/http_stub/version.rb +1 -1
- data/lib/http_stub/views/_stub.haml +7 -0
- data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +232 -0
- data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +8 -8
- data/spec/lib/http_stub/configurer/request/omittable_spec.rb +8 -8
- data/spec/lib/http_stub/configurer/request/regexpable_spec.rb +14 -14
- data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +74 -0
- data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +19 -26
- data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +203 -0
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +18 -157
- data/spec/lib/http_stub/configurer/server/buffered_command_processor_spec.rb +35 -0
- data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +62 -0
- data/spec/lib/http_stub/configurer/server/command_spec.rb +25 -0
- data/spec/lib/http_stub/configurer/server/dsl_spec.rb +241 -0
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +253 -0
- data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +99 -0
- data/spec/lib/http_stub/configurer_integration_spec.rb +172 -122
- data/spec/lib/http_stub/configurer_spec.rb +4 -4
- data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +25 -25
- data/spec/lib/http_stub/controllers/stub_controller_spec.rb +22 -22
- data/spec/lib/http_stub/hash_extensions_spec.rb +24 -24
- data/spec/lib/http_stub/models/exact_value_matcher_spec.rb +4 -4
- data/spec/lib/http_stub/models/hash_with_string_value_matchers_spec.rb +29 -29
- data/spec/lib/http_stub/models/headers_spec.rb +10 -10
- data/spec/lib/http_stub/models/omitted_value_matcher_spec.rb +8 -8
- data/spec/lib/http_stub/models/regexp_value_matcher_spec.rb +6 -6
- data/spec/lib/http_stub/models/registry_spec.rb +71 -28
- data/spec/lib/http_stub/models/request_header_parser_spec.rb +4 -4
- data/spec/lib/http_stub/models/request_pipeline_spec.rb +2 -2
- data/spec/lib/http_stub/models/response_spec.rb +38 -38
- data/spec/lib/http_stub/models/string_value_matcher_spec.rb +25 -25
- data/spec/lib/http_stub/models/stub_activator_spec.rb +15 -15
- data/spec/lib/http_stub/models/stub_headers_spec.rb +18 -18
- data/spec/lib/http_stub/models/stub_parameters_spec.rb +16 -16
- data/spec/lib/http_stub/models/stub_registry_integration_spec.rb +62 -0
- data/spec/lib/http_stub/models/stub_registry_spec.rb +152 -0
- data/spec/lib/http_stub/models/stub_spec.rb +67 -43
- data/spec/lib/http_stub/models/stub_triggers_spec.rb +64 -0
- data/spec/lib/http_stub/models/stub_uri_spec.rb +9 -9
- data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +7 -7
- data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +5 -5
- data/spec/lib/http_stub/rake/server_tasks_spec.rb +17 -15
- data/spec/lib/http_stub/server_daemon_spec.rb +16 -16
- data/spec/lib/http_stub/server_integration_spec.rb +112 -65
- data/spec/lib/http_stub/server_spec.rb +134 -96
- data/spec/spec_helper.rb +1 -1
- data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +27 -0
- data/spec/support/server_integration.rb +2 -2
- metadata +69 -30
- data/lib/http_stub/configurer/command.rb +0 -26
- data/lib/http_stub/configurer/command_processor.rb +0 -36
- data/lib/http_stub/configurer/impatient_command_chain.rb +0 -13
- data/lib/http_stub/configurer/patient_command_chain.rb +0 -25
- data/spec/lib/http_stub/configurer/command_processor_integration_spec.rb +0 -63
- data/spec/lib/http_stub/configurer/command_spec.rb +0 -40
- data/spec/lib/http_stub/configurer/impatient_command_chain_spec.rb +0 -17
- data/spec/lib/http_stub/configurer/patient_command_chain_spec.rb +0 -73
@@ -0,0 +1,253 @@
|
|
1
|
+
describe HttpStub::Configurer::Server::Facade do
|
2
|
+
|
3
|
+
let(:configurer) { double(HttpStub::Configurer) }
|
4
|
+
let(:request_processor) { instance_double(HttpStub::Configurer::Server::RequestProcessor) }
|
5
|
+
|
6
|
+
let(:facade) { HttpStub::Configurer::Server::Facade.new(configurer) }
|
7
|
+
|
8
|
+
before(:example) do
|
9
|
+
allow(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).and_return(request_processor)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "constructor" do
|
13
|
+
|
14
|
+
it "creates a request processor with the provided configurer" do
|
15
|
+
expect(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).with(configurer)
|
16
|
+
|
17
|
+
facade
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#stub_response" do
|
23
|
+
|
24
|
+
let(:stub_uri) { "/some/stub/uri" }
|
25
|
+
let(:request) { instance_double(HttpStub::Configurer::Request::Stub, stub_uri: stub_uri) }
|
26
|
+
|
27
|
+
subject { facade.stub_response(request) }
|
28
|
+
|
29
|
+
before(:example) { allow(request_processor).to receive(:submit) }
|
30
|
+
|
31
|
+
it "submits the stub request via the request processor" do
|
32
|
+
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
33
|
+
|
34
|
+
subject
|
35
|
+
end
|
36
|
+
|
37
|
+
it "describes the stub via its stub uri" do
|
38
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "stubbing '#{stub_uri}'"))
|
39
|
+
|
40
|
+
subject
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#stub_activator" do
|
46
|
+
|
47
|
+
let(:activation_uri) { "/some/activation/uri" }
|
48
|
+
let(:request) { instance_double(HttpStub::Configurer::Request::StubActivator, activation_uri: activation_uri) }
|
49
|
+
|
50
|
+
subject { facade.stub_activator(request) }
|
51
|
+
|
52
|
+
before(:example) { allow(request_processor).to receive(:submit) }
|
53
|
+
|
54
|
+
it "submits the stub request via the request processor" do
|
55
|
+
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
56
|
+
|
57
|
+
subject
|
58
|
+
end
|
59
|
+
|
60
|
+
it "describes the stub via its activation uri" do
|
61
|
+
expect(request_processor).to(
|
62
|
+
receive(:submit).with(hash_including(description: "registering activator '#{activation_uri}'"))
|
63
|
+
)
|
64
|
+
|
65
|
+
subject
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#activate" do
|
71
|
+
|
72
|
+
let(:uri) { "/some/activation/uri" }
|
73
|
+
let(:request) { instance_double(Net::HTTP::Get) }
|
74
|
+
|
75
|
+
subject { facade.activate(uri) }
|
76
|
+
|
77
|
+
before(:example) do
|
78
|
+
allow(Net::HTTP::Get).to receive(:new).and_return(request)
|
79
|
+
allow(request_processor).to receive(:submit)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "creates a GET request for the uri" do
|
83
|
+
expect(Net::HTTP::Get).to receive(:new).with(uri).and_return(request)
|
84
|
+
|
85
|
+
subject
|
86
|
+
end
|
87
|
+
|
88
|
+
it "submits the GET request via the request processor" do
|
89
|
+
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
90
|
+
|
91
|
+
subject
|
92
|
+
end
|
93
|
+
|
94
|
+
it "describes the activation request via the provided uri" do
|
95
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "activating '#{uri}'"))
|
96
|
+
|
97
|
+
subject
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#remember_stubs" do
|
103
|
+
|
104
|
+
let(:request) { instance_double(Net::HTTP::Post) }
|
105
|
+
|
106
|
+
subject { facade.remember_stubs }
|
107
|
+
|
108
|
+
before(:example) do
|
109
|
+
allow(Net::HTTP::Post).to receive(:new).and_return(request)
|
110
|
+
allow(request).to receive(:body=)
|
111
|
+
allow(request_processor).to receive(:submit)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "creates a POST request for /stubs/memory endpoint" do
|
115
|
+
expect(Net::HTTP::Post).to receive(:new).with("/stubs/memory").and_return(request)
|
116
|
+
|
117
|
+
subject
|
118
|
+
end
|
119
|
+
|
120
|
+
it "establishes an empty body on the POST request" do
|
121
|
+
expect(request).to receive(:body=).with("")
|
122
|
+
|
123
|
+
subject
|
124
|
+
end
|
125
|
+
|
126
|
+
it "submits the POST request via the request processor" do
|
127
|
+
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
128
|
+
|
129
|
+
subject
|
130
|
+
end
|
131
|
+
|
132
|
+
it "describes the request as committing the servers stubs to memory" do
|
133
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "committing stubs to memory"))
|
134
|
+
|
135
|
+
subject
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#recall_stubs" do
|
141
|
+
|
142
|
+
let(:request) { instance_double(Net::HTTP::Get) }
|
143
|
+
|
144
|
+
subject { facade.recall_stubs }
|
145
|
+
|
146
|
+
before(:example) do
|
147
|
+
allow(Net::HTTP::Get).to receive(:new).and_return(request)
|
148
|
+
allow(request_processor).to receive(:submit)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "creates a POST request for /stubs/memory endpoint" do
|
152
|
+
expect(Net::HTTP::Get).to receive(:new).with("/stubs/memory").and_return(request)
|
153
|
+
|
154
|
+
subject
|
155
|
+
end
|
156
|
+
|
157
|
+
it "submits the GET request via the request processor" do
|
158
|
+
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
159
|
+
|
160
|
+
subject
|
161
|
+
end
|
162
|
+
|
163
|
+
it "describes the request as recalling the servers stubs in memory" do
|
164
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "recalling stubs in memory"))
|
165
|
+
|
166
|
+
subject
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "#clear_stubs" do
|
172
|
+
|
173
|
+
let(:request) { instance_double(Net::HTTP::Delete) }
|
174
|
+
|
175
|
+
subject { facade.clear_stubs }
|
176
|
+
|
177
|
+
before(:example) do
|
178
|
+
allow(Net::HTTP::Delete).to receive(:new).and_return(request)
|
179
|
+
allow(request_processor).to receive(:submit)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "creates a DELETE request for the /stubs endpoint" do
|
183
|
+
expect(Net::HTTP::Delete).to receive(:new).with("/stubs").and_return(request)
|
184
|
+
|
185
|
+
subject
|
186
|
+
end
|
187
|
+
|
188
|
+
it "adds the DELETE request to the server state" do
|
189
|
+
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
190
|
+
|
191
|
+
subject
|
192
|
+
end
|
193
|
+
|
194
|
+
it "describes the request as clearing the server stubs" do
|
195
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "clearing stubs"))
|
196
|
+
|
197
|
+
subject
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "#clear_activators" do
|
203
|
+
|
204
|
+
let(:request) { instance_double(Net::HTTP::Delete) }
|
205
|
+
|
206
|
+
subject { facade.clear_activators }
|
207
|
+
|
208
|
+
before(:example) do
|
209
|
+
allow(Net::HTTP::Delete).to receive(:new).and_return(request)
|
210
|
+
allow(request_processor).to receive(:submit)
|
211
|
+
end
|
212
|
+
|
213
|
+
it "creates a DELETE request for the /stubs/activators endpoint" do
|
214
|
+
expect(Net::HTTP::Delete).to receive(:new).with("/stubs/activators").and_return(request)
|
215
|
+
|
216
|
+
subject
|
217
|
+
end
|
218
|
+
|
219
|
+
it "adds the DELETE request to the server state" do
|
220
|
+
expect(request_processor).to receive(:submit).with(hash_including(request: request))
|
221
|
+
|
222
|
+
subject
|
223
|
+
end
|
224
|
+
|
225
|
+
it "describes the request as clearing the server stub activators" do
|
226
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "clearing activators"))
|
227
|
+
|
228
|
+
subject
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "#server_has_started" do
|
234
|
+
|
235
|
+
it "informs the request processor to disable buffering requests" do
|
236
|
+
expect(request_processor).to receive(:disable_buffering!)
|
237
|
+
|
238
|
+
facade.server_has_started
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "#flush_requests" do
|
244
|
+
|
245
|
+
it "informs the request processor to flush it's requests" do
|
246
|
+
expect(request_processor).to receive(:flush!)
|
247
|
+
|
248
|
+
facade.flush_requests
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
describe HttpStub::Configurer::Server::RequestProcessor do
|
2
|
+
|
3
|
+
let(:configurer) { double(HttpStub::Configurer) }
|
4
|
+
let(:command_processor) { instance_double(HttpStub::Configurer::Server::CommandProcessor) }
|
5
|
+
let(:buffered_command_processor) { instance_double(HttpStub::Configurer::Server::BufferedCommandProcessor) }
|
6
|
+
|
7
|
+
let(:request_processor) { HttpStub::Configurer::Server::RequestProcessor.new(configurer) }
|
8
|
+
|
9
|
+
before(:example) do
|
10
|
+
allow(HttpStub::Configurer::Server::CommandProcessor).to receive(:new).and_return(command_processor)
|
11
|
+
allow(HttpStub::Configurer::Server::BufferedCommandProcessor).to(
|
12
|
+
receive(:new).and_return(buffered_command_processor)
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "constructor" do
|
17
|
+
|
18
|
+
it "creates a command processor for the configurer" do
|
19
|
+
expect(HttpStub::Configurer::Server::CommandProcessor).to receive(:new).with(configurer)
|
20
|
+
|
21
|
+
request_processor
|
22
|
+
end
|
23
|
+
|
24
|
+
it "creates a buffered command processor that flushes via the command processor" do
|
25
|
+
expect(HttpStub::Configurer::Server::BufferedCommandProcessor).to receive(:new).with(command_processor)
|
26
|
+
|
27
|
+
request_processor
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#submit" do
|
33
|
+
|
34
|
+
let(:args) { { some_arg_key: "some arg value" } }
|
35
|
+
|
36
|
+
subject { request_processor.submit(args) }
|
37
|
+
|
38
|
+
shared_examples_for "submitting a request to the server" do |processor_description|
|
39
|
+
|
40
|
+
let(:command) { instance_double(HttpStub::Configurer::Server::Command) }
|
41
|
+
|
42
|
+
before(:each) { allow(active_command_processor).to receive(:process) }
|
43
|
+
|
44
|
+
it "creates a command for the provided arguments" do
|
45
|
+
expect(HttpStub::Configurer::Server::Command).to receive(:new).with(hash_including(args)).and_return(command)
|
46
|
+
|
47
|
+
subject
|
48
|
+
end
|
49
|
+
|
50
|
+
it "processes the command via the #{processor_description}" do
|
51
|
+
allow(HttpStub::Configurer::Server::Command).to receive(:new).and_return(command)
|
52
|
+
expect(active_command_processor).to receive(:process).with(command)
|
53
|
+
|
54
|
+
subject
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when request buffering is enabled" do
|
60
|
+
|
61
|
+
let(:active_command_processor) { buffered_command_processor }
|
62
|
+
|
63
|
+
it_behaves_like "submitting a request to the server", "buffered command processor"
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when request buffering is disabled" do
|
68
|
+
|
69
|
+
let(:active_command_processor) { command_processor }
|
70
|
+
|
71
|
+
before(:example) { request_processor.disable_buffering! }
|
72
|
+
|
73
|
+
it_behaves_like "submitting a request to the server", "command processor"
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#flush!" do
|
80
|
+
|
81
|
+
subject { request_processor.flush! }
|
82
|
+
|
83
|
+
before(:example) { allow(buffered_command_processor).to receive(:flush) }
|
84
|
+
|
85
|
+
it "delegates to the buffered command processor" do
|
86
|
+
expect(buffered_command_processor).to receive(:flush)
|
87
|
+
|
88
|
+
subject
|
89
|
+
end
|
90
|
+
|
91
|
+
it "disables request buffering" do
|
92
|
+
expect(request_processor).to receive(:disable_buffering!)
|
93
|
+
|
94
|
+
subject
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
@@ -1,16 +1,17 @@
|
|
1
1
|
describe HttpStub::Configurer, "when the server is running" do
|
2
2
|
include_context "server integration"
|
3
3
|
|
4
|
-
let(:configurer)
|
4
|
+
let(:configurer) { HttpStub::Examples::ConfigurerWithClassActivator.new }
|
5
|
+
let(:stub_server) { configurer.stub_server }
|
5
6
|
|
6
|
-
after(:
|
7
|
+
after(:example) do
|
7
8
|
configurer.clear_stubs!
|
8
9
|
configurer.class.clear_activators!
|
9
10
|
end
|
10
11
|
|
11
12
|
context "and the configurer is initialized" do
|
12
13
|
|
13
|
-
before(:
|
14
|
+
before(:example) do
|
14
15
|
configurer.class.host(server_host)
|
15
16
|
configurer.class.port(server_port)
|
16
17
|
configurer.class.initialize!
|
@@ -18,15 +19,15 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
18
19
|
|
19
20
|
context "and a stub is activated" do
|
20
21
|
|
21
|
-
before(:
|
22
|
+
before(:example) { configurer.activate!("/an_activator") }
|
22
23
|
|
23
24
|
context "and the stub request is made" do
|
24
25
|
|
25
26
|
let(:response) { Net::HTTP.get_response(server_host, "/stub_path", server_port) }
|
26
27
|
|
27
|
-
it "
|
28
|
-
response.code.
|
29
|
-
response.body.
|
28
|
+
it "replays the stubbed response" do
|
29
|
+
expect(response.code).to eql("200")
|
30
|
+
expect(response.body).to eql("Stub activator body")
|
30
31
|
end
|
31
32
|
|
32
33
|
end
|
@@ -39,8 +40,8 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
39
40
|
|
40
41
|
let(:response) { Net::HTTP.get_response(server_host, "/stub_path", server_port) }
|
41
42
|
|
42
|
-
it "
|
43
|
-
response.code.
|
43
|
+
it "responds with a 404 status code" do
|
44
|
+
expect(response.code).to eql("404")
|
44
45
|
end
|
45
46
|
|
46
47
|
end
|
@@ -51,28 +52,28 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
51
52
|
|
52
53
|
let(:configurer) { HttpStub::Examples::ConfigurerWithClassStub.new }
|
53
54
|
|
54
|
-
it "
|
55
|
+
it "registers the stub" do
|
55
56
|
response = Net::HTTP.get_response(server_host, "/a_class_stub", server_port)
|
56
57
|
|
57
|
-
response.code.
|
58
|
-
response.body.
|
58
|
+
expect(response.code).to eql("201")
|
59
|
+
expect(response.body).to eql("Class stub body")
|
59
60
|
end
|
60
61
|
|
61
62
|
context "and the stub is overridden" do
|
62
63
|
|
63
|
-
before(:
|
64
|
+
before(:example) do
|
64
65
|
configurer.stub_response!("/a_class_stub", method: :get, response: { body: "Other class stub body" })
|
65
66
|
end
|
66
67
|
|
67
68
|
context "and the configurer is re-initialized" do
|
68
69
|
|
69
|
-
before(:
|
70
|
+
before(:example) { configurer.class.initialize! }
|
70
71
|
|
71
|
-
it "
|
72
|
+
it "re-establishes the class stub as having priority" do
|
72
73
|
response = Net::HTTP.get_response(server_host, "/a_class_stub", server_port)
|
73
74
|
|
74
|
-
response.code.
|
75
|
-
response.body.
|
75
|
+
expect(response.code).to eql("201")
|
76
|
+
expect(response.body).to eql("Class stub body")
|
76
77
|
end
|
77
78
|
|
78
79
|
end
|
@@ -85,48 +86,48 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
85
86
|
|
86
87
|
let(:configurer) { HttpStub::Examples::ConfigurerWithComplexInitializer.new }
|
87
88
|
|
88
|
-
it "
|
89
|
+
it "registers the activated activator" do
|
89
90
|
response = Net::HTTP.get_response(server_host, "/activated_during_initialization_stub_path", server_port)
|
90
91
|
|
91
|
-
response.code.
|
92
|
-
response.body.
|
92
|
+
expect(response.code).to eql("200")
|
93
|
+
expect(response.body).to eql("Activated during initialization body")
|
93
94
|
end
|
94
95
|
|
95
|
-
it "
|
96
|
+
it "registers the stub" do
|
96
97
|
response = Net::HTTP.get_response(server_host, "/stubbed_during_initialization_path", server_port)
|
97
98
|
|
98
|
-
response.code.
|
99
|
-
response.body.
|
99
|
+
expect(response.code).to eql("200")
|
100
|
+
expect(response.body).to eql("Stubbed during initialization body")
|
100
101
|
end
|
101
102
|
|
102
103
|
context "and another stub is registered" do
|
103
104
|
|
104
|
-
before(:
|
105
|
+
before(:example) do
|
105
106
|
configurer.stub_response!("/another_stub", method: :get, response: { body: "Another stub body" })
|
106
107
|
end
|
107
108
|
|
108
|
-
context "and the
|
109
|
+
context "and the servers remembered stubs are recalled" do
|
109
110
|
|
110
|
-
before(:
|
111
|
+
before(:example) { configurer.recall_stubs! }
|
111
112
|
|
112
|
-
it "
|
113
|
+
it "removes the stub registered post-initialization" do
|
113
114
|
response = Net::HTTP.get_response(server_host, "/another_stub", server_port)
|
114
115
|
|
115
|
-
response.code.
|
116
|
+
expect(response.code).to eql("404")
|
116
117
|
end
|
117
118
|
|
118
|
-
it "
|
119
|
+
it "retains the activated activator during initialization" do
|
119
120
|
response = Net::HTTP.get_response(server_host, "/activated_during_initialization_stub_path", server_port)
|
120
121
|
|
121
|
-
response.code.
|
122
|
-
response.body.
|
122
|
+
expect(response.code).to eql("200")
|
123
|
+
expect(response.body).to eql("Activated during initialization body")
|
123
124
|
end
|
124
125
|
|
125
|
-
it "
|
126
|
+
it "retains the stub registered during initialization" do
|
126
127
|
response = Net::HTTP.get_response(server_host, "/stubbed_during_initialization_path", server_port)
|
127
128
|
|
128
|
-
response.code.
|
129
|
-
response.body.
|
129
|
+
expect(response.code).to eql("200")
|
130
|
+
expect(response.body).to eql("Stubbed during initialization body")
|
130
131
|
end
|
131
132
|
|
132
133
|
end
|
@@ -135,13 +136,13 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
135
136
|
|
136
137
|
end
|
137
138
|
|
138
|
-
context "and a
|
139
|
+
context "and a stub is submitted" do
|
139
140
|
|
140
141
|
context "that contains no headers or parameters" do
|
141
142
|
|
142
143
|
context "and contains a response status" do
|
143
144
|
|
144
|
-
before(:
|
145
|
+
before(:example) do
|
145
146
|
configurer.stub_response!("/stub_with_status", method: :get, response: { status: 201, body: "Stub body" })
|
146
147
|
end
|
147
148
|
|
@@ -149,26 +150,26 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
149
150
|
|
150
151
|
let(:response) { Net::HTTP.get_response(server_host, "/stub_with_status", server_port) }
|
151
152
|
|
152
|
-
it "
|
153
|
-
response.code.
|
153
|
+
it "responds with the stubbed status" do
|
154
|
+
expect(response.code).to eql("201")
|
154
155
|
end
|
155
156
|
|
156
|
-
it "
|
157
|
-
response.body.
|
157
|
+
it "replays the stubbed body" do
|
158
|
+
expect(response.body).to eql("Stub body")
|
158
159
|
end
|
159
160
|
|
160
161
|
end
|
161
162
|
|
162
|
-
context "and
|
163
|
+
context "and stubs are cleared" do
|
163
164
|
|
164
|
-
before(:
|
165
|
+
before(:example) { configurer.clear_stubs! }
|
165
166
|
|
166
167
|
context "and the original request is made" do
|
167
168
|
|
168
169
|
let(:response) { Net::HTTP.get_response(server_host, "/stub_with_status", server_port) }
|
169
170
|
|
170
|
-
it "
|
171
|
-
response.code.
|
171
|
+
it "responds with a 404 status code" do
|
172
|
+
expect(response.code).to eql("404")
|
172
173
|
end
|
173
174
|
|
174
175
|
end
|
@@ -179,7 +180,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
179
180
|
|
180
181
|
context "and does not contain a response status" do
|
181
182
|
|
182
|
-
before(:
|
183
|
+
before(:example) do
|
183
184
|
configurer.stub_response!("/stub_without_status", method: :get, response: { body: "Stub body" })
|
184
185
|
end
|
185
186
|
|
@@ -187,15 +188,15 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
187
188
|
|
188
189
|
let(:response) { Net::HTTP.get_response(server_host, "/stub_without_status", server_port) }
|
189
190
|
|
190
|
-
it "
|
191
|
-
response.body.
|
191
|
+
it "responds with the stubbed body" do
|
192
|
+
expect(response.body).to eql("Stub body")
|
192
193
|
end
|
193
194
|
|
194
195
|
end
|
195
196
|
|
196
197
|
context "and the stub uri is regular expression containing meta characters" do
|
197
198
|
|
198
|
-
before(:
|
199
|
+
before(:example) do
|
199
200
|
configurer.stub_response!(/\/stub\/regexp\/\$key=value/, method: :get, response: { body: "Stub body" })
|
200
201
|
end
|
201
202
|
|
@@ -203,8 +204,8 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
203
204
|
|
204
205
|
let(:response) { Net::HTTP.get_response(server_host, "/match/stub/regexp/$key=value", server_port) }
|
205
206
|
|
206
|
-
it "
|
207
|
-
response.body.
|
207
|
+
it "responds with the stubbed body" do
|
208
|
+
expect(response.body).to eql("Stub body")
|
208
209
|
end
|
209
210
|
|
210
211
|
end
|
@@ -213,8 +214,8 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
213
214
|
|
214
215
|
let(:response) { Net::HTTP.get_response(server_host, "/stub/no_match/regexp", server_port) }
|
215
216
|
|
216
|
-
it "
|
217
|
-
response.code.
|
217
|
+
it "responds with a 404 status code" do
|
218
|
+
expect(response.code).to eql("404")
|
218
219
|
end
|
219
220
|
|
220
221
|
end
|
@@ -230,7 +231,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
230
231
|
|
231
232
|
context "whose values are strings" do
|
232
233
|
|
233
|
-
before(:
|
234
|
+
before(:example) do
|
234
235
|
configurer.stub_response!(
|
235
236
|
"/stub_with_headers", method: :get, headers: { key: "value" },
|
236
237
|
response: { status: 202, body: "Another stub body" }
|
@@ -241,9 +242,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
241
242
|
|
242
243
|
let(:response) { HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "value" }) }
|
243
244
|
|
244
|
-
it "
|
245
|
-
response.code.
|
246
|
-
response.body.
|
245
|
+
it "replays the stubbed response" do
|
246
|
+
expect(response.code).to eql(202)
|
247
|
+
expect(response.body).to eql("Another stub body")
|
247
248
|
end
|
248
249
|
|
249
250
|
end
|
@@ -252,8 +253,8 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
252
253
|
|
253
254
|
let(:response) { HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "other_value" }) }
|
254
255
|
|
255
|
-
it "
|
256
|
-
response.code.
|
256
|
+
it "responds with a 404 status code" do
|
257
|
+
expect(response.code).to eql(404)
|
257
258
|
end
|
258
259
|
|
259
260
|
end
|
@@ -262,7 +263,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
262
263
|
|
263
264
|
context "whose values are regular expressions" do
|
264
265
|
|
265
|
-
before(:
|
266
|
+
before(:example) do
|
266
267
|
configurer.stub_response!(
|
267
268
|
"/stub_with_headers", method: :get, headers: { key: /^match.*/ },
|
268
269
|
response: { status: 202, body: "Another stub body" }
|
@@ -275,9 +276,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
275
276
|
HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "matching_value" })
|
276
277
|
end
|
277
278
|
|
278
|
-
it "
|
279
|
-
response.code.
|
280
|
-
response.body.
|
279
|
+
it "replays the stubbed response" do
|
280
|
+
expect(response.code).to eql(202)
|
281
|
+
expect(response.body).to eql("Another stub body")
|
281
282
|
end
|
282
283
|
|
283
284
|
end
|
@@ -288,8 +289,8 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
288
289
|
HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "does_not_match_value" })
|
289
290
|
end
|
290
291
|
|
291
|
-
it "
|
292
|
-
response.code.
|
292
|
+
it "responds with a 404 status code" do
|
293
|
+
expect(response.code).to eql(404)
|
293
294
|
end
|
294
295
|
|
295
296
|
end
|
@@ -302,7 +303,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
302
303
|
|
303
304
|
context "whose values are strings" do
|
304
305
|
|
305
|
-
before(:
|
306
|
+
before(:example) do
|
306
307
|
configurer.stub_response!("/stub_with_parameters", method: :get, parameters: { key: "value" },
|
307
308
|
response: { status: 202, body: "Another stub body" })
|
308
309
|
end
|
@@ -311,9 +312,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
311
312
|
|
312
313
|
let(:response) { Net::HTTP.get_response(server_host, "/stub_with_parameters?key=value", server_port) }
|
313
314
|
|
314
|
-
it "
|
315
|
-
response.code.
|
316
|
-
response.body.
|
315
|
+
it "replays the stubbed response" do
|
316
|
+
expect(response.code).to eql("202")
|
317
|
+
expect(response.body).to eql("Another stub body")
|
317
318
|
end
|
318
319
|
|
319
320
|
end
|
@@ -324,8 +325,8 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
324
325
|
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=another_value", server_port)
|
325
326
|
end
|
326
327
|
|
327
|
-
it "
|
328
|
-
response.code.
|
328
|
+
it "responds with a 404 status code" do
|
329
|
+
expect(response.code).to eql("404")
|
329
330
|
end
|
330
331
|
|
331
332
|
end
|
@@ -334,7 +335,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
334
335
|
|
335
336
|
context "whose values are regular expressions" do
|
336
337
|
|
337
|
-
before(:
|
338
|
+
before(:example) do
|
338
339
|
configurer.stub_response!(
|
339
340
|
"/stub_with_parameters", method: :get, parameters: { key: /^match.*/ },
|
340
341
|
response: { status: 202, body: "Another stub body" }
|
@@ -347,9 +348,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
347
348
|
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=matching_value", server_port)
|
348
349
|
end
|
349
350
|
|
350
|
-
it "
|
351
|
-
response.code.
|
352
|
-
response.body.
|
351
|
+
it "replays the stubbed response" do
|
352
|
+
expect(response.code).to eql("202")
|
353
|
+
expect(response.body).to eql("Another stub body")
|
353
354
|
end
|
354
355
|
|
355
356
|
end
|
@@ -360,8 +361,8 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
360
361
|
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=does_not_match_value", server_port)
|
361
362
|
end
|
362
363
|
|
363
|
-
it "
|
364
|
-
response.code.
|
364
|
+
it "responds with a 404 status code" do
|
365
|
+
expect(response.code).to eql("404")
|
365
366
|
end
|
366
367
|
|
367
368
|
end
|
@@ -370,7 +371,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
370
371
|
|
371
372
|
context "whose values indicate the parameters must be omitted" do
|
372
373
|
|
373
|
-
before(:
|
374
|
+
before(:example) do
|
374
375
|
configurer.stub_response!(
|
375
376
|
"/stub_with_omitted_parameters", method: :get, parameters: { key: :omitted },
|
376
377
|
response: { status: 202, body: "Omitted parameter stub body" }
|
@@ -381,9 +382,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
381
382
|
|
382
383
|
let(:response) { Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters", server_port) }
|
383
384
|
|
384
|
-
it "
|
385
|
-
response.code.
|
386
|
-
response.body.
|
385
|
+
it "replays the stubbed response" do
|
386
|
+
expect(response.code).to eql("202")
|
387
|
+
expect(response.body).to eql("Omitted parameter stub body")
|
387
388
|
end
|
388
389
|
|
389
390
|
end
|
@@ -394,8 +395,8 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
394
395
|
Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters?key=must_be_omitted", server_port)
|
395
396
|
end
|
396
397
|
|
397
|
-
it "
|
398
|
-
response.code.
|
398
|
+
it "responds with a 404 status code" do
|
399
|
+
expect(response.code).to eql("404")
|
399
400
|
end
|
400
401
|
|
401
402
|
end
|
@@ -404,7 +405,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
404
405
|
|
405
406
|
context "whose values are numbers" do
|
406
407
|
|
407
|
-
before(:
|
408
|
+
before(:example) do
|
408
409
|
configurer.stub_response!("/stub_with_parameters", method: :get, parameters: { key: 88 },
|
409
410
|
response: { status: 203, body: "Body for parameter number" })
|
410
411
|
end
|
@@ -413,9 +414,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
413
414
|
|
414
415
|
let(:response) { Net::HTTP.get_response(server_host, "/stub_with_parameters?key=88", server_port) }
|
415
416
|
|
416
|
-
it "
|
417
|
-
response.code.
|
418
|
-
response.body.
|
417
|
+
it "replays the stubbed response" do
|
418
|
+
expect(response.code).to eql("203")
|
419
|
+
expect(response.body).to eql("Body for parameter number")
|
419
420
|
end
|
420
421
|
|
421
422
|
end
|
@@ -424,7 +425,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
424
425
|
|
425
426
|
context "whose values are regular expressions" do
|
426
427
|
|
427
|
-
before(:
|
428
|
+
before(:example) do
|
428
429
|
configurer.stub_response!(
|
429
430
|
"/stub_with_parameters", method: :get, parameters: { key: /^match.*/ },
|
430
431
|
response: { status: 202, body: "Another stub body" }
|
@@ -437,9 +438,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
437
438
|
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=matching_value", server_port)
|
438
439
|
end
|
439
440
|
|
440
|
-
it "
|
441
|
-
response.code.
|
442
|
-
response.body.
|
441
|
+
it "replays the stubbed response" do
|
442
|
+
expect(response.code).to eql("202")
|
443
|
+
expect(response.body).to eql("Another stub body")
|
443
444
|
end
|
444
445
|
|
445
446
|
end
|
@@ -450,8 +451,8 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
450
451
|
Net::HTTP.get_response(server_host, "/stub_with_parameters?key=does_not_match_value", server_port)
|
451
452
|
end
|
452
453
|
|
453
|
-
it "
|
454
|
-
response.code.
|
454
|
+
it "responds with a 404 status code" do
|
455
|
+
expect(response.code).to eql("404")
|
455
456
|
end
|
456
457
|
|
457
458
|
end
|
@@ -460,7 +461,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
460
461
|
|
461
462
|
context "whose values indicate the parameters must be omitted" do
|
462
463
|
|
463
|
-
before(:
|
464
|
+
before(:example) do
|
464
465
|
configurer.stub_response!(
|
465
466
|
"/stub_with_omitted_parameters", method: :get, parameters: { key: :omitted },
|
466
467
|
response: { status: 202, body: "Omitted parameter stub body" }
|
@@ -471,9 +472,9 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
471
472
|
|
472
473
|
let(:response) { Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters", server_port) }
|
473
474
|
|
474
|
-
it "
|
475
|
-
response.code.
|
476
|
-
response.body.
|
475
|
+
it "replays the stubbed response" do
|
476
|
+
expect(response.code).to eql("202")
|
477
|
+
expect(response.body).to eql("Omitted parameter stub body")
|
477
478
|
end
|
478
479
|
|
479
480
|
end
|
@@ -484,8 +485,57 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
484
485
|
Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters?key=must_be_omitted", server_port)
|
485
486
|
end
|
486
487
|
|
487
|
-
it "
|
488
|
-
response.code.
|
488
|
+
it "responds with a 404 status code" do
|
489
|
+
expect(response.code).to eql("404")
|
490
|
+
end
|
491
|
+
|
492
|
+
end
|
493
|
+
|
494
|
+
end
|
495
|
+
|
496
|
+
end
|
497
|
+
|
498
|
+
context "that contains triggers" do
|
499
|
+
|
500
|
+
let(:triggers) do
|
501
|
+
(1..3).map do |trigger_number|
|
502
|
+
stub_server.build_stub do |stub|
|
503
|
+
stub.match_request("/triggered_stub_#{trigger_number}", method: :get)
|
504
|
+
stub.with_response(status: 200 + trigger_number, body: "Triggered stub body #{trigger_number}")
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
before(:example) do
|
510
|
+
stub_server.add_stub! do |stub|
|
511
|
+
stub.match_request("/stub_with_triggers", method: :get)
|
512
|
+
stub.with_response(body: "Trigger stub body")
|
513
|
+
triggers.each { |trigger| stub.and_add_stub(trigger) }
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
context "and a request is made matching the stub" do
|
518
|
+
|
519
|
+
before(:example) do
|
520
|
+
@stub_with_triggers_response = Net::HTTP.get_response(server_host, "/stub_with_triggers", server_port)
|
521
|
+
end
|
522
|
+
|
523
|
+
it "replays the stubbed response" do
|
524
|
+
expect(@stub_with_triggers_response.code).to eql("200")
|
525
|
+
expect(@stub_with_triggers_response.body).to eql("Trigger stub body")
|
526
|
+
end
|
527
|
+
|
528
|
+
(1..3).each do |trigger_number|
|
529
|
+
|
530
|
+
context "and then a request matching triggered stub ##{trigger_number} is made" do
|
531
|
+
|
532
|
+
let(:response) { Net::HTTP.get_response(server_host, "/triggered_stub_#{trigger_number}", server_port) }
|
533
|
+
|
534
|
+
it "replays the triggered response" do
|
535
|
+
expect(response.code).to eql("20#{trigger_number}")
|
536
|
+
expect(response.body).to eql("Triggered stub body #{trigger_number}")
|
537
|
+
end
|
538
|
+
|
489
539
|
end
|
490
540
|
|
491
541
|
end
|
@@ -500,11 +550,11 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
500
550
|
|
501
551
|
let(:configurer) { HttpStub::Examples::ConfigurerWithInitializeCallback.new }
|
502
552
|
|
503
|
-
it "
|
553
|
+
it "executes the callback" do
|
504
554
|
response = Net::HTTP.get_response(server_host, "/stubbed_on_initialize_path", server_port)
|
505
555
|
|
506
|
-
response.code.
|
507
|
-
response.body.
|
556
|
+
expect(response.code).to eql("200")
|
557
|
+
expect(response.body).to eql("Stubbed on initialize body")
|
508
558
|
end
|
509
559
|
|
510
560
|
end
|
@@ -515,61 +565,61 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
515
565
|
|
516
566
|
context "and the configurer is informed that the server has started" do
|
517
567
|
|
518
|
-
before(:
|
568
|
+
before(:example) { configurer.server_has_started! }
|
519
569
|
|
520
|
-
it "
|
570
|
+
it "does not initialize the configurer" do
|
521
571
|
activation_lambda = lambda { configurer.activate!("/an_activator") }
|
522
572
|
|
523
|
-
activation_lambda.
|
573
|
+
expect(activation_lambda).to raise_error(/error occurred activating '\/an_activator'/i)
|
524
574
|
end
|
525
575
|
|
526
576
|
context "and an attempt is made to register a stub" do
|
527
577
|
|
528
|
-
before(:
|
578
|
+
before(:example) do
|
529
579
|
configurer.stub_response!("/some_stub_path", method: :get, response: { body: "Some stub body"})
|
530
580
|
end
|
531
581
|
|
532
|
-
it "
|
582
|
+
it "registers the stub" do
|
533
583
|
response = Net::HTTP.get_response(server_host, "/some_stub_path", server_port)
|
534
584
|
|
535
|
-
response.code.
|
536
|
-
response.body.
|
585
|
+
expect(response.code).to eql("200")
|
586
|
+
expect(response.body).to eql("Some stub body")
|
537
587
|
end
|
538
588
|
|
539
589
|
end
|
540
590
|
|
541
591
|
context "and an attempt is made to register a stub with a timeout" do
|
542
592
|
|
543
|
-
before(:
|
593
|
+
before(:example) do
|
544
594
|
configurer.stub_response!("/some_stub_path", method: :get, response: {:delay_in_seconds => 2})
|
545
595
|
end
|
546
596
|
|
547
|
-
it "
|
597
|
+
it "delegates to request pipeline" do
|
548
598
|
before = Time.new
|
549
599
|
|
550
600
|
response = Net::HTTP.get_response(server_host, "/some_stub_path", server_port)
|
551
|
-
response.code.
|
601
|
+
expect(response.code).to eql("200")
|
552
602
|
|
553
603
|
after = Time.now
|
554
604
|
|
555
|
-
(after - before).round().
|
605
|
+
expect((after - before).round()).to be >= 2
|
556
606
|
end
|
557
607
|
|
558
608
|
end
|
559
609
|
|
560
610
|
describe "and an attempt is made to register a response with a content type header" do
|
561
611
|
|
562
|
-
before(:
|
612
|
+
before(:example) do
|
563
613
|
configurer.stub_response!(
|
564
614
|
"/some_stub_path", method: :get, response: { body: "Some stub body",
|
565
615
|
headers: { "content-type" => "application/xhtml" } }
|
566
616
|
)
|
567
617
|
end
|
568
618
|
|
569
|
-
it "
|
619
|
+
it "registers the stub" do
|
570
620
|
response = Net::HTTP.get_response("localhost", "/some_stub_path", 8001)
|
571
621
|
|
572
|
-
response.content_type.
|
622
|
+
expect(response.content_type).to eql("application/xhtml")
|
573
623
|
end
|
574
624
|
|
575
625
|
end
|
@@ -584,16 +634,16 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
584
634
|
}
|
585
635
|
end
|
586
636
|
|
587
|
-
before(:
|
637
|
+
before(:example) do
|
588
638
|
configurer.stub_response!(
|
589
639
|
"/some_stub_path", method: :get, response: { body: "Some stub body", headers: response_headers }
|
590
640
|
)
|
591
641
|
end
|
592
642
|
|
593
|
-
it "
|
643
|
+
it "registers the stub" do
|
594
644
|
response = Net::HTTP.get_response("localhost", "/some_stub_path", 8001)
|
595
645
|
|
596
|
-
response_headers.each { |key, value| response[key].
|
646
|
+
response_headers.each { |key, value| expect(response[key]).to eql(value) }
|
597
647
|
end
|
598
648
|
|
599
649
|
end
|
@@ -604,10 +654,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
604
654
|
|
605
655
|
context "and an attempt is made to activate a stub" do
|
606
656
|
|
607
|
-
it "
|
657
|
+
it "raises an exception indicating an error occurred during activation" do
|
608
658
|
activation_lambda = lambda { configurer.activate!("/an_activator") }
|
609
659
|
|
610
|
-
activation_lambda.
|
660
|
+
expect(activation_lambda).to raise_error(/error occurred activating '\/an_activator'/i)
|
611
661
|
end
|
612
662
|
|
613
663
|
end
|
@@ -618,10 +668,10 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
618
668
|
|
619
669
|
let(:configurer) { HttpStub::Examples::ConfigurerWithInitializeCallback.new }
|
620
670
|
|
621
|
-
it "
|
671
|
+
it "does not execute the callback" do
|
622
672
|
response = Net::HTTP.get_response(server_host, "/stubbed_on_initialize_path", server_port)
|
623
673
|
|
624
|
-
response.code.
|
674
|
+
expect(response.code).to eql("404")
|
625
675
|
end
|
626
676
|
|
627
677
|
end
|