webmock 1.20.3 → 1.20.4
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.
- data/CHANGELOG.md +4 -0
- data/README.md +21 -22
- data/lib/webmock/matchers/hash_including_matcher.rb +1 -1
- data/lib/webmock/version.rb +1 -1
- data/spec/acceptance/curb/curb_spec.rb +36 -36
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +24 -24
- data/spec/acceptance/excon/excon_spec.rb +11 -11
- data/spec/acceptance/httpclient/httpclient_spec.rb +9 -9
- data/spec/acceptance/net_http/net_http_shared.rb +23 -23
- data/spec/acceptance/net_http/net_http_spec.rb +29 -29
- data/spec/acceptance/patron/patron_spec.rb +11 -11
- data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +29 -29
- data/spec/acceptance/shared/callbacks.rb +18 -18
- data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +3 -3
- data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +10 -10
- data/spec/acceptance/shared/precedence_of_stubs.rb +2 -2
- data/spec/acceptance/shared/request_expectations.rb +302 -302
- data/spec/acceptance/shared/returning_declared_responses.rb +92 -92
- data/spec/acceptance/shared/stubbing_requests.rb +103 -103
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +8 -8
- data/spec/quality_spec.rb +3 -3
- data/spec/spec_helper.rb +0 -6
- data/spec/unit/errors_spec.rb +16 -16
- data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +1 -1
- data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +2 -2
- data/spec/unit/rack_response_spec.rb +14 -14
- data/spec/unit/request_execution_verifier_spec.rb +31 -31
- data/spec/unit/request_pattern_spec.rb +202 -197
- data/spec/unit/request_registry_spec.rb +10 -9
- data/spec/unit/request_signature_spec.rb +21 -20
- data/spec/unit/request_stub_spec.rb +54 -53
- data/spec/unit/response_spec.rb +44 -44
- data/spec/unit/stub_registry_spec.rb +15 -15
- data/spec/unit/stub_request_snippet_spec.rb +8 -8
- data/spec/unit/util/hash_counter_spec.rb +6 -6
- data/spec/unit/util/hash_keys_stringifier_spec.rb +1 -1
- data/spec/unit/util/headers_spec.rb +4 -4
- data/spec/unit/util/json_spec.rb +1 -1
- data/spec/unit/util/uri_spec.rb +30 -30
- data/spec/unit/util/version_checker_spec.rb +9 -9
- data/spec/unit/webmock_spec.rb +1 -1
- data/webmock.gemspec +1 -1
- metadata +10 -9
@@ -4,32 +4,37 @@ describe WebMock::RequestPattern do
|
|
4
4
|
|
5
5
|
describe "describing itself" do
|
6
6
|
it "should report string describing itself" do
|
7
|
-
WebMock::RequestPattern.new(:get, "www.example.com",
|
8
|
-
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).to_s.
|
7
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com",
|
8
|
+
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).to_s).to eq(
|
9
9
|
"GET http://www.example.com/ with body \"abc\" with headers {'A'=>'a', 'B'=>'b'}"
|
10
|
+
)
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should report string describing itself with block" do
|
13
|
-
WebMock::RequestPattern.new(:get, "www.example.com",
|
14
|
-
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).with {|req| true}.to_s.
|
14
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com",
|
15
|
+
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).with {|req| true}.to_s).to eq(
|
15
16
|
"GET http://www.example.com/ with body \"abc\" with headers {'A'=>'a', 'B'=>'b'} with given block"
|
17
|
+
)
|
16
18
|
end
|
17
19
|
|
18
20
|
it "should report string describing itself with query params" do
|
19
|
-
WebMock::RequestPattern.new(:get, /.*example.*/, :query => {'a' => ['b', 'c']}).to_s.
|
21
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/, :query => {'a' => ['b', 'c']}).to_s).to eq(
|
20
22
|
"GET /.*example.*/ with query params {\"a\"=>[\"b\", \"c\"]}"
|
23
|
+
)
|
21
24
|
end
|
22
25
|
|
23
26
|
it "should report string describing itself with query params as hash including matcher" do
|
24
|
-
WebMock::RequestPattern.new(:get, /.*example.*/,
|
25
|
-
:query => WebMock::Matchers::HashIncludingMatcher.new({'a' => ['b', 'c']})).to_s.
|
27
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/,
|
28
|
+
:query => WebMock::Matchers::HashIncludingMatcher.new({'a' => ['b', 'c']})).to_s).to eq(
|
26
29
|
"GET /.*example.*/ with query params hash_including({\"a\"=>[\"b\", \"c\"]})"
|
30
|
+
)
|
27
31
|
end
|
28
32
|
|
29
33
|
it "should report string describing itself with body as hash including matcher" do
|
30
|
-
WebMock::RequestPattern.new(:get, /.*example.*/,
|
31
|
-
:body => WebMock::Matchers::HashIncludingMatcher.new({'a' => ['b', 'c']})).to_s.
|
34
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/,
|
35
|
+
:body => WebMock::Matchers::HashIncludingMatcher.new({'a' => ['b', 'c']})).to_s).to eq(
|
32
36
|
"GET /.*example.*/ with body hash_including({\"a\"=>[\"b\", \"c\"]})"
|
37
|
+
)
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
@@ -40,12 +45,12 @@ describe WebMock::RequestPattern do
|
|
40
45
|
|
41
46
|
it "should have assigned body pattern" do
|
42
47
|
@request_pattern.with(:body => "abc")
|
43
|
-
@request_pattern.to_s.
|
48
|
+
expect(@request_pattern.to_s).to eq(WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc").to_s)
|
44
49
|
end
|
45
50
|
|
46
51
|
it "should have assigned normalized headers pattern" do
|
47
52
|
@request_pattern.with(:headers => {'A' => 'a'})
|
48
|
-
@request_pattern.to_s.
|
53
|
+
expect(@request_pattern.to_s).to eq(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A' => 'a'}).to_s)
|
49
54
|
end
|
50
55
|
|
51
56
|
it "should raise an error if options passed to `with` are invalid" do
|
@@ -67,110 +72,110 @@ describe WebMock::RequestPattern do
|
|
67
72
|
describe "when matching" do
|
68
73
|
|
69
74
|
it "should match if uri matches and method matches" do
|
70
|
-
WebMock::RequestPattern.new(:get, "www.example.com").
|
71
|
-
|
75
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com")).
|
76
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
72
77
|
end
|
73
78
|
|
74
79
|
it "should match if uri matches and method pattern is any" do
|
75
|
-
WebMock::RequestPattern.new(:any, "www.example.com").
|
76
|
-
|
80
|
+
expect(WebMock::RequestPattern.new(:any, "www.example.com")).
|
81
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
77
82
|
end
|
78
83
|
|
79
84
|
it "should not match if request has different method" do
|
80
|
-
WebMock::RequestPattern.new(:post, "www.example.com").
|
81
|
-
|
85
|
+
expect(WebMock::RequestPattern.new(:post, "www.example.com")).
|
86
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
82
87
|
end
|
83
88
|
|
84
89
|
it "should match if uri matches request uri" do
|
85
|
-
WebMock::RequestPattern.new(:get, "www.example.com").
|
86
|
-
|
90
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com")).
|
91
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
87
92
|
end
|
88
93
|
|
89
94
|
it "should match if request has unescaped uri" do
|
90
|
-
WebMock::RequestPattern.new(:get, "www.example.com/my%20path").
|
91
|
-
|
95
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com/my%20path")).
|
96
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/my path"))
|
92
97
|
end
|
93
98
|
|
94
99
|
it "should match if request has escaped uri" do
|
95
|
-
WebMock::RequestPattern.new(:get, "www.example.com/my path").
|
96
|
-
|
100
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com/my path")).
|
101
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/my%20path"))
|
97
102
|
end
|
98
103
|
|
99
104
|
it "should match if uri regexp pattern matches unescaped form of request uri" do
|
100
|
-
WebMock::RequestPattern.new(:get, /.*my path.*/).
|
101
|
-
|
105
|
+
expect(WebMock::RequestPattern.new(:get, /.*my path.*/)).
|
106
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/my%20path"))
|
102
107
|
end
|
103
108
|
|
104
109
|
it "should match if uri regexp pattern matches request uri" do
|
105
|
-
WebMock::RequestPattern.new(:get, /.*example.*/).
|
106
|
-
|
110
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/)).
|
111
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
107
112
|
end
|
108
113
|
|
109
114
|
it "should match if uri Addressable::Template pattern matches unescaped form of request uri" do
|
110
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/{any_path}")).
|
111
|
-
|
115
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/{any_path}"))).
|
116
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/my%20path"))
|
112
117
|
end
|
113
118
|
|
114
119
|
it "should match if uri Addressable::Template pattern matches request uri" do
|
115
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com")).
|
116
|
-
|
120
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"))).
|
121
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
117
122
|
end
|
118
123
|
|
119
124
|
it "should match for uris with same parameters as pattern" do
|
120
|
-
WebMock::RequestPattern.new(:get, "www.example.com?a=1&b=2").
|
121
|
-
|
125
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com?a=1&b=2")).
|
126
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a=1&b=2"))
|
122
127
|
end
|
123
128
|
|
124
129
|
it "should not match for uris with different parameters" do
|
125
|
-
WebMock::RequestPattern.new(:get, "www.example.com?a=1&b=2").
|
126
|
-
|
130
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com?a=1&b=2")).
|
131
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a=2&b=1"))
|
127
132
|
end
|
128
133
|
|
129
134
|
it "should match for uri parameters in different order" do
|
130
|
-
WebMock::RequestPattern.new(:get, "www.example.com?b=2&a=1").
|
131
|
-
|
135
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com?b=2&a=1")).
|
136
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a=1&b=2"))
|
132
137
|
end
|
133
138
|
|
134
139
|
describe "when parameters are escaped" do
|
135
140
|
|
136
141
|
it "should match if uri pattern has escaped parameters and request has unescaped parameters" do
|
137
|
-
WebMock::RequestPattern.new(:get, "www.example.com/?a=a%20b").
|
138
|
-
|
142
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com/?a=a%20b")).
|
143
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a b"))
|
139
144
|
end
|
140
145
|
|
141
146
|
it "should match if uri pattern has unescaped parameters and request has escaped parameters" do
|
142
|
-
WebMock::RequestPattern.new(:get, "www.example.com/?a=a b").
|
143
|
-
|
147
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com/?a=a b")).
|
148
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a%20b"))
|
144
149
|
end
|
145
150
|
|
146
151
|
it "should match if uri regexp pattern matches uri with unescaped parameters and request has escaped parameters" do
|
147
|
-
WebMock::RequestPattern.new(:get, /.*a=a b.*/).
|
148
|
-
|
152
|
+
expect(WebMock::RequestPattern.new(:get, /.*a=a b.*/)).
|
153
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a%20b"))
|
149
154
|
end
|
150
155
|
|
151
156
|
it "should match if uri regexp pattern matches uri with escaped parameters and request has unescaped parameters" do
|
152
|
-
WebMock::RequestPattern.new(:get, /.*a=a%20b.*/).
|
153
|
-
|
157
|
+
expect(WebMock::RequestPattern.new(:get, /.*a=a%20b.*/)).
|
158
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a b"))
|
154
159
|
end
|
155
160
|
|
156
161
|
it "should match if uri Addressable::Template pattern matches uri without parameter value and request has escaped parameters" do
|
157
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/{?a}")).
|
158
|
-
|
162
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/{?a}"))).
|
163
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a%20b"))
|
159
164
|
end
|
160
165
|
|
161
166
|
it "should match if uri Addressable::Template pattern matches uri without parameter value and request has unescaped parameters" do
|
162
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/{?a}")).
|
163
|
-
|
167
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/{?a}"))).
|
168
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a b"))
|
164
169
|
end
|
165
170
|
|
166
171
|
it "should match if uri Addressable::Template pattern matches uri with unescaped parameter value and request has unescaped parameters" do
|
167
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/?a=a b")).
|
168
|
-
|
172
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/?a=a b"))).
|
173
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a b"))
|
169
174
|
end
|
170
175
|
|
171
176
|
it "should match if uri Addressable::Template pattern matches uri with escaped parameter value and request has escaped parameters" do
|
172
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/?a=a%20b")).
|
173
|
-
|
177
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/?a=a%20b"))).
|
178
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a%20b"))
|
174
179
|
end
|
175
180
|
|
176
181
|
end
|
@@ -179,119 +184,119 @@ describe WebMock::RequestPattern do
|
|
179
184
|
|
180
185
|
describe "when uri is described as regexp" do
|
181
186
|
it "should match request query params" do
|
182
|
-
WebMock::RequestPattern.new(:get, /.*example.*/, :query => {"a" => ["b", "c"]}).
|
183
|
-
|
187
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/, :query => {"a" => ["b", "c"]})).
|
188
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
184
189
|
end
|
185
190
|
|
186
191
|
it "should match request query params if params don't match" do
|
187
|
-
WebMock::RequestPattern.new(:get, /.*example.*/, :query => {"x" => ["b", "c"]}).
|
188
|
-
|
192
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/, :query => {"x" => ["b", "c"]})).
|
193
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
189
194
|
end
|
190
195
|
|
191
196
|
it "should match when query params are declared as HashIncluding matcher matching params" do
|
192
|
-
WebMock::RequestPattern.new(:get, /.*example.*/,
|
193
|
-
:query => WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]})).
|
194
|
-
|
197
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/,
|
198
|
+
:query => WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
|
199
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
195
200
|
end
|
196
201
|
|
197
202
|
it "should not match when query params are declared as HashIncluding matcher not matching params" do
|
198
|
-
WebMock::RequestPattern.new(:get, /.*example.*/,
|
199
|
-
:query => WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]})).
|
200
|
-
|
203
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/,
|
204
|
+
:query => WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]}))).
|
205
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
201
206
|
end
|
202
207
|
|
203
208
|
it "should match when query params are declared as RSpec HashIncluding matcher matching params" do
|
204
|
-
WebMock::RequestPattern.new(:get, /.*example.*/,
|
205
|
-
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]})).
|
206
|
-
|
209
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/,
|
210
|
+
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
|
211
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
207
212
|
end
|
208
213
|
|
209
214
|
it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do
|
210
|
-
WebMock::RequestPattern.new(:get, /.*example.*/,
|
211
|
-
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]})).
|
212
|
-
|
215
|
+
expect(WebMock::RequestPattern.new(:get, /.*example.*/,
|
216
|
+
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]}))).
|
217
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
213
218
|
end
|
214
219
|
end
|
215
220
|
|
216
221
|
describe "when uri is described as Addressable::Template" do
|
217
222
|
it "should raise error if query params are specified" do
|
218
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), :query => {"a" => ["b", "c"]}).
|
219
|
-
|
223
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), :query => {"a" => ["b", "c"]})).
|
224
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
220
225
|
end
|
221
226
|
|
222
227
|
it "should match request query params if params don't match" do
|
223
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), :query => {"x" => ["b", "c"]}).
|
224
|
-
|
228
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), :query => {"x" => ["b", "c"]})).
|
229
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
225
230
|
end
|
226
231
|
|
227
232
|
it "should match when query params are declared as HashIncluding matcher matching params" do
|
228
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"),
|
229
|
-
:query => WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]})).
|
230
|
-
|
233
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"),
|
234
|
+
:query => WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
|
235
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
231
236
|
end
|
232
237
|
|
233
238
|
it "should not match when query params are declared as HashIncluding matcher not matching params" do
|
234
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"),
|
235
|
-
:query => WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]})).
|
236
|
-
|
239
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"),
|
240
|
+
:query => WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]}))).
|
241
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
237
242
|
end
|
238
243
|
|
239
244
|
it "should match when query params are declared as RSpec HashIncluding matcher matching params" do
|
240
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"),
|
241
|
-
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]})).
|
242
|
-
|
245
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"),
|
246
|
+
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
|
247
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
243
248
|
end
|
244
249
|
|
245
250
|
it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do
|
246
|
-
WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"),
|
247
|
-
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]})).
|
248
|
-
|
251
|
+
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"),
|
252
|
+
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]}))).
|
253
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
249
254
|
end
|
250
255
|
end
|
251
256
|
|
252
257
|
describe "when uri is described as string" do
|
253
258
|
it "should match when query params are the same as declared in hash" do
|
254
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]}).
|
255
|
-
|
259
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]})).
|
260
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
256
261
|
end
|
257
262
|
|
258
263
|
it "should not match when query params are different than the declared in hash" do
|
259
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]}).
|
260
|
-
|
264
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]})).
|
265
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?x[]=b&a[]=c"))
|
261
266
|
end
|
262
267
|
|
263
268
|
it "should match when query params are the same as declared as string" do
|
264
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :query => "a[]=b&a[]=c").
|
265
|
-
|
269
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :query => "a[]=b&a[]=c")).
|
270
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
266
271
|
end
|
267
272
|
|
268
273
|
it "should match when query params are the same as declared both in query option or url" do
|
269
|
-
WebMock::RequestPattern.new(:get, "www.example.com/?x=3", :query => "a[]=b&a[]=c").
|
270
|
-
|
274
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com/?x=3", :query => "a[]=b&a[]=c")).
|
275
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com/?x=3&a[]=b&a[]=c"))
|
271
276
|
end
|
272
277
|
|
273
278
|
it "should match when query params are declared as HashIncluding matcher matching params" do
|
274
|
-
WebMock::RequestPattern.new(:get, "www.example.com",
|
275
|
-
:query => WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]})).
|
276
|
-
|
279
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com",
|
280
|
+
:query => WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
|
281
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
277
282
|
end
|
278
283
|
|
279
284
|
it "should not match when query params are declared as HashIncluding matcher not matching params" do
|
280
|
-
WebMock::RequestPattern.new(:get, "www.example.com",
|
281
|
-
:query => WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]})).
|
282
|
-
|
285
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com",
|
286
|
+
:query => WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]}))).
|
287
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
283
288
|
end
|
284
289
|
|
285
290
|
it "should match when query params are declared as RSpec HashIncluding matcher matching params" do
|
286
|
-
WebMock::RequestPattern.new(:get, "www.example.com",
|
287
|
-
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]})).
|
288
|
-
|
291
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com",
|
292
|
+
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
|
293
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
289
294
|
end
|
290
295
|
|
291
296
|
it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do
|
292
|
-
WebMock::RequestPattern.new(:get, "www.example.com",
|
293
|
-
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]})).
|
294
|
-
|
297
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com",
|
298
|
+
:query => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]}))).
|
299
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
295
300
|
end
|
296
301
|
|
297
302
|
context "when using query values notation as flat array" do
|
@@ -300,8 +305,8 @@ describe WebMock::RequestPattern do
|
|
300
305
|
end
|
301
306
|
|
302
307
|
it "should not match when repeated query params are not the same as declared as string" do
|
303
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :query => "a=b&a=c").
|
304
|
-
|
308
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :query => "a=b&a=c")).
|
309
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a=b&a=c"))
|
305
310
|
end
|
306
311
|
|
307
312
|
after :all do
|
@@ -314,43 +319,43 @@ describe WebMock::RequestPattern do
|
|
314
319
|
describe "when matching requests with body" do
|
315
320
|
|
316
321
|
it "should match if request body and body pattern are the same" do
|
317
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc").
|
318
|
-
|
322
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc")).
|
323
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
319
324
|
end
|
320
325
|
|
321
326
|
it "should match if request body matches regexp" do
|
322
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :body => /^abc$/).
|
323
|
-
|
327
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :body => /^abc$/)).
|
328
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
324
329
|
end
|
325
330
|
|
326
331
|
it "should not match if body pattern is different than request body" do
|
327
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :body => "def").
|
328
|
-
|
332
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :body => "def")).
|
333
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
329
334
|
end
|
330
335
|
|
331
336
|
it "should not match if request body doesn't match regexp pattern" do
|
332
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :body => /^abc$/).
|
333
|
-
|
337
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :body => /^abc$/)).
|
338
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "xabc"))
|
334
339
|
end
|
335
340
|
|
336
341
|
it "should match if pattern doesn't have specified body" do
|
337
|
-
WebMock::RequestPattern.new(:get, "www.example.com").
|
338
|
-
|
342
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com")).
|
343
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
339
344
|
end
|
340
345
|
|
341
346
|
it "should not match if pattern has body specified as nil but request body is not empty" do
|
342
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :body => nil).
|
343
|
-
|
347
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :body => nil)).
|
348
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
344
349
|
end
|
345
350
|
|
346
351
|
it "should not match if pattern has empty body but request body is not empty" do
|
347
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :body => "").
|
348
|
-
|
352
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :body => "")).
|
353
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
349
354
|
end
|
350
355
|
|
351
356
|
it "should not match if pattern has body specified but request has no body" do
|
352
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc").
|
353
|
-
|
357
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc")).
|
358
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
354
359
|
end
|
355
360
|
|
356
361
|
describe "when body in pattern is declared as a hash" do
|
@@ -358,70 +363,70 @@ describe WebMock::RequestPattern do
|
|
358
363
|
|
359
364
|
describe "for request with url encoded body" do
|
360
365
|
it "should match when hash matches body" do
|
361
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
362
|
-
|
366
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
367
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a=1&c[d][]=e&c[d][]=f&b=five'))
|
363
368
|
end
|
364
369
|
|
365
370
|
it "should match when hash matches body in different order of params" do
|
366
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
367
|
-
|
371
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
372
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a=1&c[d][]=e&b=five&c[d][]=f'))
|
368
373
|
end
|
369
374
|
|
370
375
|
it "should not match when hash doesn't match url encoded body" do
|
371
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
372
|
-
|
376
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
377
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'c[d][]=f&a=1&c[d][]=e'))
|
373
378
|
end
|
374
379
|
|
375
380
|
it "should not match when body is not url encoded" do
|
376
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
377
|
-
|
381
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
382
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'foo bar'))
|
378
383
|
end
|
379
384
|
|
380
385
|
it "should match when hash contains regex values" do
|
381
|
-
WebMock::RequestPattern.new(:post, "www.example.com", :body => {:a => /^\w{5}$/, :b => {:c => /^\d{3}$/}}).
|
382
|
-
|
386
|
+
expect(WebMock::RequestPattern.new(:post, "www.example.com", :body => {:a => /^\w{5}$/, :b => {:c => /^\d{3}$/}})).
|
387
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a=abcde&b[c]=123'))
|
383
388
|
end
|
384
389
|
|
385
390
|
it "should not match when hash does not contains regex values" do
|
386
|
-
WebMock::RequestPattern.new(:post, "www.example.com", :body => {:a => /^\d+$/, :b => {:c => /^\d{3}$/}}).
|
387
|
-
|
391
|
+
expect(WebMock::RequestPattern.new(:post, "www.example.com", :body => {:a => /^\d+$/, :b => {:c => /^\d{3}$/}})).
|
392
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a=abcde&b[c]=123'))
|
388
393
|
end
|
389
394
|
end
|
390
395
|
|
391
396
|
describe "for request with json body and content type is set to json" do
|
392
397
|
it "should match when hash matches body" do
|
393
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
394
|
-
|
398
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
399
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/json'},
|
395
400
|
:body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}"))
|
396
401
|
end
|
397
402
|
|
398
403
|
it "should match if hash matches body in different form" do
|
399
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
400
|
-
|
404
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
405
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/json'},
|
401
406
|
:body => "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}"))
|
402
407
|
end
|
403
408
|
|
404
409
|
it "should not match when body is not json" do
|
405
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
406
|
-
|
410
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
411
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
407
412
|
:headers => {:content_type => 'application/json'}, :body => "foo bar"))
|
408
413
|
end
|
409
414
|
|
410
415
|
it "should not match if request body is different" do
|
411
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => {:a => 1, :b => 2}).
|
412
|
-
|
416
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => {:a => 1, :b => 2})).
|
417
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
413
418
|
:headers => {:content_type => 'application/json'}, :body => "{\"a\":1,\"c\":null}"))
|
414
419
|
end
|
415
420
|
|
416
421
|
it "should not match if request body is has less params than pattern" do
|
417
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => {:a => 1, :b => 2}).
|
418
|
-
|
422
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => {:a => 1, :b => 2})).
|
423
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
419
424
|
:headers => {:content_type => 'application/json'}, :body => "{\"a\":1}"))
|
420
425
|
end
|
421
426
|
|
422
427
|
it "should not match if request body is has more params than pattern" do
|
423
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => {:a => 1}).
|
424
|
-
|
428
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => {:a => 1})).
|
429
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
425
430
|
:headers => {:content_type => 'application/json'}, :body => "{\"a\":1,\"c\":1}"))
|
426
431
|
end
|
427
432
|
end
|
@@ -430,26 +435,26 @@ describe WebMock::RequestPattern do
|
|
430
435
|
let(:body_hash) { {"opt" => {:a => '1', :b => 'five', 'c' => {'d' => ['e', 'f']}}} }
|
431
436
|
|
432
437
|
it "should match when hash matches body" do
|
433
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
434
|
-
|
438
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
439
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/xml'},
|
435
440
|
:body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))
|
436
441
|
end
|
437
442
|
|
438
443
|
it "should match if hash matches body in different form" do
|
439
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
440
|
-
|
444
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
445
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/xml'},
|
441
446
|
:body => "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))
|
442
447
|
end
|
443
448
|
|
444
449
|
it "should not match when body is not xml" do
|
445
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
446
|
-
|
450
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
451
|
+
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
447
452
|
:headers => {:content_type => 'application/xml'}, :body => "foo bar"))
|
448
453
|
end
|
449
454
|
|
450
455
|
it "matches when the content type include a charset" do
|
451
|
-
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
452
|
-
|
456
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash)).
|
457
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/xml;charset=UTF-8'},
|
453
458
|
:body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))
|
454
459
|
|
455
460
|
end
|
@@ -460,105 +465,105 @@ describe WebMock::RequestPattern do
|
|
460
465
|
let(:signature) { WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a=1&c[d][]=e&c[d][]=f&b=five') }
|
461
466
|
|
462
467
|
it "should match when query params are declared as HashIncluding matcher matching params" do
|
463
|
-
WebMock::RequestPattern.new(:post, "www.example.com",
|
464
|
-
:body => WebMock::Matchers::HashIncludingMatcher.new({:a => '1', 'c' => {'d' => ['e', 'f']}})).
|
465
|
-
|
468
|
+
expect(WebMock::RequestPattern.new(:post, "www.example.com",
|
469
|
+
:body => WebMock::Matchers::HashIncludingMatcher.new({:a => '1', 'c' => {'d' => ['e', 'f']}}))).
|
470
|
+
to match(signature)
|
466
471
|
end
|
467
472
|
|
468
473
|
it "should not match when query params are declared as HashIncluding matcher not matching params" do
|
469
|
-
WebMock::RequestPattern.new(:post, "www.example.com",
|
470
|
-
:body => WebMock::Matchers::HashIncludingMatcher.new({:x => '1', 'c' => {'d' => ['e', 'f']}})).
|
471
|
-
|
474
|
+
expect(WebMock::RequestPattern.new(:post, "www.example.com",
|
475
|
+
:body => WebMock::Matchers::HashIncludingMatcher.new({:x => '1', 'c' => {'d' => ['e', 'f']}}))).
|
476
|
+
not_to match(signature)
|
472
477
|
end
|
473
478
|
|
474
479
|
it "should match when query params are declared as RSpec HashIncluding matcher matching params" do
|
475
|
-
WebMock::RequestPattern.new(:post, "www.example.com",
|
476
|
-
:body => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({:a => '1', 'c' => {'d' => ['e', 'f']}})).
|
477
|
-
|
480
|
+
expect(WebMock::RequestPattern.new(:post, "www.example.com",
|
481
|
+
:body => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({:a => '1', 'c' => {'d' => ['e', 'f']}}))).
|
482
|
+
to match(signature)
|
478
483
|
end
|
479
484
|
|
480
485
|
it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do
|
481
|
-
WebMock::RequestPattern.new(:post, "www.example.com",
|
482
|
-
:body => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({:x => '1', 'c' => {'d' => ['e', 'f']}})).
|
483
|
-
|
486
|
+
expect(WebMock::RequestPattern.new(:post, "www.example.com",
|
487
|
+
:body => RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({:x => '1', 'c' => {'d' => ['e', 'f']}}))).
|
488
|
+
not_to match(signature)
|
484
489
|
end
|
485
490
|
end
|
486
491
|
end
|
487
492
|
|
488
493
|
it "should match if pattern and request have the same headers" do
|
489
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}).
|
490
|
-
|
494
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'})).
|
495
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
491
496
|
end
|
492
497
|
|
493
498
|
it "should match if pattern headers values are regexps matching request header values" do
|
494
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => %r{^image/jpeg$}}).
|
495
|
-
|
499
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => %r{^image/jpeg$}})).
|
500
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
496
501
|
end
|
497
502
|
|
498
503
|
it "should not match if pattern has different value of header than request" do
|
499
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/png'}).
|
500
|
-
|
504
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/png'})).
|
505
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
501
506
|
end
|
502
507
|
|
503
508
|
it "should not match if pattern header value regexp doesn't match request header value" do
|
504
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => %r{^image\/jpeg$}}).
|
505
|
-
|
509
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => %r{^image\/jpeg$}})).
|
510
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpegx'}))
|
506
511
|
end
|
507
512
|
|
508
513
|
it "should match if request has more headers than request pattern" do
|
509
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}).
|
510
|
-
|
514
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'})).
|
515
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg', 'Content-Length' => '8888'}))
|
511
516
|
end
|
512
517
|
|
513
518
|
it "should not match if request has less headers than the request pattern" do
|
514
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg', 'Content-Length' => '8888'}).
|
515
|
-
|
519
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg', 'Content-Length' => '8888'})).
|
520
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
516
521
|
end
|
517
522
|
|
518
523
|
it "should match even is header keys are declared in different form" do
|
519
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'ContentLength' => '8888', 'Content-type' => 'image/png'}).
|
520
|
-
|
524
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'ContentLength' => '8888', 'Content-type' => 'image/png'})).
|
525
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {:ContentLength => 8888, 'content_type' => 'image/png'}))
|
521
526
|
end
|
522
527
|
|
523
528
|
it "should match is pattern doesn't have specified headers" do
|
524
|
-
WebMock::RequestPattern.new(:get, "www.example.com").
|
525
|
-
|
529
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com")).
|
530
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}))
|
526
531
|
end
|
527
532
|
|
528
533
|
it "should not match if pattern has nil headers but request has headers" do
|
529
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => nil).
|
530
|
-
|
534
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => nil)).
|
535
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}))
|
531
536
|
end
|
532
537
|
|
533
538
|
it "should not match if pattern has empty headers but request has headers" do
|
534
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {}).
|
535
|
-
|
539
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {})).
|
540
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}))
|
536
541
|
end
|
537
542
|
|
538
543
|
it "should not match if pattern has specified headers but request has nil headers" do
|
539
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A'=>'a'}).
|
540
|
-
|
544
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A'=>'a'})).
|
545
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
541
546
|
end
|
542
547
|
|
543
548
|
it "should not match if pattern has specified headers but request has empty headers" do
|
544
|
-
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A'=>'a'}).
|
545
|
-
|
549
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A'=>'a'})).
|
550
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {}))
|
546
551
|
end
|
547
552
|
|
548
553
|
it "should match if block given in pattern evaluates request to true" do
|
549
|
-
WebMock::RequestPattern.new(:get, "www.example.com").with { |request| true }.
|
550
|
-
|
554
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com").with { |request| true }).
|
555
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
551
556
|
end
|
552
557
|
|
553
558
|
it "should not match if block given in pattrn evaluates request to false" do
|
554
|
-
WebMock::RequestPattern.new(:get, "www.example.com").with { |request| false }.
|
555
|
-
|
559
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com").with { |request| false }).
|
560
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
556
561
|
end
|
557
562
|
|
558
563
|
it "should yield block with request signature" do
|
559
564
|
signature = WebMock::RequestSignature.new(:get, "www.example.com")
|
560
|
-
WebMock::RequestPattern.new(:get, "www.example.com").with { |request| request == signature }.
|
561
|
-
|
565
|
+
expect(WebMock::RequestPattern.new(:get, "www.example.com").with { |request| request == signature }).
|
566
|
+
to match(signature)
|
562
567
|
end
|
563
568
|
|
564
569
|
end
|