http_stub 0.18.1 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/http_stub/configurer/dsl/endpoint_template.rb +20 -8
- data/lib/http_stub/configurer/dsl/server.rb +1 -3
- data/lib/http_stub/configurer/dsl/stub_builder.rb +2 -2
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/endpoint_template_spec.rb +9 -2
- data/spec/lib/http_stub/configurer/dsl/endpoint_template_spec.rb +114 -40
- data/spec/lib/http_stub/configurer/dsl/server_spec.rb +3 -31
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b3e67c607aa3b80f5e886bd7de7fbbfd3749f72
|
4
|
+
data.tar.gz: f0f313f13ccd2d1e0b2eaf62292e2c293b5b2592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3f87569921e42a1272453d37ef65a5585c148ec081a943bc128af5cbff417e59440beedee64b21dc08af0f1c71b3a14f428fcc215903c92104b1ba40787abec
|
7
|
+
data.tar.gz: fb62118fd274913421bda1ef15a2776871a9af76dd2ad96f07b29b1a20417bc2ab60d102bd65ba1faaaefd91aeb7d21687a35dcb0c0a8587245d92eea760a91d
|
@@ -4,19 +4,31 @@ module HttpStub
|
|
4
4
|
|
5
5
|
class EndpointTemplate
|
6
6
|
|
7
|
-
delegate :match_requests, :schema, :respond_with, :trigger, :invoke, to: :@
|
7
|
+
delegate :match_requests, :schema, :respond_with, :trigger, :invoke, to: :@template_stub_builder
|
8
8
|
|
9
|
-
def initialize(server
|
9
|
+
def initialize(server)
|
10
10
|
@server = server
|
11
|
-
@
|
11
|
+
@template_stub_builder = HttpStub::Configurer::DSL::StubBuilder.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_stub(response_overrides={}, &block)
|
15
|
+
@server.build_stub { |stub| compose_stub(stub, response_overrides, &block) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_stub!(response_overrides={}, &block)
|
19
|
+
@server.add_stub! { |stub| compose_stub(stub, response_overrides, &block) }
|
12
20
|
end
|
13
21
|
|
14
22
|
def add_scenario!(name, response_overrides={}, &block)
|
15
|
-
@server.add_one_stub_scenario!(name)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
@server.add_one_stub_scenario!(name) { |stub| compose_stub(stub, response_overrides, &block) }
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def compose_stub(stub_builder, response_overrides, &block)
|
29
|
+
stub_builder.merge!(@template_stub_builder)
|
30
|
+
stub_builder.respond_with(response_overrides)
|
31
|
+
stub_builder.invoke(&block) if block_given?
|
20
32
|
end
|
21
33
|
|
22
34
|
end
|
@@ -43,9 +43,7 @@ module HttpStub
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def endpoint_template(&block)
|
46
|
-
HttpStub::Configurer::DSL::EndpointTemplate.new(self
|
47
|
-
template.invoke(&block)
|
48
|
-
end
|
46
|
+
HttpStub::Configurer::DSL::EndpointTemplate.new(self).tap { |template| template.invoke(&block) }
|
49
47
|
end
|
50
48
|
|
51
49
|
def add_activator!(&block)
|
data/lib/http_stub/version.rb
CHANGED
@@ -13,6 +13,13 @@ describe "Endpoint Template acceptance" do
|
|
13
13
|
expect(response.code).to eql(404)
|
14
14
|
end
|
15
15
|
|
16
|
+
it "registers any stubs added to the template" do
|
17
|
+
response = issue_request("custom_stub_uri")
|
18
|
+
|
19
|
+
expect(response.code).to eql(201)
|
20
|
+
expect(response.body).to eql("custom stub body")
|
21
|
+
end
|
22
|
+
|
16
23
|
context "and a templated scenario is activated" do
|
17
24
|
|
18
25
|
before(:example) { stub_server.activate!(scenario_name) }
|
@@ -21,7 +28,7 @@ describe "Endpoint Template acceptance" do
|
|
21
28
|
|
22
29
|
let(:scenario_name) { "custom_request" }
|
23
30
|
|
24
|
-
let(:response) { issue_request("
|
31
|
+
let(:response) { issue_request("custom_scenario_uri") }
|
25
32
|
|
26
33
|
it "registers a templated stub for the scenario" do
|
27
34
|
expect(response.code).to eql(200)
|
@@ -38,7 +45,7 @@ describe "Endpoint Template acceptance" do
|
|
38
45
|
|
39
46
|
it "registers a templated stub for the scenario" do
|
40
47
|
expect(response.code).to eql(202)
|
41
|
-
expect(response.body).to eql("custom body")
|
48
|
+
expect(response.body).to eql("custom scenario body")
|
42
49
|
end
|
43
50
|
|
44
51
|
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
describe HttpStub::Configurer::DSL::EndpointTemplate do
|
2
2
|
|
3
|
-
let(:
|
3
|
+
let(:server) { instance_double(HttpStub::Configurer::DSL::Server) }
|
4
|
+
let(:response_defaults) { {} }
|
5
|
+
let(:template_stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
|
4
6
|
|
5
|
-
let(:
|
6
|
-
let(:response_defaults) { {} }
|
7
|
-
let(:default_stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
|
8
|
-
|
9
|
-
let(:endpoint_template) { HttpStub::Configurer::DSL::EndpointTemplate.new(server, response_defaults) }
|
7
|
+
let(:endpoint_template) { HttpStub::Configurer::DSL::EndpointTemplate.new(server) }
|
10
8
|
|
11
9
|
before(:example) do
|
12
|
-
allow(HttpStub::Configurer::DSL::StubBuilder).to(
|
13
|
-
|
14
|
-
|
10
|
+
allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(template_stub_builder)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "creates a stub builder to hold the templated default values" do
|
14
|
+
expect(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).with(no_args)
|
15
|
+
|
16
|
+
endpoint_template
|
15
17
|
end
|
16
18
|
|
17
19
|
describe "#match_requests" do
|
@@ -21,8 +23,8 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
21
23
|
|
22
24
|
subject { endpoint_template.match_requests(uri, args) }
|
23
25
|
|
24
|
-
it "delegates to the
|
25
|
-
expect(
|
26
|
+
it "delegates to the templates stub builder" do
|
27
|
+
expect(template_stub_builder).to receive(:match_requests).with(uri, args)
|
26
28
|
|
27
29
|
subject
|
28
30
|
end
|
@@ -36,8 +38,8 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
36
38
|
|
37
39
|
subject { endpoint_template.schema(type, definition) }
|
38
40
|
|
39
|
-
it "delegates to the
|
40
|
-
expect(
|
41
|
+
it "delegates to the templates stub builder" do
|
42
|
+
expect(template_stub_builder).to receive(:schema).with(type, definition)
|
41
43
|
|
42
44
|
subject
|
43
45
|
end
|
@@ -50,8 +52,8 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
50
52
|
|
51
53
|
subject { endpoint_template.respond_with(args) }
|
52
54
|
|
53
|
-
it "delegates to the
|
54
|
-
expect(
|
55
|
+
it "delegates to the templates stub builder" do
|
56
|
+
expect(template_stub_builder).to receive(:respond_with).with(args)
|
55
57
|
|
56
58
|
subject
|
57
59
|
end
|
@@ -64,8 +66,8 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
64
66
|
|
65
67
|
subject { endpoint_template.trigger(trigger) }
|
66
68
|
|
67
|
-
it "delegates to the
|
68
|
-
expect(
|
69
|
+
it "delegates to the templates stub builder" do
|
70
|
+
expect(template_stub_builder).to receive(:trigger).with(trigger)
|
69
71
|
|
70
72
|
subject
|
71
73
|
end
|
@@ -79,8 +81,8 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
79
81
|
|
80
82
|
subject { endpoint_template.invoke(&block) }
|
81
83
|
|
82
|
-
it "delegates to the
|
83
|
-
expect(
|
84
|
+
it "delegates to the templates stub builder" do
|
85
|
+
expect(template_stub_builder).to receive(:invoke).and_yield
|
84
86
|
expect(block_verifier).to receive(:verify)
|
85
87
|
|
86
88
|
subject
|
@@ -88,32 +90,19 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
88
90
|
|
89
91
|
end
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
let(:name) { "some_scenario_name" }
|
94
|
-
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder).as_null_object }
|
95
|
-
|
96
|
-
before(:example) { allow(server).to receive(:add_one_stub_scenario!).and_yield(stub_builder) }
|
97
|
-
|
98
|
-
subject { endpoint_template.add_scenario!(name) }
|
99
|
-
|
100
|
-
it "add a one stub scenario to the server" do
|
101
|
-
expect(server).to receive(:add_one_stub_scenario!).with(name)
|
102
|
-
|
103
|
-
subject
|
104
|
-
end
|
93
|
+
shared_examples_for "an endpoint template method composing a stub" do
|
105
94
|
|
106
95
|
it "merges the added stub with the default stub builder" do
|
107
|
-
expect(stub_builder).to receive(:merge!).with(
|
96
|
+
expect(stub_builder).to receive(:merge!).with(template_stub_builder)
|
108
97
|
|
109
|
-
|
98
|
+
subject_without_overrides_and_block
|
110
99
|
end
|
111
100
|
|
112
101
|
context "when response overrides are provided" do
|
113
102
|
|
114
103
|
let(:response_overrides) { { status: 302 } }
|
115
104
|
|
116
|
-
subject {
|
105
|
+
subject { subject_with_response_overrides(response_overrides) }
|
117
106
|
|
118
107
|
it "informs the stub builder to respond with the response overrides" do
|
119
108
|
expect(stub_builder).to receive(:respond_with).with(response_overrides)
|
@@ -125,7 +114,7 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
125
114
|
|
126
115
|
context "when response overrides are not provided" do
|
127
116
|
|
128
|
-
subject {
|
117
|
+
subject { subject_without_overrides_and_block }
|
129
118
|
|
130
119
|
it "does not change the stub builder by requesting it respond with an empty hash" do
|
131
120
|
expect(stub_builder).to receive(:respond_with).with({})
|
@@ -139,7 +128,7 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
139
128
|
expect(stub_builder).to receive(:merge!).ordered
|
140
129
|
expect(stub_builder).to receive(:respond_with).ordered
|
141
130
|
|
142
|
-
|
131
|
+
subject_without_overrides_and_block
|
143
132
|
end
|
144
133
|
|
145
134
|
context "when a block is provided" do
|
@@ -147,7 +136,7 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
147
136
|
let(:block_verifier) { double("BlockVerifier") }
|
148
137
|
let(:block) { lambda { block_verifier.verify } }
|
149
138
|
|
150
|
-
subject {
|
139
|
+
subject { subject_with_block(&block) }
|
151
140
|
|
152
141
|
it "requests the added stub builder invoke the provided block" do
|
153
142
|
expect(stub_builder).to receive(:invoke).and_yield
|
@@ -167,7 +156,7 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
167
156
|
|
168
157
|
context "when a block is not provided" do
|
169
158
|
|
170
|
-
subject {
|
159
|
+
subject { subject_without_overrides_and_block }
|
171
160
|
|
172
161
|
it "does not requests the added stub builder invoke a block" do
|
173
162
|
expect(stub_builder).not_to receive(:invoke)
|
@@ -179,4 +168,89 @@ describe HttpStub::Configurer::DSL::EndpointTemplate do
|
|
179
168
|
|
180
169
|
end
|
181
170
|
|
171
|
+
describe "#build_stub" do
|
172
|
+
|
173
|
+
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder).as_null_object }
|
174
|
+
|
175
|
+
before(:example) { allow(server).to receive(:build_stub).and_yield(stub_builder) }
|
176
|
+
|
177
|
+
def subject_without_overrides_and_block
|
178
|
+
endpoint_template.build_stub
|
179
|
+
end
|
180
|
+
|
181
|
+
def subject_with_response_overrides(overrides)
|
182
|
+
endpoint_template.build_stub(overrides)
|
183
|
+
end
|
184
|
+
|
185
|
+
def subject_with_block(&block)
|
186
|
+
endpoint_template.build_stub(&block)
|
187
|
+
end
|
188
|
+
|
189
|
+
it "builds a stub on the server" do
|
190
|
+
expect(server).to receive(:build_stub)
|
191
|
+
|
192
|
+
subject_without_overrides_and_block
|
193
|
+
end
|
194
|
+
|
195
|
+
it_behaves_like "an endpoint template method composing a stub"
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "#add_stub!" do
|
200
|
+
|
201
|
+
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder).as_null_object }
|
202
|
+
|
203
|
+
before(:example) { allow(server).to receive(:add_stub!).and_yield(stub_builder) }
|
204
|
+
|
205
|
+
def subject_without_overrides_and_block
|
206
|
+
endpoint_template.add_stub!
|
207
|
+
end
|
208
|
+
|
209
|
+
def subject_with_response_overrides(overrides)
|
210
|
+
endpoint_template.add_stub!(overrides)
|
211
|
+
end
|
212
|
+
|
213
|
+
def subject_with_block(&block)
|
214
|
+
endpoint_template.add_stub!(&block)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "builds a stub on the server" do
|
218
|
+
expect(server).to receive(:add_stub!)
|
219
|
+
|
220
|
+
subject_without_overrides_and_block
|
221
|
+
end
|
222
|
+
|
223
|
+
it_behaves_like "an endpoint template method composing a stub"
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "#add_scenario!" do
|
228
|
+
|
229
|
+
let(:name) { "some_scenario_name" }
|
230
|
+
let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder).as_null_object }
|
231
|
+
|
232
|
+
before(:example) { allow(server).to receive(:add_one_stub_scenario!).and_yield(stub_builder) }
|
233
|
+
|
234
|
+
def subject_without_overrides_and_block
|
235
|
+
endpoint_template.add_scenario!(name)
|
236
|
+
end
|
237
|
+
|
238
|
+
def subject_with_response_overrides(overrides)
|
239
|
+
endpoint_template.add_scenario!(name, overrides)
|
240
|
+
end
|
241
|
+
|
242
|
+
def subject_with_block(&block)
|
243
|
+
endpoint_template.add_scenario!(name, &block)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "adds a one stub scenario to the server" do
|
247
|
+
expect(server).to receive(:add_one_stub_scenario!).with(name)
|
248
|
+
|
249
|
+
subject_without_overrides_and_block
|
250
|
+
end
|
251
|
+
|
252
|
+
it_behaves_like "an endpoint template method composing a stub"
|
253
|
+
|
254
|
+
end
|
255
|
+
|
182
256
|
end
|
@@ -227,42 +227,14 @@ describe HttpStub::Configurer::DSL::Server do
|
|
227
227
|
subject
|
228
228
|
end
|
229
229
|
|
230
|
-
it "returns the created endpoint template" do
|
231
|
-
expect(subject).to eql(endpoint_template)
|
232
|
-
end
|
233
|
-
|
234
230
|
it "creates a template for the server" do
|
235
|
-
expect(HttpStub::Configurer::DSL::EndpointTemplate).to(
|
236
|
-
receive(:new).with(server, anything).and_return(endpoint_template)
|
237
|
-
)
|
231
|
+
expect(HttpStub::Configurer::DSL::EndpointTemplate).to receive(:new).with(server).and_return(endpoint_template)
|
238
232
|
|
239
233
|
subject
|
240
234
|
end
|
241
235
|
|
242
|
-
|
243
|
-
|
244
|
-
include_context "establish response defaults"
|
245
|
-
|
246
|
-
it "creates a template with the defaults" do
|
247
|
-
expect(HttpStub::Configurer::DSL::EndpointTemplate).to(
|
248
|
-
receive(:new).with(anything, response_defaults).and_return(endpoint_template)
|
249
|
-
)
|
250
|
-
|
251
|
-
subject
|
252
|
-
end
|
253
|
-
|
254
|
-
end
|
255
|
-
|
256
|
-
context "when no response defaults have been established" do
|
257
|
-
|
258
|
-
it "creates a template with empty response defaults" do
|
259
|
-
expect(HttpStub::Configurer::DSL::EndpointTemplate).to(
|
260
|
-
receive(:new).with(anything, {}).and_return(endpoint_template)
|
261
|
-
)
|
262
|
-
|
263
|
-
subject
|
264
|
-
end
|
265
|
-
|
236
|
+
it "returns the created endpoint template" do
|
237
|
+
expect(subject).to eql(endpoint_template)
|
266
238
|
end
|
267
239
|
|
268
240
|
end
|