http_stub 0.24.3 → 0.25.0
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.rb +8 -2
- data/lib/http_stub/server/application/application.rb +16 -4
- data/lib/http_stub/server/request/request.rb +6 -1
- data/lib/http_stub/server/response.rb +5 -3
- data/lib/http_stub/server/scenario/controller.rb +2 -2
- data/lib/http_stub/server/scenario/parser.rb +1 -3
- data/lib/http_stub/server/stub/controller.rb +8 -6
- data/lib/http_stub/server/stub/empty.rb +9 -5
- data/lib/http_stub/server/stub/match/controller.rb +22 -0
- data/lib/http_stub/server/stub/match/{result.rb → match.rb} +9 -1
- data/lib/http_stub/server/stub/match/miss.rb +19 -0
- data/lib/http_stub/server/stub/match/rules.rb +33 -0
- data/lib/http_stub/server/stub/parser.rb +1 -1
- data/lib/http_stub/server/stub/payload.rb +20 -0
- data/lib/http_stub/server/stub/payload/base_uri_modifier.rb +17 -0
- data/lib/http_stub/server/stub/payload/response_body_modifier.rb +19 -0
- data/lib/http_stub/server/stub/response/base.rb +5 -1
- data/lib/http_stub/server/stub/response/file.rb +5 -0
- data/lib/http_stub/server/stub/response/text.rb +4 -0
- data/lib/http_stub/server/stub/stub.rb +8 -18
- data/lib/http_stub/server/stub/triggers.rb +1 -1
- data/lib/http_stub/server/views/_activate_scenario.haml +17 -4
- data/lib/http_stub/server/views/_stub.haml +2 -2
- data/lib/http_stub/server/views/{_match.haml → _stub_match.haml} +1 -1
- data/lib/http_stub/server/views/_stub_miss.haml +3 -0
- data/lib/http_stub/server/views/index.haml +4 -2
- data/lib/http_stub/server/views/stub_matches.haml +4 -0
- data/lib/http_stub/server/views/stub_misses.haml +4 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/stub_match_last_spec.rb +170 -0
- data/spec/acceptance/stub_match_list_spec.rb +115 -0
- data/spec/acceptance/stub_miss_list_spec.rb +58 -0
- data/spec/lib/http_stub/server/application/application_spec.rb +57 -13
- data/spec/lib/http_stub/server/request/request_spec.rb +41 -1
- data/spec/lib/http_stub/server/response_spec.rb +18 -12
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +4 -4
- data/spec/lib/http_stub/server/scenario/parser_spec.rb +30 -27
- data/spec/lib/http_stub/server/stub/controller_spec.rb +45 -26
- data/spec/lib/http_stub/server/stub/empty_spec.rb +14 -14
- data/spec/lib/http_stub/server/stub/match/controller_spec.rb +69 -0
- data/spec/lib/http_stub/server/stub/match/match_spec.rb +146 -0
- data/spec/lib/http_stub/server/stub/match/miss_spec.rb +15 -0
- data/spec/lib/http_stub/server/stub/match/rules_spec.rb +247 -0
- data/spec/lib/http_stub/server/stub/parser_spec.rb +12 -14
- data/spec/lib/http_stub/server/stub/payload/base_uri_modifier_spec.rb +23 -0
- data/spec/lib/http_stub/server/{payload_file_consolidator_spec.rb → stub/payload/response_body_modifier_spec.rb} +22 -14
- data/spec/lib/http_stub/server/stub/payload_spec.rb +33 -0
- data/spec/lib/http_stub/server/stub/response/base_spec.rb +22 -0
- data/spec/lib/http_stub/server/stub/response/file_spec.rb +29 -1
- data/spec/lib/http_stub/server/stub/response/text_spec.rb +18 -0
- data/spec/lib/http_stub/server/stub/stub_spec.rb +48 -145
- data/spec/lib/http_stub/server/stub/triggers_spec.rb +14 -0
- data/spec/spec_helper.rb +7 -3
- data/spec/support/{configurer_integration.rb → http_stub/configurer_integration.rb} +3 -2
- data/spec/support/http_stub/html_view_excluding_request_details.rb +11 -0
- data/spec/support/http_stub/html_view_including_request_details.rb +47 -0
- data/spec/support/http_stub/server/scenario/scenario_fixture.rb +1 -1
- data/spec/support/http_stub/server/stub/match/match_fixture.rb +21 -0
- data/spec/support/http_stub/server/stub/match/miss_fixture.rb +17 -0
- data/spec/support/{server_integration.rb → http_stub/server_integration.rb} +0 -0
- data/spec/support/http_stub/stub_fixture.rb +1 -0
- data/spec/support/http_stub/stub_registrator.rb +83 -0
- metadata +47 -19
- data/lib/http_stub/server/stub/payload_file_consolidator.rb +0 -18
- data/lib/http_stub/server/views/_miss.haml +0 -7
- data/lib/http_stub/server/views/match_results.haml +0 -7
- data/spec/acceptance/stub_match_spec.rb +0 -252
- data/spec/lib/http_stub/server/stub/match/result_spec.rb +0 -33
- data/spec/support/http_stub/server/stub/match/result_fixture.rb +0 -19
@@ -1,18 +0,0 @@
|
|
1
|
-
module HttpStub
|
2
|
-
module Server
|
3
|
-
module Stub
|
4
|
-
|
5
|
-
class PayloadFileConsolidator
|
6
|
-
|
7
|
-
def self.consolidate!(payload, request)
|
8
|
-
response_file = request.parameters["response_file_#{payload["id"]}"]
|
9
|
-
payload["response"]["body"] = response_file if response_file
|
10
|
-
payload["triggers"].each { |trigger_payload| consolidate!(trigger_payload, request) } if payload["triggers"]
|
11
|
-
payload
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,252 +0,0 @@
|
|
1
|
-
describe "Stub match acceptance" do
|
2
|
-
include_context "configurer integration"
|
3
|
-
|
4
|
-
before(:example) { configurer.initialize! }
|
5
|
-
|
6
|
-
after(:example) { configurer.clear_stubs! }
|
7
|
-
|
8
|
-
describe "GET /http_stub/stubs/matches" do
|
9
|
-
|
10
|
-
let(:request_uri) { "/some/uri" }
|
11
|
-
let(:request_method) { :get }
|
12
|
-
let(:request_headers) do
|
13
|
-
(1..3).reduce({}) { |result, i| result.tap { result["request_header_#{i}"] = "request header value #{i}" } }
|
14
|
-
end
|
15
|
-
let(:request_parameters) { {} }
|
16
|
-
let(:request_body) { nil }
|
17
|
-
|
18
|
-
let(:response) { HTTParty.get("#{server_uri}/http_stub/stubs/matches") }
|
19
|
-
let(:response_document) { Nokogiri::HTML(response.body) }
|
20
|
-
|
21
|
-
shared_context "builds a simple stub" do
|
22
|
-
|
23
|
-
let(:stub_response_status) { 203 }
|
24
|
-
let(:stub_response_headers) do
|
25
|
-
(1..3).reduce({}) { |result, i| result.tap { result["response_header_#{i}"] = "response header value #{i}" } }
|
26
|
-
end
|
27
|
-
let(:stub_response_body) { "Stub response body" }
|
28
|
-
|
29
|
-
def build_stub
|
30
|
-
stub_server.build_stub do |stub|
|
31
|
-
stub.match_requests(uri: request_uri, method: request_method,
|
32
|
-
headers: request_headers, parameters: request_parameters, body: request_body)
|
33
|
-
stub.respond_with(status: stub_response_status, headers: stub_response_headers, body: stub_response_body)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
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
|
-
)
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
shared_context "issues requests of various types" do
|
62
|
-
|
63
|
-
it "returns a response body that contains the uri of the request" do
|
64
|
-
expect(response.body).to match(/#{escape_html(request_uri)}/)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "returns a response body that contains the method of the request" do
|
68
|
-
expect(response.body).to match(/#{escape_html(request_method)}/)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "returns a response body that contains the headers of the request whose names are in uppercase" do
|
72
|
-
request_headers.each do |expected_header_key, expected_header_value|
|
73
|
-
expect(response.body).to match(/#{expected_header_key.upcase}:#{expected_header_value}/)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when the request contains parameters" do
|
78
|
-
include_context "issues requests with parameters"
|
79
|
-
|
80
|
-
it "returns a response body that contains the parameters" do
|
81
|
-
request_parameters.each do |expected_parameter_key, expected_parameter_value|
|
82
|
-
expect(response.body).to match(/#{expected_parameter_key}=#{expected_parameter_value}/)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
context "when the request contains a body" do
|
89
|
-
|
90
|
-
let(:request_body) { "Some <strong>request body</strong>" }
|
91
|
-
|
92
|
-
it "returns a response body that contains the body" do
|
93
|
-
expect(response.body).to match(/#{escape_html(request_body)}/)
|
94
|
-
end
|
95
|
-
|
96
|
-
def issue_request
|
97
|
-
HTTParty.send(request_method, "#{server_uri}#{request_uri}", headers: request_headers, body: request_body)
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
def issue_request
|
103
|
-
HTTParty.send(request_method, "#{server_uri}#{request_uri}", headers: request_headers)
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
context "when a request has been made matching a stub" do
|
109
|
-
|
110
|
-
include_context "builds a simple stub"
|
111
|
-
include_context "registers a stub"
|
112
|
-
|
113
|
-
before(:example) do
|
114
|
-
register_stub
|
115
|
-
|
116
|
-
issue_request
|
117
|
-
end
|
118
|
-
|
119
|
-
include_context "issues requests of various types"
|
120
|
-
|
121
|
-
it "returns a response body that indicates the request matched a stub" do
|
122
|
-
expect(response.body).to include("Match")
|
123
|
-
end
|
124
|
-
|
125
|
-
it "returns a response body that contains stub response status" do
|
126
|
-
expect(response.body).to match(/#{escape_html(stub_response_status)}/)
|
127
|
-
end
|
128
|
-
|
129
|
-
it "returns a response body that contains stub response headers" do
|
130
|
-
stub_response_headers.each do |expected_header_key, expected_header_value|
|
131
|
-
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
it "returns a response body that contains stub response body" do
|
136
|
-
expect(response.body).to match(/#{escape_html(stub_response_body)}/)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "returns a response body that contains a link to the matched stub" do
|
140
|
-
stub_link = response_document.css("a.stub").first
|
141
|
-
expect(full_stub_uri).to end_with(stub_link["href"])
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
context "when a request has been made matching a stub whose response includes request references" do
|
147
|
-
|
148
|
-
include_context "registers a stub"
|
149
|
-
include_context "issues requests with parameters"
|
150
|
-
|
151
|
-
def build_stub
|
152
|
-
stub_server.build_stub do |stub|
|
153
|
-
stub.match_requests(uri: request_uri, method: request_method,
|
154
|
-
headers: request_headers, parameters: request_parameters)
|
155
|
-
stub.respond_with do |request|
|
156
|
-
{
|
157
|
-
status: 203,
|
158
|
-
headers: { header_reference: request.headers[:request_header_2],
|
159
|
-
parameter_reference: request.parameters[:parameter_2] },
|
160
|
-
body: "header: #{request.headers[:request_header_3]}, parameter: #{request.parameters[:parameter_3]}"
|
161
|
-
}
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
before(:example) do
|
167
|
-
register_stub
|
168
|
-
|
169
|
-
issue_request
|
170
|
-
end
|
171
|
-
|
172
|
-
it "returns a response body that indicates the request matched a stub" do
|
173
|
-
expect(response.body).to include("Match")
|
174
|
-
end
|
175
|
-
|
176
|
-
it "returns a response body that contains stub response status" do
|
177
|
-
expect(response.body).to match(/203/)
|
178
|
-
end
|
179
|
-
|
180
|
-
it "returns a response body that contains stub response headers with interpolated request references" do
|
181
|
-
expected_stub_response_headers = {
|
182
|
-
header_reference: "request header value 2",
|
183
|
-
parameter_reference: "parameter value 2"
|
184
|
-
}
|
185
|
-
|
186
|
-
expected_stub_response_headers.each do |expected_header_key, expected_header_value|
|
187
|
-
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
it "returns a response body that contains stub response body with interpolated request references" do
|
192
|
-
expected_stub_response_body = "header: request header value 3, parameter: parameter value 3"
|
193
|
-
|
194
|
-
expect(response.body).to match(/#{escape_html(expected_stub_response_body)}/)
|
195
|
-
end
|
196
|
-
|
197
|
-
it "returns a response body that contains a link to the matched stub" do
|
198
|
-
stub_link = response_document.css("a.stub").first
|
199
|
-
expect(full_stub_uri).to end_with(stub_link["href"])
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
context "when a request has been made that does not match a stub" do
|
205
|
-
|
206
|
-
before(:example) { issue_request }
|
207
|
-
|
208
|
-
include_context "issues requests of various types"
|
209
|
-
|
210
|
-
it "returns a response body that indicates the request did not match a stub" do
|
211
|
-
expect(response.body).to include("Miss")
|
212
|
-
end
|
213
|
-
|
214
|
-
end
|
215
|
-
|
216
|
-
context "when a request has been made configuring a stub" do
|
217
|
-
|
218
|
-
include_context "builds a simple stub"
|
219
|
-
include_context "registers a stub"
|
220
|
-
|
221
|
-
before(:example) { register_stub }
|
222
|
-
|
223
|
-
it "returns a response body that does not include the stub configuration request" do
|
224
|
-
expect(response.body).to_not match(/#{request_uri}/)
|
225
|
-
end
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
|
-
context "when a request has been made configuring a scenario" do
|
230
|
-
|
231
|
-
include_context "builds a simple stub"
|
232
|
-
include_context "registers a stub"
|
233
|
-
|
234
|
-
before(:example) { register_scenario }
|
235
|
-
|
236
|
-
it "returns a response body that does not include the scenario configuration request" do
|
237
|
-
expect(response.body).to_not match(/#{request_uri}/)
|
238
|
-
end
|
239
|
-
|
240
|
-
def register_scenario
|
241
|
-
stub_server.add_scenario_with_one_stub!("Some scenario", build_stub)
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
def full_stub_uri
|
247
|
-
@register_stub_response.header["location"]
|
248
|
-
end
|
249
|
-
|
250
|
-
end
|
251
|
-
|
252
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
describe HttpStub::Server::Stub::Match::Result do
|
2
|
-
|
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) }
|
6
|
-
|
7
|
-
let(:stub_match) { HttpStub::Server::Stub::Match::Result.new(request, response, stub) }
|
8
|
-
|
9
|
-
describe "#request" do
|
10
|
-
|
11
|
-
it "exposes the provided value" do
|
12
|
-
expect(stub_match.request).to eql(request)
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
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
|
-
|
25
|
-
describe "#stub" do
|
26
|
-
|
27
|
-
it "exposes the provided value" do
|
28
|
-
expect(stub_match.stub).to eql(stub)
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module HttpStub
|
2
|
-
module Server
|
3
|
-
module Stub
|
4
|
-
module Match
|
5
|
-
|
6
|
-
class ResultFixture
|
7
|
-
|
8
|
-
def self.empty
|
9
|
-
HttpStub::Server::Stub::Match::Result.new(
|
10
|
-
HttpStub::Server::RequestFixture.create, HttpStub::Server::Response::NOT_FOUND, nil
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|