http_stub 0.14.0.rc1 → 0.14.0.rc2
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/stub_activator_payload_builder.rb +1 -1
- data/lib/http_stub/configurer/request/stub_payload_builder.rb +4 -0
- data/lib/http_stub/configurer/server/dsl.rb +4 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +12 -0
- data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +24 -3
- data/spec/lib/http_stub/configurer/server/dsl_spec.rb +48 -1
- data/spec/lib/http_stub/configurer_integration_spec.rb +1 -1
- 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: 6d5d1e764366bda9d5f710c4938843dd56cfe795
|
4
|
+
data.tar.gz: e45dbffa5460da77bb50c24bf57eea45a43afe95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e2c3a0c793fb39fe1a6c1ab1a88de29da1f086370b0e98836f8366b5ad523ccc228a4ca2fa208bcd2576ac8eb27fe8f8689cd247c9b2a12c224c310491503e9
|
7
|
+
data.tar.gz: 7e8282e64d9ad2c8e627ebe5ceffcbeb8df653cdd5f9915bab7a4b17ae28bbdf003376fbf9fa8088fc7688d30e88a6e274c525eb5e75fd6e3e827af7b2908e5d
|
@@ -4,7 +4,7 @@ module HttpStub
|
|
4
4
|
|
5
5
|
class StubActivatorPayloadBuilder
|
6
6
|
|
7
|
-
delegate :match_request, :with_response, :and_add_stub, to: :@stub_payload_builder
|
7
|
+
delegate :match_request, :with_response, :and_add_stub, :and_add_stubs, to: :@stub_payload_builder
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@stub_payload_builder = HttpStub::Configurer::Request::StubPayloadBuilder.new
|
@@ -23,6 +23,10 @@ module HttpStub
|
|
23
23
|
@server_facade.stub_response(HttpStub::Configurer::Request::Stub.new(resolved_builder.build))
|
24
24
|
end
|
25
25
|
|
26
|
+
def add_stubs!(builders)
|
27
|
+
builders.each { |builder| add_stub!(builder) }
|
28
|
+
end
|
29
|
+
|
26
30
|
def add_activator!(&block)
|
27
31
|
builder = HttpStub::Configurer::Request::StubActivatorPayloadBuilder.new
|
28
32
|
block.call(builder)
|
data/lib/http_stub/version.rb
CHANGED
@@ -43,6 +43,18 @@ describe HttpStub::Configurer::Request::StubActivatorPayloadBuilder do
|
|
43
43
|
|
44
44
|
end
|
45
45
|
|
46
|
+
describe "#and_add_stubs" do
|
47
|
+
|
48
|
+
let(:trigger_builders) { (1..3).map { instance_double(HttpStub::Configurer::Request::StubPayloadBuilder) } }
|
49
|
+
|
50
|
+
it "delegates to a stub payload builder" do
|
51
|
+
expect(stub_builder).to receive(:and_add_stubs).with(trigger_builders)
|
52
|
+
|
53
|
+
builder.and_add_stubs(trigger_builders)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
46
58
|
describe "#build" do
|
47
59
|
|
48
60
|
subject { builder.build }
|
@@ -2,6 +2,17 @@ describe HttpStub::Configurer::Request::StubPayloadBuilder do
|
|
2
2
|
|
3
3
|
let(:builder) { HttpStub::Configurer::Request::StubPayloadBuilder.new }
|
4
4
|
|
5
|
+
shared_context "add stub trigger" do
|
6
|
+
|
7
|
+
let(:trigger_payload) { { "trigger_key" => "trigger value" } }
|
8
|
+
let(:trigger_builder) do
|
9
|
+
instance_double(HttpStub::Configurer::Request::StubPayloadBuilder, build: trigger_payload)
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:example) { builder.and_add_stub(trigger_builder) }
|
13
|
+
|
14
|
+
end
|
15
|
+
|
5
16
|
shared_context "add stub triggers" do
|
6
17
|
|
7
18
|
let(:trigger_payloads) { (1..3).map { |i| { "trigger_#{i}_key" => "trigger #{i} value" } } }
|
@@ -11,13 +22,13 @@ describe HttpStub::Configurer::Request::StubPayloadBuilder do
|
|
11
22
|
end
|
12
23
|
end
|
13
24
|
|
14
|
-
before(:example) {
|
25
|
+
before(:example) { builder.and_add_stubs(trigger_builders) }
|
15
26
|
|
16
27
|
end
|
17
28
|
|
18
29
|
describe "#build" do
|
19
30
|
|
20
|
-
context "when provided a
|
31
|
+
context "when provided a request match and response data" do
|
21
32
|
|
22
33
|
include_context "stub payload builder arguments"
|
23
34
|
|
@@ -176,8 +187,18 @@ describe HttpStub::Configurer::Request::StubPayloadBuilder do
|
|
176
187
|
|
177
188
|
end
|
178
189
|
|
179
|
-
context "when stub
|
190
|
+
context "when a stub trigger is added" do
|
180
191
|
|
192
|
+
include_context "add stub trigger"
|
193
|
+
|
194
|
+
it "has a triggers entry containing the stub trigger payload" do
|
195
|
+
expect(subject).to include(triggers: [ trigger_payload ])
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
context "when stub triggers are added" do
|
201
|
+
|
181
202
|
include_context "add stub triggers"
|
182
203
|
|
183
204
|
it "has a triggers entry containing the stub trigger payloads" do
|
@@ -85,7 +85,7 @@ describe HttpStub::Configurer::Server::DSL do
|
|
85
85
|
subject
|
86
86
|
end
|
87
87
|
|
88
|
-
it "informs the server facade
|
88
|
+
it "informs the server facade of the stub request" do
|
89
89
|
expect(server_facade).to receive(:stub_response).with(stub_request)
|
90
90
|
|
91
91
|
subject
|
@@ -129,6 +129,53 @@ describe HttpStub::Configurer::Server::DSL do
|
|
129
129
|
|
130
130
|
end
|
131
131
|
|
132
|
+
describe "#add_stubs!" do
|
133
|
+
|
134
|
+
context "when multiple stub payload builders are provided" do
|
135
|
+
|
136
|
+
let(:stub_payloads) { (1..3).map { |i| { "stub_payload_key_#{i}" => "stub payload value #{i}" } } }
|
137
|
+
let(:stub_payload_builders) do
|
138
|
+
stub_payloads.map do |payload|
|
139
|
+
instance_double(HttpStub::Configurer::Request::StubPayloadBuilder, build: payload)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
let(:stub_requests) do
|
143
|
+
(1..stub_payloads.length).map { instance_double(HttpStub::Configurer::Request::Stub) }
|
144
|
+
end
|
145
|
+
|
146
|
+
subject { dsl.add_stubs!(stub_payload_builders) }
|
147
|
+
|
148
|
+
before(:example) do
|
149
|
+
allow(HttpStub::Configurer::Request::Stub).to receive(:new).and_return(*stub_requests)
|
150
|
+
allow(server_facade).to receive(:stub_response)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "builds the each stub payload" do
|
154
|
+
stub_payload_builders.zip(stub_payloads).each do |stub_payload_builder, stub_payload|
|
155
|
+
expect(stub_payload_builder).to receive(:build).and_return(stub_payload)
|
156
|
+
end
|
157
|
+
|
158
|
+
subject
|
159
|
+
end
|
160
|
+
|
161
|
+
it "creates a stub request for each built payload" do
|
162
|
+
stub_payloads.zip(stub_requests).each do |stub_payload, stub_request|
|
163
|
+
expect(HttpStub::Configurer::Request::Stub).to receive(:new).with(stub_payload).and_return(stub_request)
|
164
|
+
end
|
165
|
+
|
166
|
+
subject
|
167
|
+
end
|
168
|
+
|
169
|
+
it "informs the server facade of each stub request" do
|
170
|
+
stub_requests.each { |stub_request| expect(server_facade).to receive(:stub_response).with(stub_request) }
|
171
|
+
|
172
|
+
subject
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
132
179
|
describe "#add_activator!" do
|
133
180
|
|
134
181
|
let(:stub_activator_payload) { { activator_payload_key: "activator payload value" } }
|
@@ -510,7 +510,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
510
510
|
stub_server.add_stub! do |stub|
|
511
511
|
stub.match_request("/stub_with_triggers", method: :get)
|
512
512
|
stub.with_response(body: "Trigger stub body")
|
513
|
-
|
513
|
+
stub.and_add_stubs(triggers)
|
514
514
|
end
|
515
515
|
end
|
516
516
|
|