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
@@ -0,0 +1,146 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Match::Match 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(:match) { HttpStub::Server::Stub::Match::Match.new(request, response, stub) }
|
8
|
+
|
9
|
+
describe "#request" do
|
10
|
+
|
11
|
+
it "exposes the provided value" do
|
12
|
+
expect(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(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(match.stub).to eql(stub)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#matches?" do
|
34
|
+
|
35
|
+
let(:request_uri) { "/some/endpoint/uri" }
|
36
|
+
let(:request_method) { "GET" }
|
37
|
+
|
38
|
+
let(:criteria_uri) { request_uri }
|
39
|
+
let(:criteria_method) { criteria_method }
|
40
|
+
let(:criteria) { { uri: criteria_uri, method: criteria_method } }
|
41
|
+
let(:logger) { instance_double(Logger) }
|
42
|
+
|
43
|
+
subject { match.matches?(criteria, logger) }
|
44
|
+
|
45
|
+
before(:each) do
|
46
|
+
allow(request).to receive(:uri).and_return(request_uri)
|
47
|
+
allow(request).to receive(:method).and_return(request_method)
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when the uri matches" do
|
51
|
+
|
52
|
+
let(:criteria_uri) { request_uri }
|
53
|
+
|
54
|
+
context "and the criteria method is the same as the results request method" do
|
55
|
+
|
56
|
+
let(:criteria_method) { request_method }
|
57
|
+
|
58
|
+
it "returns true" do
|
59
|
+
expect(subject).to be(true)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
context "and the criteria method has different casing than the results request method" do
|
65
|
+
|
66
|
+
let(:criteria_method) { request_method.downcase }
|
67
|
+
|
68
|
+
it "returns true" do
|
69
|
+
expect(subject).to be(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
context "and the criteria method is different than the results request method" do
|
75
|
+
|
76
|
+
let(:criteria_method) { "POST" }
|
77
|
+
|
78
|
+
it "returns false" do
|
79
|
+
expect(subject).to be(false)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when the method matches" do
|
87
|
+
|
88
|
+
let(:criteria_method) { request_method }
|
89
|
+
|
90
|
+
context "and the criteria uri is the same as the results request uri" do
|
91
|
+
|
92
|
+
let(:criteria_uri) { request_uri }
|
93
|
+
|
94
|
+
it "returns true" do
|
95
|
+
expect(subject).to be(true)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
context "and the criteria uri partially matches the results request uri" do
|
101
|
+
|
102
|
+
let(:criteria_uri) { "endpoint/uri" }
|
103
|
+
|
104
|
+
it "returns true" do
|
105
|
+
expect(subject).to be(true)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
context "and the criteria uri is not within the results request uri" do
|
111
|
+
|
112
|
+
let(:criteria_uri) { "/another/endpoint/uri" }
|
113
|
+
|
114
|
+
it "returns false" do
|
115
|
+
expect(subject).to be(false)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#to_hash" do
|
125
|
+
|
126
|
+
subject { match.to_hash }
|
127
|
+
|
128
|
+
describe "supporting creating a JSON representation of the result" do
|
129
|
+
|
130
|
+
it "contains the matching request" do
|
131
|
+
expect(subject).to include(request: request)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "contains the served response" do
|
135
|
+
expect(subject).to include(response: response)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "contains the matched stub" do
|
139
|
+
expect(subject).to include(stub: stub)
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Match::Miss do
|
2
|
+
|
3
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request) }
|
4
|
+
|
5
|
+
let(:miss) { HttpStub::Server::Stub::Match::Miss.new(request) }
|
6
|
+
|
7
|
+
describe "#request" do
|
8
|
+
|
9
|
+
it "exposes the provided value" do
|
10
|
+
expect(miss.request).to eql(request)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,247 @@
|
|
1
|
+
describe HttpStub::Server::Stub::Match::Rules do
|
2
|
+
|
3
|
+
let(:header_payload) do
|
4
|
+
{
|
5
|
+
"match_rule_header1" => "match_rule_header_value1",
|
6
|
+
"match_rule_header2" => "match_rule_header_value2",
|
7
|
+
"match_rule_header3" => "match_rule_header_value3"
|
8
|
+
}
|
9
|
+
end
|
10
|
+
let(:parameter_payload) do
|
11
|
+
{
|
12
|
+
"match_rule_parameter1" => "match_rule_parameter_value1",
|
13
|
+
"match_rule_parameter2" => "match_rule_parameter_value2",
|
14
|
+
"match_rule_parameter3" => "match_rule_parameter_value3"
|
15
|
+
}
|
16
|
+
end
|
17
|
+
let(:method_payload) { "get" }
|
18
|
+
let(:match_rules_payload) do
|
19
|
+
{
|
20
|
+
"uri" => "/a_path",
|
21
|
+
"method" => method_payload,
|
22
|
+
"headers" => header_payload,
|
23
|
+
"parameters" => parameter_payload,
|
24
|
+
"body" => { "schema" => { "json" => "stub schema definition" } }
|
25
|
+
}
|
26
|
+
end
|
27
|
+
let(:uri_rule) { instance_double(HttpStub::Server::Stub::Match::Rule::Uri, matches?: true) }
|
28
|
+
let(:method_rule) { instance_double(HttpStub::Server::Stub::Match::Rule::Method, matches?: true) }
|
29
|
+
let(:headers_rule) { instance_double(HttpStub::Server::Stub::Match::Rule::Headers, matches?: true) }
|
30
|
+
let(:parameters_rule) { instance_double(HttpStub::Server::Stub::Match::Rule::Parameters, matches?: true) }
|
31
|
+
let(:body_rule) { double("HttpStub::Server::Stub::SomeRequestBody", matches?: true) }
|
32
|
+
|
33
|
+
let(:match_rules) { HttpStub::Server::Stub::Match::Rules.new(match_rules_payload) }
|
34
|
+
|
35
|
+
before(:example) do
|
36
|
+
allow(HttpStub::Server::Stub::Match::Rule::Uri).to receive(:new).and_return(uri_rule)
|
37
|
+
allow(HttpStub::Server::Stub::Match::Rule::Method).to receive(:new).and_return(method_rule)
|
38
|
+
allow(HttpStub::Server::Stub::Match::Rule::Headers).to receive(:new).and_return(headers_rule)
|
39
|
+
allow(HttpStub::Server::Stub::Match::Rule::Parameters).to receive(:new).and_return(parameters_rule)
|
40
|
+
allow(HttpStub::Server::Stub::Match::Rule::Body).to receive(:create).and_return(body_rule)
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "::EMPTY" do
|
44
|
+
|
45
|
+
subject { HttpStub::Server::Stub::Match::Rules::EMPTY }
|
46
|
+
|
47
|
+
it "has an empty uri rule" do
|
48
|
+
expect(subject.uri.to_s).to eql("")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has an empty method rule" do
|
52
|
+
expect(subject.method.to_s).to eql("")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "has an empty headers rule" do
|
56
|
+
expect(subject.headers.to_hash).to eql({})
|
57
|
+
end
|
58
|
+
|
59
|
+
it "has an empty parameters rule" do
|
60
|
+
expect(subject.parameters.to_hash).to eql({})
|
61
|
+
end
|
62
|
+
|
63
|
+
it "has an empty body rule" do
|
64
|
+
expect(subject.body.to_s).to eql("")
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#matches?" do
|
70
|
+
|
71
|
+
let(:request_method) { method_payload }
|
72
|
+
let(:request) { instance_double(HttpStub::Server::Request::Request, method: method_payload) }
|
73
|
+
let(:logger) { instance_double(Logger) }
|
74
|
+
|
75
|
+
subject { match_rules.matches?(request, logger) }
|
76
|
+
|
77
|
+
describe "when the request uri matches" do
|
78
|
+
|
79
|
+
before(:example) { allow(uri_rule).to receive(:matches?).with(request, logger).and_return(true) }
|
80
|
+
|
81
|
+
describe "and the request method matches" do
|
82
|
+
|
83
|
+
describe "and a headers rule is configured" do
|
84
|
+
|
85
|
+
describe "that matches" do
|
86
|
+
|
87
|
+
before(:example) { allow(headers_rule).to receive(:matches?).with(request, logger).and_return(true) }
|
88
|
+
|
89
|
+
describe "and a parameters rule is configured" do
|
90
|
+
|
91
|
+
describe "that matches" do
|
92
|
+
|
93
|
+
before(:example) do
|
94
|
+
allow(parameters_rule).to receive(:matches?).with(request, logger).and_return(true)
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "and a body rule is configured" do
|
98
|
+
|
99
|
+
describe "that matches" do
|
100
|
+
|
101
|
+
before(:example) do
|
102
|
+
allow(body_rule).to receive(:matches?).with(request, logger).and_return(true)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns true" do
|
106
|
+
expect(subject).to be(true)
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "when the request uri does not match" do
|
126
|
+
|
127
|
+
before(:example) { allow(uri_rule).to receive(:matches?).with(request, logger).and_return(false) }
|
128
|
+
|
129
|
+
it "returns false" do
|
130
|
+
expect(subject).to be(false)
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "when the request method does not match" do
|
136
|
+
|
137
|
+
before(:example) { allow(method_rule).to receive(:matches?).with(request, logger).and_return(false) }
|
138
|
+
|
139
|
+
it "returns false" do
|
140
|
+
expect(subject).to be(false)
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "when the headers do not match" do
|
146
|
+
|
147
|
+
before(:example) { allow(headers_rule).to receive(:matches?).with(request, logger).and_return(false) }
|
148
|
+
|
149
|
+
it "returns false" do
|
150
|
+
expect(subject).to be(false)
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "when the parameters do not match" do
|
156
|
+
|
157
|
+
before(:example) { allow(parameters_rule).to receive(:matches?).with(request, logger).and_return(false) }
|
158
|
+
|
159
|
+
it "returns false" do
|
160
|
+
expect(subject).to be(false)
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "when the bodies do not match" do
|
166
|
+
|
167
|
+
before(:example) { allow(body_rule).to receive(:matches?).with(request, logger).and_return(false) }
|
168
|
+
|
169
|
+
it "returns false" do
|
170
|
+
expect(subject).to be(false)
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "#uri" do
|
178
|
+
|
179
|
+
it "returns the uri rule for the uri provided in the request body" do
|
180
|
+
expect(match_rules.uri).to eql(uri_rule)
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "#method" do
|
186
|
+
|
187
|
+
it "returns the method rule for the method provided in the request body" do
|
188
|
+
expect(match_rules.method).to eql(method_rule)
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "#headers" do
|
194
|
+
|
195
|
+
it "returns the headers rule for the headers provided in the request body" do
|
196
|
+
expect(match_rules.headers).to eql(headers_rule)
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "#parameters" do
|
202
|
+
|
203
|
+
it "returns the parameters rule for the parameters provided in the request body" do
|
204
|
+
expect(match_rules.parameters).to eql(parameters_rule)
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "#body" do
|
210
|
+
|
211
|
+
it "returns the body rule for the body provided in the request body" do
|
212
|
+
expect(match_rules.body).to eql(body_rule)
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "#to_hash" do
|
218
|
+
|
219
|
+
subject { match_rules.to_hash }
|
220
|
+
|
221
|
+
describe "supporting creating a JSON representation of the stub" do
|
222
|
+
|
223
|
+
it "contains the rules uri" do
|
224
|
+
expect(subject).to include(uri: match_rules.uri)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "contains the rules method" do
|
228
|
+
expect(subject).to include(method: match_rules.method)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "contains the rules headers" do
|
232
|
+
expect(subject).to include(headers: match_rules.headers)
|
233
|
+
end
|
234
|
+
|
235
|
+
it "contains the rules parameters" do
|
236
|
+
expect(subject).to include(parameters: match_rules.parameters)
|
237
|
+
end
|
238
|
+
|
239
|
+
it "contains the rules body" do
|
240
|
+
expect(subject).to include(body: match_rules.body)
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
@@ -17,19 +17,17 @@ describe HttpStub::Server::Stub::Parser do
|
|
17
17
|
let(:payload) { HttpStub::StubFixture.new.server_payload }
|
18
18
|
let(:parameters) { { "payload" => payload.to_json } }
|
19
19
|
|
20
|
-
it "
|
21
|
-
expect(HttpStub::Server::Stub::
|
20
|
+
it "modifies the payload" do
|
21
|
+
expect(HttpStub::Server::Stub::Payload).to receive(:modify!).with(payload, request)
|
22
22
|
|
23
23
|
subject
|
24
24
|
end
|
25
25
|
|
26
|
-
it "returns the
|
27
|
-
|
28
|
-
allow(HttpStub::Server::Stub::
|
29
|
-
receive(:consolidate!).and_return(consolidated_payload)
|
30
|
-
)
|
26
|
+
it "returns the modified payload" do
|
27
|
+
modified_payload = { modified_payload_key: "modified payload value" }
|
28
|
+
allow(HttpStub::Server::Stub::Payload).to receive(:modify!).and_return(modified_payload)
|
31
29
|
|
32
|
-
expect(subject).to eql(
|
30
|
+
expect(subject).to eql(modified_payload)
|
33
31
|
end
|
34
32
|
|
35
33
|
end
|
@@ -38,17 +36,17 @@ describe HttpStub::Server::Stub::Parser do
|
|
38
36
|
|
39
37
|
let(:body_hash) { HttpStub::StubFixture.new.server_payload }
|
40
38
|
|
41
|
-
it "
|
42
|
-
expect(HttpStub::Server::Stub::
|
39
|
+
it "modifies the body" do
|
40
|
+
expect(HttpStub::Server::Stub::Payload).to receive(:modify!).with(body_hash, request)
|
43
41
|
|
44
42
|
subject
|
45
43
|
end
|
46
44
|
|
47
|
-
it "returns the
|
48
|
-
|
49
|
-
allow(HttpStub::Server::Stub::
|
45
|
+
it "returns the modified body" do
|
46
|
+
modified_body = { modified_body_key: "modified body value" }
|
47
|
+
allow(HttpStub::Server::Stub::Payload).to receive(:modify!).and_return(modified_body)
|
50
48
|
|
51
|
-
expect(subject).to eql(
|
49
|
+
expect(subject).to eql(modified_body)
|
52
50
|
end
|
53
51
|
|
54
52
|
end
|