http_stub 0.23.0 → 0.23.1
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/server/application.rb +3 -3
- data/lib/http_stub/server/stub/controller.rb +9 -6
- data/lib/http_stub/server/stub/match/result.rb +5 -4
- data/lib/http_stub/server/stub/registry.rb +3 -9
- data/lib/http_stub/server/views/_match.haml +1 -1
- data/lib/http_stub/server/views/_request.haml +5 -5
- data/lib/http_stub/server/views/_response.haml +4 -4
- data/lib/http_stub/server/views/_stub.haml +1 -1
- data/lib/http_stub/server/views/_text_response.haml +1 -1
- data/lib/http_stub/server/views/scenarios.haml +3 -3
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/stub_match_spec.rb +87 -17
- data/spec/lib/http_stub/server/stub/controller_spec.rb +50 -9
- data/spec/lib/http_stub/server/stub/match/result_spec.rb +12 -3
- data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +2 -3
- data/spec/lib/http_stub/server/stub/registry_spec.rb +4 -45
- data/spec/support/http_stub/server/stub/match/result_fixture.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce0263a68a9d4c8c707c93ee727ca7cd1f1388d3
|
4
|
+
data.tar.gz: fb4eacb144bf2a1c5444dd2338f1c7ec35e94fc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9e438b9879d87af9ebd28542529353c5b20bd802ba922143d4d0f56d395de6ce6eca492640731aa70209234061d3d3af879753ca767bd354ccf753e77f0ffab
|
7
|
+
data.tar.gz: fd634a047f29426b9d5dac4409b677bb978de7d54bdfea4bea7a54ad2a6d7b34d4eb35bb4f3743a395f995184042dfa61036a1120875264b665f09ff43bb2f19
|
@@ -21,10 +21,10 @@ module HttpStub
|
|
21
21
|
|
22
22
|
def initialize
|
23
23
|
super()
|
24
|
-
@
|
25
|
-
@stub_registry = HttpStub::Server::Stub::Registry.new(@match_result_registry)
|
24
|
+
@stub_registry = HttpStub::Server::Stub::Registry.new
|
26
25
|
@scenario_registry = HttpStub::Server::Registry.new("scenario")
|
27
|
-
@
|
26
|
+
@match_result_registry = HttpStub::Server::Registry.new("match result")
|
27
|
+
@stub_controller = HttpStub::Server::Stub::Controller.new(@stub_registry, @match_result_registry)
|
28
28
|
@scenario_controller = HttpStub::Server::Scenario::Controller.new(@scenario_registry, @stub_registry)
|
29
29
|
end
|
30
30
|
|
@@ -4,23 +4,26 @@ module HttpStub
|
|
4
4
|
|
5
5
|
class Controller
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(stub_registry, match_result_registry)
|
8
|
+
@stub_registry = stub_registry
|
9
|
+
@match_result_registry = match_result_registry
|
9
10
|
end
|
10
11
|
|
11
12
|
def register(request, logger)
|
12
13
|
stub = HttpStub::Server::Stub.create(HttpStub::Server::Stub::Parser.parse(request))
|
13
|
-
@
|
14
|
+
@stub_registry.add(stub, logger)
|
14
15
|
HttpStub::Server::Response.success("location" => stub.stub_uri)
|
15
16
|
end
|
16
17
|
|
17
18
|
def match(request, logger)
|
18
|
-
stub = @
|
19
|
-
stub ? stub.response_for(request) : HttpStub::Server::Response::NOT_FOUND
|
19
|
+
stub = @stub_registry.match(request, logger)
|
20
|
+
response = stub ? stub.response_for(request) : HttpStub::Server::Response::NOT_FOUND
|
21
|
+
@match_result_registry.add(HttpStub::Server::Stub::Match::Result.new(request, response, stub), logger)
|
22
|
+
response
|
20
23
|
end
|
21
24
|
|
22
25
|
def clear(logger)
|
23
|
-
@registry.clear(logger)
|
26
|
+
[ @stub_registry, @match_result_registry ].each { |registry| registry.clear(logger) }
|
24
27
|
end
|
25
28
|
|
26
29
|
end
|
@@ -5,11 +5,12 @@ module HttpStub
|
|
5
5
|
|
6
6
|
class Result
|
7
7
|
|
8
|
-
attr_reader :request, :stub
|
8
|
+
attr_reader :request, :response, :stub
|
9
9
|
|
10
|
-
def initialize(request, stub)
|
11
|
-
@request
|
12
|
-
@
|
10
|
+
def initialize(request, response, stub)
|
11
|
+
@request = request
|
12
|
+
@response = response
|
13
|
+
@stub = stub
|
13
14
|
end
|
14
15
|
|
15
16
|
end
|
@@ -4,16 +4,14 @@ module HttpStub
|
|
4
4
|
|
5
5
|
class Registry
|
6
6
|
|
7
|
-
delegate :add, :concat, :find, :all, to: :@stub_registry
|
7
|
+
delegate :add, :concat, :find, :all, :clear, to: :@stub_registry
|
8
8
|
|
9
|
-
def initialize
|
10
|
-
@
|
11
|
-
@stub_registry = HttpStub::Server::Registry.new("stub")
|
9
|
+
def initialize
|
10
|
+
@stub_registry = HttpStub::Server::Registry.new("stub")
|
12
11
|
end
|
13
12
|
|
14
13
|
def match(request, logger)
|
15
14
|
@stub_registry.find(request, logger).tap do |matched_stub|
|
16
|
-
@match_result_registry.add(HttpStub::Server::Stub::Match::Result.new(request, matched_stub), logger)
|
17
15
|
matched_stub.triggers.add_to(self, logger) if matched_stub
|
18
16
|
end
|
19
17
|
end
|
@@ -26,10 +24,6 @@ module HttpStub
|
|
26
24
|
@stub_registry.rollback_to(@remembered_stub) if @remembered_stub
|
27
25
|
end
|
28
26
|
|
29
|
-
def clear(logger)
|
30
|
-
[ @match_result_registry, @stub_registry ].each { |registry| registry.clear(logger) }
|
31
|
-
end
|
32
|
-
|
33
27
|
end
|
34
28
|
|
35
29
|
end
|
@@ -2,6 +2,6 @@
|
|
2
2
|
%h3 Request
|
3
3
|
= partial :request, locals: { request: match.request }
|
4
4
|
%h3 Response
|
5
|
-
=partial :response, locals: { response: match.
|
5
|
+
= partial :response, locals: { response: match.response }
|
6
6
|
%h3 Matched Stub
|
7
7
|
%a{ href: match.stub.stub_uri, class: [:stub, :link] } Match
|
@@ -1,16 +1,16 @@
|
|
1
1
|
%table
|
2
2
|
%tr
|
3
3
|
%td.title URI:
|
4
|
-
%td=h(request.uri)
|
4
|
+
%td= h(request.uri)
|
5
5
|
%tr
|
6
6
|
%td.title Method:
|
7
|
-
%td=request.method
|
7
|
+
%td= request.method
|
8
8
|
%tr
|
9
9
|
%td.title Headers:
|
10
|
-
%td=h(request.headers)
|
10
|
+
%td= h(request.headers)
|
11
11
|
%tr
|
12
12
|
%td.title Parameters:
|
13
|
-
%td=h(request.parameters)
|
13
|
+
%td= h(request.parameters)
|
14
14
|
%tr
|
15
15
|
%td.title Body:
|
16
|
-
%td=h(request.body)
|
16
|
+
%td= h(request.body)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
%table
|
2
2
|
%tr
|
3
3
|
%td.title Status:
|
4
|
-
%td=response.status
|
4
|
+
%td= response.status
|
5
5
|
%tr
|
6
6
|
%td.title Headers:
|
7
|
-
%td=h(response.headers)
|
7
|
+
%td= h(response.headers)
|
8
8
|
%tr
|
9
9
|
%td.title Body:
|
10
10
|
%td
|
11
|
-
%pre=partial "#{response.type}_response".to_sym, locals: { response: response }
|
11
|
+
%pre= partial "#{response.type}_response".to_sym, locals: { response: response }
|
12
12
|
%tr
|
13
13
|
%td.title Delay:
|
14
|
-
%td=h(response.delay_in_seconds)
|
14
|
+
%td= h(response.delay_in_seconds)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
%h3 Request
|
3
3
|
= partial :request, locals: { request: the_stub }
|
4
4
|
%h3 Response
|
5
|
-
=partial :response, locals: { response: the_stub.response }
|
5
|
+
= partial :response, locals: { response: the_stub.response }
|
6
6
|
%h3 Triggers
|
7
7
|
- the_stub.triggers.each do |trigger|
|
8
8
|
= partial :stub, locals: { the_stub: trigger }
|
@@ -1 +1 @@
|
|
1
|
-
=pp(response.body)
|
1
|
+
= pp(response.body)
|
@@ -4,9 +4,9 @@
|
|
4
4
|
%table{ class: :scenarios }
|
5
5
|
- scenarios.each do |scenario|
|
6
6
|
%tr
|
7
|
-
%td{ class: [:scenario_name, :
|
8
|
-
%td{ class: :
|
7
|
+
%td{ class: [:scenario_name, :"header-rule"] }= scenario.name
|
8
|
+
%td{ class: :"header-rule" }
|
9
9
|
%a{ href: scenario.links.activate, class: [:scenario, :link, :activate_scenario], data: { name: scenario.name } } Activate
|
10
|
-
%td{ class: :
|
10
|
+
%td{ class: :"header-rule" }
|
11
11
|
%a{ href: scenario.links.detail, class: [:scenario, :link, :view_scenario] } View Detail
|
12
12
|
= partial :activate_scenario
|
data/lib/http_stub/version.rb
CHANGED
@@ -18,7 +18,7 @@ describe "Stub match acceptance" do
|
|
18
18
|
let(:response) { HTTParty.get("#{server_uri}/http_stub/stubs/matches") }
|
19
19
|
let(:response_document) { Nokogiri::HTML(response.body) }
|
20
20
|
|
21
|
-
shared_context "
|
21
|
+
shared_context "builds a simple stub" do
|
22
22
|
|
23
23
|
let(:stub_response_status) { 203 }
|
24
24
|
let(:stub_response_headers) do
|
@@ -26,17 +26,34 @@ describe "Stub match acceptance" do
|
|
26
26
|
end
|
27
27
|
let(:stub_response_body) { "Stub response body" }
|
28
28
|
|
29
|
-
def register_stub
|
30
|
-
@register_stub_response = stub_server.add_stub!(build_stub)
|
31
|
-
end
|
32
|
-
|
33
29
|
def build_stub
|
34
30
|
stub_server.build_stub do |stub|
|
35
31
|
stub.match_requests(uri: request_uri, method: request_method,
|
36
32
|
headers: request_headers, parameters: request_parameters, body: request_body)
|
37
33
|
stub.respond_with(status: stub_response_status, headers: stub_response_headers, body: stub_response_body)
|
38
34
|
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
39
38
|
|
39
|
+
shared_context "registers a stub" do
|
40
|
+
|
41
|
+
def register_stub
|
42
|
+
@register_stub_response = stub_server.add_stub!(build_stub)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
shared_context "issues requests with parameters" do
|
48
|
+
|
49
|
+
let(:request_parameters) do
|
50
|
+
(1..3).reduce({}) { |result, i| result.tap { result["parameter_#{i}"] = "parameter value #{i}" } }
|
51
|
+
end
|
52
|
+
|
53
|
+
def issue_request
|
54
|
+
HTTParty.send(
|
55
|
+
request_method, "#{server_uri}#{request_uri}", headers: request_headers, query: request_parameters
|
56
|
+
)
|
40
57
|
end
|
41
58
|
|
42
59
|
end
|
@@ -59,22 +76,14 @@ describe "Stub match acceptance" do
|
|
59
76
|
|
60
77
|
context "when the request contains parameters" do
|
61
78
|
|
62
|
-
|
63
|
-
(1..3).reduce({}) { |result, i| result.tap { result["parameter_#{i}"] = "parameter value #{i}" } }
|
64
|
-
end
|
79
|
+
include_context "issues requests with parameters"
|
65
80
|
|
66
|
-
it "returns a response body that
|
81
|
+
it "returns a response body that contains the parameters" do
|
67
82
|
request_parameters.each do |expected_parameter_key, expected_parameter_value|
|
68
83
|
expect(response.body).to match(/#{expected_parameter_key}=#{expected_parameter_value}/)
|
69
84
|
end
|
70
85
|
end
|
71
86
|
|
72
|
-
def issue_request
|
73
|
-
HTTParty.send(
|
74
|
-
request_method, "#{server_uri}#{request_uri}", headers: request_headers, query: request_parameters
|
75
|
-
)
|
76
|
-
end
|
77
|
-
|
78
87
|
end
|
79
88
|
|
80
89
|
context "when the request contains a body" do
|
@@ -99,6 +108,7 @@ describe "Stub match acceptance" do
|
|
99
108
|
|
100
109
|
context "when a request has been made matching a stub" do
|
101
110
|
|
111
|
+
include_context "builds a simple stub"
|
102
112
|
include_context "registers a stub"
|
103
113
|
|
104
114
|
before(:example) do
|
@@ -132,8 +142,62 @@ describe "Stub match acceptance" do
|
|
132
142
|
expect(full_stub_uri).to end_with(stub_link["href"])
|
133
143
|
end
|
134
144
|
|
135
|
-
|
136
|
-
|
145
|
+
end
|
146
|
+
|
147
|
+
context "when a request has been made matching a stub whose response includes request references" do
|
148
|
+
|
149
|
+
include_context "registers a stub"
|
150
|
+
include_context "issues requests with parameters"
|
151
|
+
|
152
|
+
def build_stub
|
153
|
+
stub_server.build_stub do |stub|
|
154
|
+
stub.match_requests(uri: request_uri, method: request_method,
|
155
|
+
headers: request_headers, parameters: request_parameters)
|
156
|
+
stub.respond_with do |request|
|
157
|
+
{
|
158
|
+
status: 203,
|
159
|
+
headers: { header_reference: request.headers[:request_header_2],
|
160
|
+
parameter_reference: request.parameters[:parameter_2] },
|
161
|
+
body: "header: #{request.headers[:request_header_3]}, parameter: #{request.parameters[:parameter_3]}"
|
162
|
+
}
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
before(:example) do
|
168
|
+
register_stub
|
169
|
+
|
170
|
+
issue_request
|
171
|
+
end
|
172
|
+
|
173
|
+
it "returns a response body that indicates the request matched a stub" do
|
174
|
+
expect(response.body).to include("Match")
|
175
|
+
end
|
176
|
+
|
177
|
+
it "returns a response body that contains stub response status" do
|
178
|
+
expect(response.body).to match(/203/)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "returns a response body that contains stub response headers with interpolated request references" do
|
182
|
+
expected_stub_response_headers = {
|
183
|
+
header_reference: "request header value 2",
|
184
|
+
parameter_reference: "parameter value 2"
|
185
|
+
}
|
186
|
+
|
187
|
+
expected_stub_response_headers.each do |expected_header_key, expected_header_value|
|
188
|
+
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it "returns a response body that contains stub response body with interpolated request references" do
|
193
|
+
expected_stub_response_body = "header: request header value 3, parameter: parameter value 3"
|
194
|
+
|
195
|
+
expect(response.body).to match(/#{escape_html(expected_stub_response_body)}/)
|
196
|
+
end
|
197
|
+
|
198
|
+
it "returns a response body that contains a link to the matched stub" do
|
199
|
+
stub_link = response_document.css("a.stub").first
|
200
|
+
expect(full_stub_uri).to end_with(stub_link["href"])
|
137
201
|
end
|
138
202
|
|
139
203
|
end
|
@@ -152,6 +216,7 @@ describe "Stub match acceptance" do
|
|
152
216
|
|
153
217
|
context "when a request has been made configuring a stub" do
|
154
218
|
|
219
|
+
include_context "builds a simple stub"
|
155
220
|
include_context "registers a stub"
|
156
221
|
|
157
222
|
before(:example) { register_stub }
|
@@ -164,6 +229,7 @@ describe "Stub match acceptance" do
|
|
164
229
|
|
165
230
|
context "when a request has been made configuring a scenario" do
|
166
231
|
|
232
|
+
include_context "builds a simple stub"
|
167
233
|
include_context "registers a stub"
|
168
234
|
|
169
235
|
before(:example) { register_scenario }
|
@@ -178,6 +244,10 @@ describe "Stub match acceptance" do
|
|
178
244
|
|
179
245
|
end
|
180
246
|
|
247
|
+
def full_stub_uri
|
248
|
+
@register_stub_response.header["location"]
|
249
|
+
end
|
250
|
+
|
181
251
|
end
|
182
252
|
|
183
253
|
end
|
@@ -6,9 +6,11 @@ describe HttpStub::Server::Stub::Controller do
|
|
6
6
|
let(:response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
7
7
|
let(:stub_uri) { "/some/stub/uri" }
|
8
8
|
let(:the_stub) { instance_double(HttpStub::Server::Stub::Stub, response: response, stub_uri: stub_uri) }
|
9
|
-
let(:registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
|
10
9
|
|
11
|
-
let(:
|
10
|
+
let(:stub_registry) { instance_double(HttpStub::Server::Stub::Registry).as_null_object }
|
11
|
+
let(:match_result_registry) { instance_double(HttpStub::Server::Registry).as_null_object }
|
12
|
+
|
13
|
+
let(:controller) { HttpStub::Server::Stub::Controller.new(stub_registry, match_result_registry) }
|
12
14
|
|
13
15
|
before(:example) do
|
14
16
|
allow(HttpStub::Server::Stub::Parser).to receive(:parse).and_return(payload)
|
@@ -32,7 +34,7 @@ describe HttpStub::Server::Stub::Controller do
|
|
32
34
|
end
|
33
35
|
|
34
36
|
it "adds the stub to the stub registry" do
|
35
|
-
expect(
|
37
|
+
expect(stub_registry).to receive(:add).with(the_stub, logger)
|
36
38
|
|
37
39
|
subject
|
38
40
|
end
|
@@ -54,9 +56,15 @@ describe HttpStub::Server::Stub::Controller do
|
|
54
56
|
|
55
57
|
describe "#match" do
|
56
58
|
|
59
|
+
let(:calculated_stub_response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
60
|
+
|
57
61
|
subject { controller.match(request, logger) }
|
58
62
|
|
59
|
-
before(:example)
|
63
|
+
before(:example) do
|
64
|
+
allow(stub_registry).to receive(:match).with(request, logger).and_return(matched_stub)
|
65
|
+
allow(the_stub).to receive(:response_for).and_return(calculated_stub_response)
|
66
|
+
allow(match_result_registry).to receive(:add)
|
67
|
+
end
|
60
68
|
|
61
69
|
describe "when a stub has been registered that matches the request" do
|
62
70
|
|
@@ -68,11 +76,22 @@ describe HttpStub::Server::Stub::Controller do
|
|
68
76
|
subject
|
69
77
|
end
|
70
78
|
|
71
|
-
it "
|
72
|
-
|
73
|
-
|
79
|
+
it "determines the match result for the request, calculated response and stub" do
|
80
|
+
expect(HttpStub::Server::Stub::Match::Result).to receive(:new).with(request, calculated_stub_response, the_stub)
|
81
|
+
|
82
|
+
subject
|
83
|
+
end
|
84
|
+
|
85
|
+
it "adds the match result to the match result registry" do
|
86
|
+
expect(match_result_registry).to(
|
87
|
+
receive(:add).with(an_instance_of(HttpStub::Server::Stub::Match::Result), logger)
|
88
|
+
)
|
89
|
+
|
90
|
+
subject
|
91
|
+
end
|
74
92
|
|
75
|
-
|
93
|
+
it "returns the calculated response" do
|
94
|
+
expect(subject).to eql(calculated_stub_response)
|
76
95
|
end
|
77
96
|
|
78
97
|
end
|
@@ -85,6 +104,22 @@ describe HttpStub::Server::Stub::Controller do
|
|
85
104
|
expect(subject).to eql(HttpStub::Server::Response::NOT_FOUND)
|
86
105
|
end
|
87
106
|
|
107
|
+
it "creates a match result for request with the not found response and no stub" do
|
108
|
+
expect(HttpStub::Server::Stub::Match::Result).to(
|
109
|
+
receive(:new).with(request, HttpStub::Server::Response::NOT_FOUND, nil)
|
110
|
+
)
|
111
|
+
|
112
|
+
subject
|
113
|
+
end
|
114
|
+
|
115
|
+
it "adds the match result to the match result registry" do
|
116
|
+
expect(match_result_registry).to(
|
117
|
+
receive(:add).with(an_instance_of(HttpStub::Server::Stub::Match::Result), logger)
|
118
|
+
)
|
119
|
+
|
120
|
+
subject
|
121
|
+
end
|
122
|
+
|
88
123
|
end
|
89
124
|
|
90
125
|
end
|
@@ -94,7 +129,13 @@ describe HttpStub::Server::Stub::Controller do
|
|
94
129
|
subject { controller.clear(logger) }
|
95
130
|
|
96
131
|
it "clears the stub registry" do
|
97
|
-
expect(
|
132
|
+
expect(stub_registry).to receive(:clear).with(logger)
|
133
|
+
|
134
|
+
subject
|
135
|
+
end
|
136
|
+
|
137
|
+
it "clears the match result registry" do
|
138
|
+
expect(match_result_registry).to receive(:clear).with(logger)
|
98
139
|
|
99
140
|
subject
|
100
141
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
describe HttpStub::Server::Stub::Match::Result do
|
2
2
|
|
3
|
-
let(:request)
|
4
|
-
let(:
|
3
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request) }
|
4
|
+
let(:response) { instance_double(HttpStub::Server::Stub::Response::Base) }
|
5
|
+
let(:stub) { instance_double(HttpStub::Server::Stub::Stub) }
|
5
6
|
|
6
|
-
let(:stub_match) { HttpStub::Server::Stub::Match::Result.new(request, stub) }
|
7
|
+
let(:stub_match) { HttpStub::Server::Stub::Match::Result.new(request, response, stub) }
|
7
8
|
|
8
9
|
describe "#request" do
|
9
10
|
|
@@ -13,6 +14,14 @@ describe HttpStub::Server::Stub::Match::Result do
|
|
13
14
|
|
14
15
|
end
|
15
16
|
|
17
|
+
describe "#response" do
|
18
|
+
|
19
|
+
it "exposes the provided value" do
|
20
|
+
expect(stub_match.response).to eql(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
16
25
|
describe "#stub" do
|
17
26
|
|
18
27
|
it "exposes the provided value" do
|
@@ -1,9 +1,8 @@
|
|
1
1
|
describe HttpStub::Server::Stub::Registry, "integrating with real stubs" do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:logger) { instance_double(Logger, info: nil) }
|
3
|
+
let(:logger) { instance_double(Logger, info: nil) }
|
5
4
|
|
6
|
-
let(:stub_registry) { HttpStub::Server::Stub::Registry.new
|
5
|
+
let(:stub_registry) { HttpStub::Server::Stub::Registry.new }
|
7
6
|
|
8
7
|
describe "#recall" do
|
9
8
|
|
@@ -1,11 +1,10 @@
|
|
1
1
|
describe HttpStub::Server::Stub::Registry do
|
2
2
|
|
3
|
-
let(:match_result_registry) { instance_double(HttpStub::Server::Registry) }
|
4
3
|
let(:underlying_stub_registry) { instance_double(HttpStub::Server::Registry) }
|
5
4
|
|
6
5
|
let(:logger) { instance_double(Logger) }
|
7
6
|
|
8
|
-
let(:stub_registry) { HttpStub::Server::Stub::Registry.new
|
7
|
+
let(:stub_registry) { HttpStub::Server::Stub::Registry.new }
|
9
8
|
|
10
9
|
before(:example) { allow(HttpStub::Server::Registry).to receive(:new).and_return(underlying_stub_registry) }
|
11
10
|
|
@@ -58,15 +57,10 @@ describe HttpStub::Server::Stub::Registry do
|
|
58
57
|
let(:triggers) { instance_double(HttpStub::Server::Stub::Triggers, add_to: nil) }
|
59
58
|
let(:stub) { instance_double(HttpStub::Server::Stub::Stub, triggers: triggers) }
|
60
59
|
let(:found_stub) { nil }
|
61
|
-
let(:match_result) { instance_double(HttpStub::Server::Stub::Match::Result) }
|
62
60
|
|
63
61
|
subject { stub_registry.match(request, logger) }
|
64
62
|
|
65
|
-
before(:example)
|
66
|
-
allow(underlying_stub_registry).to receive(:find).and_return(found_stub)
|
67
|
-
allow(HttpStub::Server::Stub::Match::Result).to receive(:new).and_return(match_result)
|
68
|
-
allow(match_result_registry).to receive(:add)
|
69
|
-
end
|
63
|
+
before(:example) { allow(underlying_stub_registry).to receive(:find).and_return(found_stub) }
|
70
64
|
|
71
65
|
it "finds a matching stub in the underlying simple registry based on the request" do
|
72
66
|
expect(underlying_stub_registry).to receive(:find).with(request, logger)
|
@@ -78,18 +72,6 @@ describe HttpStub::Server::Stub::Registry do
|
|
78
72
|
|
79
73
|
let(:found_stub) { stub }
|
80
74
|
|
81
|
-
it "creates a match containing the request and the stub" do
|
82
|
-
expect(HttpStub::Server::Stub::Match::Result).to receive(:new).with(request, stub)
|
83
|
-
|
84
|
-
subject
|
85
|
-
end
|
86
|
-
|
87
|
-
it "adds the match result to the match result registry" do
|
88
|
-
expect(match_result_registry).to receive(:add).with(match_result, logger)
|
89
|
-
|
90
|
-
subject
|
91
|
-
end
|
92
|
-
|
93
75
|
it "adds the stubs triggers to the underlying stub registry" do
|
94
76
|
expect(triggers).to receive(:add_to).with(stub_registry, logger)
|
95
77
|
|
@@ -106,19 +88,7 @@ describe HttpStub::Server::Stub::Registry do
|
|
106
88
|
|
107
89
|
let(:found_stub) { nil }
|
108
90
|
|
109
|
-
it "
|
110
|
-
expect(HttpStub::Server::Stub::Match::Result).to receive(:new).with(request, nil)
|
111
|
-
|
112
|
-
subject
|
113
|
-
end
|
114
|
-
|
115
|
-
it "adds the match result to the match result registry" do
|
116
|
-
expect(match_result_registry).to receive(:add).with(match_result, logger)
|
117
|
-
|
118
|
-
subject
|
119
|
-
end
|
120
|
-
|
121
|
-
it "returns the result from the underlying registry" do
|
91
|
+
it "returns nil" do
|
122
92
|
expect(subject).to eql(nil)
|
123
93
|
end
|
124
94
|
|
@@ -183,23 +153,12 @@ describe HttpStub::Server::Stub::Registry do
|
|
183
153
|
|
184
154
|
subject { stub_registry.clear(logger) }
|
185
155
|
|
186
|
-
|
187
|
-
allow(underlying_stub_registry).to receive(:clear)
|
188
|
-
allow(match_result_registry).to receive(:clear)
|
189
|
-
end
|
190
|
-
|
191
|
-
it "clears the underlying simple registry" do
|
156
|
+
it "delegates to the underlying simple registry" do
|
192
157
|
expect(underlying_stub_registry).to receive(:clear).with(logger)
|
193
158
|
|
194
159
|
subject
|
195
160
|
end
|
196
161
|
|
197
|
-
it "clears the match result registry" do
|
198
|
-
expect(match_result_registry).to receive(:clear).with(logger)
|
199
|
-
|
200
|
-
subject
|
201
|
-
end
|
202
|
-
|
203
162
|
end
|
204
163
|
|
205
164
|
end
|
@@ -6,7 +6,9 @@ module HttpStub
|
|
6
6
|
class ResultFixture
|
7
7
|
|
8
8
|
def self.empty
|
9
|
-
HttpStub::Server::Stub::Match::Result.new(
|
9
|
+
HttpStub::Server::Stub::Match::Result.new(
|
10
|
+
HttpStub::Server::RequestFixture.create, HttpStub::Server::Response::NOT_FOUND, nil
|
11
|
+
)
|
10
12
|
end
|
11
13
|
|
12
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_stub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.23.
|
4
|
+
version: 0.23.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dueckes
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2016-05-
|
15
|
+
date: 2016-05-30 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rake
|