webmock 1.3.5 → 1.4.0
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 +23 -0
- data/README.md +17 -20
- data/Rakefile +4 -3
- data/VERSION +1 -1
- data/lib/webmock.rb +5 -0
- data/lib/webmock/adapters/rspec.rb +12 -9
- data/lib/webmock/adapters/test_unit.rb +1 -6
- data/lib/webmock/api.rb +32 -0
- data/lib/webmock/assertion_failure.rb +13 -0
- data/lib/webmock/deprecation.rb +9 -0
- data/lib/webmock/http_lib_adapters/curb.rb +260 -0
- data/lib/webmock/http_lib_adapters/em_http_request.rb +2 -2
- data/lib/webmock/http_lib_adapters/httpclient.rb +4 -3
- data/lib/webmock/http_lib_adapters/net_http.rb +2 -2
- data/lib/webmock/http_lib_adapters/net_http_response.rb +9 -27
- data/lib/webmock/http_lib_adapters/patron.rb +2 -2
- data/lib/webmock/util/uri.rb +5 -0
- data/lib/webmock/webmock.rb +47 -41
- data/spec/curb_spec.rb +173 -0
- data/spec/curb_spec_helper.rb +137 -0
- data/spec/request_execution_verifier_spec.rb +9 -9
- data/spec/request_pattern_spec.rb +115 -115
- data/spec/request_registry_spec.rb +44 -42
- data/spec/request_signature_spec.rb +6 -6
- data/spec/request_stub_spec.rb +5 -5
- data/spec/response_spec.rb +33 -33
- data/spec/spec_helper.rb +2 -3
- data/spec/util/hash_counter_spec.rb +4 -4
- data/spec/util/headers_spec.rb +4 -4
- data/spec/webmock_spec.rb +67 -54
- data/test/test_helper.rb +2 -2
- data/webmock.gemspec +25 -14
- metadata +34 -29
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe RequestExecutionVerifier do
|
3
|
+
describe WebMock::RequestExecutionVerifier do
|
4
4
|
before(:each) do
|
5
|
-
@verifier = RequestExecutionVerifier.new
|
6
|
-
@request_pattern = mock(RequestPattern, :to_s => "www.example.com")
|
5
|
+
@verifier = WebMock::RequestExecutionVerifier.new
|
6
|
+
@request_pattern = mock(WebMock::RequestPattern, :to_s => "www.example.com")
|
7
7
|
@verifier.request_pattern = @request_pattern
|
8
8
|
end
|
9
9
|
|
@@ -42,14 +42,14 @@ describe RequestExecutionVerifier do
|
|
42
42
|
describe "matches?" do
|
43
43
|
|
44
44
|
it "should succeed if request was executed expected number of times" do
|
45
|
-
RequestRegistry.instance.
|
45
|
+
WebMock::RequestRegistry.instance.
|
46
46
|
should_receive(:times_executed).with(@request_pattern).and_return(10)
|
47
47
|
@verifier.expected_times_executed = 10
|
48
48
|
@verifier.matches?.should be_true
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should fail if request was not executed expected number of times" do
|
52
|
-
RequestRegistry.instance.
|
52
|
+
WebMock::RequestRegistry.instance.
|
53
53
|
should_receive(:times_executed).with(@request_pattern).and_return(10)
|
54
54
|
@verifier.expected_times_executed = 5
|
55
55
|
@verifier.matches?.should be_false
|
@@ -60,26 +60,26 @@ describe RequestExecutionVerifier do
|
|
60
60
|
describe "does_not_match?" do
|
61
61
|
|
62
62
|
it "should fail if request executed expected number of times" do
|
63
|
-
RequestRegistry.instance.
|
63
|
+
WebMock::RequestRegistry.instance.
|
64
64
|
should_receive(:times_executed).with(@request_pattern).and_return(10)
|
65
65
|
@verifier.expected_times_executed = 10
|
66
66
|
@verifier.does_not_match?.should be_false
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should succeed if request was not executed at all and expected number of times was not set" do
|
70
|
-
RequestRegistry.instance.
|
70
|
+
WebMock::RequestRegistry.instance.
|
71
71
|
should_receive(:times_executed).with(@request_pattern).and_return(0)
|
72
72
|
@verifier.does_not_match?.should be_true
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should fail if request was executed and expected number of times was not set" do
|
76
|
-
RequestRegistry.instance.
|
76
|
+
WebMock::RequestRegistry.instance.
|
77
77
|
should_receive(:times_executed).with(@request_pattern).and_return(1)
|
78
78
|
@verifier.does_not_match?.should be_false
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should succeed if request was not executed expected number of times" do
|
82
|
-
RequestRegistry.instance.
|
82
|
+
WebMock::RequestRegistry.instance.
|
83
83
|
should_receive(:times_executed).with(@request_pattern).and_return(10)
|
84
84
|
@verifier.expected_times_executed = 5
|
85
85
|
@verifier.does_not_match?.should be_true
|
@@ -1,37 +1,37 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe RequestPattern do
|
3
|
+
describe WebMock::RequestPattern do
|
4
4
|
|
5
5
|
it "should report string describing itself" do
|
6
|
-
RequestPattern.new(:get, "www.example.com",
|
6
|
+
WebMock::RequestPattern.new(:get, "www.example.com",
|
7
7
|
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).to_s.should ==
|
8
8
|
"GET http://www.example.com/ with body \"abc\" with headers {'A'=>'a', 'B'=>'b'}"
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should report string describing itself with block" do
|
12
|
-
RequestPattern.new(:get, "www.example.com",
|
12
|
+
WebMock::RequestPattern.new(:get, "www.example.com",
|
13
13
|
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).with {|req| true}.to_s.should ==
|
14
14
|
"GET http://www.example.com/ with body \"abc\" with headers {'A'=>'a', 'B'=>'b'} with given block"
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should report string describing itself with query params" do
|
18
|
-
RequestPattern.new(:get, /.*example.*/, :query => {'a' => ['b', 'c']}).to_s.should ==
|
18
|
+
WebMock::RequestPattern.new(:get, /.*example.*/, :query => {'a' => ['b', 'c']}).to_s.should ==
|
19
19
|
"GET /.*example.*/ with query params {\"a\"=>[\"b\", \"c\"]}"
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "with" do
|
23
23
|
before(:each) do
|
24
|
-
@request_pattern =
|
24
|
+
@request_pattern =WebMock::RequestPattern.new(:get, "www.example.com")
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should have assigned body pattern" do
|
28
28
|
@request_pattern.with(:body => "abc")
|
29
|
-
@request_pattern.to_s.should ==
|
29
|
+
@request_pattern.to_s.should ==WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc").to_s
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should have assigned normalized headers pattern" do
|
33
33
|
@request_pattern.with(:headers => {'A' => 'a'})
|
34
|
-
@request_pattern.to_s.should ==
|
34
|
+
@request_pattern.to_s.should ==WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A' => 'a'}).to_s
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
@@ -46,80 +46,80 @@ describe RequestPattern do
|
|
46
46
|
describe "when matching" do
|
47
47
|
|
48
48
|
it "should match if uri matches and method matches" do
|
49
|
-
|
50
|
-
should match(RequestSignature.new(:get, "www.example.com"))
|
49
|
+
WebMock::RequestPattern.new(:get, "www.example.com").
|
50
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should match if uri matches and method pattern is any" do
|
54
|
-
|
55
|
-
should match(RequestSignature.new(:get, "www.example.com"))
|
54
|
+
WebMock::RequestPattern.new(:any, "www.example.com").
|
55
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should not match if request has different method" do
|
59
|
-
|
60
|
-
should_not match(RequestSignature.new(:get, "www.example.com"))
|
59
|
+
WebMock::RequestPattern.new(:post, "www.example.com").
|
60
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should match if uri matches request uri" do
|
64
|
-
|
65
|
-
should match(RequestSignature.new(:get, "www.example.com"))
|
64
|
+
WebMock::RequestPattern.new(:get, "www.example.com").
|
65
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should match if request has unescaped uri" do
|
69
|
-
|
70
|
-
should match(RequestSignature.new(:get, "www.example.com/my path"))
|
69
|
+
WebMock::RequestPattern.new(:get, "www.example.com/my%20path").
|
70
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com/my path"))
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should match if request has escaped uri" do
|
74
|
-
|
75
|
-
should match(RequestSignature.new(:get, "www.example.com/my%20path"))
|
74
|
+
WebMock::RequestPattern.new(:get, "www.example.com/my path").
|
75
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com/my%20path"))
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should match if uri regexp pattern matches unescaped form of request uri" do
|
79
|
-
|
80
|
-
should match(RequestSignature.new(:get, "www.example.com/my%20path"))
|
79
|
+
WebMock::RequestPattern.new(:get, /.*my path.*/).
|
80
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com/my%20path"))
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should match if uri regexp pattern matches request uri" do
|
84
|
-
|
85
|
-
should match(RequestSignature.new(:get, "www.example.com"))
|
84
|
+
WebMock::RequestPattern.new(:get, /.*example.*/).
|
85
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should match for uris with same parameters as pattern" do
|
89
|
-
|
90
|
-
should match(RequestSignature.new(:get, "www.example.com?a=1&b=2"))
|
89
|
+
WebMock::RequestPattern.new(:get, "www.example.com?a=1&b=2").
|
90
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com?a=1&b=2"))
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should not match for uris with different parameters" do
|
94
|
-
|
95
|
-
should_not match(RequestSignature.new(:get, "www.example.com?a=2&b=1"))
|
94
|
+
WebMock::RequestPattern.new(:get, "www.example.com?a=1&b=2").
|
95
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com?a=2&b=1"))
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should match for uri parameters in different order" do
|
99
|
-
|
100
|
-
should match(RequestSignature.new(:get, "www.example.com?a=1&b=2"))
|
99
|
+
WebMock::RequestPattern.new(:get, "www.example.com?b=2&a=1").
|
100
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com?a=1&b=2"))
|
101
101
|
end
|
102
102
|
|
103
103
|
describe "when parameters are escaped" do
|
104
104
|
|
105
105
|
it "should match if uri pattern has escaped parameters and request has unescaped parameters" do
|
106
|
-
|
107
|
-
should match(RequestSignature.new(:get, "www.example.com/?a=a b"))
|
106
|
+
WebMock::RequestPattern.new(:get, "www.example.com/?a=a%20b").
|
107
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a b"))
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should match if uri pattern has unescaped parameters and request has escaped parameters" do
|
111
|
-
|
112
|
-
should match(RequestSignature.new(:get, "www.example.com/?a=a%20b"))
|
111
|
+
WebMock::RequestPattern.new(:get, "www.example.com/?a=a b").
|
112
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a%20b"))
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should match if uri regexp pattern matches uri with unescaped parameters and request has escaped parameters" do
|
116
|
-
|
117
|
-
should match(RequestSignature.new(:get, "www.example.com/?a=a%20b"))
|
116
|
+
WebMock::RequestPattern.new(:get, /.*a=a b.*/).
|
117
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a%20b"))
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should match if uri regexp pattern matches uri with escaped parameters and request has unescaped parameters" do
|
121
|
-
|
122
|
-
should match(RequestSignature.new(:get, "www.example.com/?a=a b"))
|
121
|
+
WebMock::RequestPattern.new(:get, /.*a=a%20b.*/).
|
122
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com/?a=a b"))
|
123
123
|
end
|
124
124
|
|
125
125
|
end
|
@@ -127,33 +127,33 @@ describe RequestPattern do
|
|
127
127
|
describe "when matching requests on query params" do
|
128
128
|
|
129
129
|
it "should match request query params even if uri is declared as regexp" do
|
130
|
-
|
131
|
-
should match(RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
130
|
+
WebMock::RequestPattern.new(:get, /.*example.*/, :query => {"a" => ["b", "c"]}).
|
131
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should match request query params if uri is declared as regexp but params don't match" do
|
135
|
-
|
136
|
-
should_not match(RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
135
|
+
WebMock::RequestPattern.new(:get, /.*example.*/, :query => {"x" => ["b", "c"]}).
|
136
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
137
137
|
end
|
138
138
|
|
139
139
|
it "should match for query params are the same as declared in hash" do
|
140
|
-
|
141
|
-
should match(RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
140
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]}).
|
141
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should not match for query params are different than the declared in hash" do
|
145
|
-
|
146
|
-
should_not match(RequestSignature.new(:get, "www.example.com?x[]=b&a[]=c"))
|
145
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]}).
|
146
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com?x[]=b&a[]=c"))
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should match for query params are the same as declared as string" do
|
150
|
-
|
151
|
-
should match(RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
150
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :query => "a[]=b&a[]=c").
|
151
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should match for query params are the same as declared both in query option or url" do
|
155
|
-
|
156
|
-
should match(RequestSignature.new(:get, "www.example.com/?x=3&a[]=b&a[]=c"))
|
155
|
+
WebMock::RequestPattern.new(:get, "www.example.com/?x=3", :query => "a[]=b&a[]=c").
|
156
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com/?x=3&a[]=b&a[]=c"))
|
157
157
|
end
|
158
158
|
|
159
159
|
end
|
@@ -161,43 +161,43 @@ describe RequestPattern do
|
|
161
161
|
describe "when matching requests with body" do
|
162
162
|
|
163
163
|
it "should match if request body and body pattern are the same" do
|
164
|
-
|
165
|
-
should match(RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
164
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc").
|
165
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
166
166
|
end
|
167
167
|
|
168
168
|
it "should match if request body matches regexp" do
|
169
|
-
|
170
|
-
should match(RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
169
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :body => /^abc$/).
|
170
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
171
171
|
end
|
172
172
|
|
173
173
|
it "should not match if body pattern is different than request body" do
|
174
|
-
|
175
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
174
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :body => "def").
|
175
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
176
176
|
end
|
177
177
|
|
178
178
|
it "should not match if request body doesn't match regexp pattern" do
|
179
|
-
|
180
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :body => "xabc"))
|
179
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :body => /^abc$/).
|
180
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "xabc"))
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should match if pattern doesn't have specified body" do
|
184
|
-
|
185
|
-
should match(RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
184
|
+
WebMock::RequestPattern.new(:get, "www.example.com").
|
185
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should not match if pattern has body specified as nil but request body is not empty" do
|
189
|
-
|
190
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
189
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :body => nil).
|
190
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should not match if pattern has empty body but request body is not empty" do
|
194
|
-
|
195
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
194
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :body => "").
|
195
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :body => "abc"))
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should not match if pattern has body specified but request has no body" do
|
199
|
-
|
200
|
-
should_not match(RequestSignature.new(:get, "www.example.com"))
|
199
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :body => "abc").
|
200
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
201
201
|
end
|
202
202
|
|
203
203
|
describe "when body in pattern is declared as a hash" do
|
@@ -205,43 +205,43 @@ describe RequestPattern do
|
|
205
205
|
|
206
206
|
describe "for request with url encoded body" do
|
207
207
|
it "should match when hash matches body" do
|
208
|
-
|
209
|
-
should match(RequestSignature.new(:post, "www.example.com", :body => 'a=1&c[d][]=e&c[d][]=f&b=five'))
|
208
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
209
|
+
should match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a=1&c[d][]=e&c[d][]=f&b=five'))
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should match when hash matches body in different order of params" do
|
213
|
-
|
214
|
-
should match(RequestSignature.new(:post, "www.example.com", :body => 'a=1&c[d][]=e&b=five&c[d][]=f'))
|
213
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
214
|
+
should match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'a=1&c[d][]=e&b=five&c[d][]=f'))
|
215
215
|
end
|
216
216
|
|
217
217
|
it "should not match when hash doesn't match url encoded body" do
|
218
|
-
|
219
|
-
should_not match(RequestSignature.new(:post, "www.example.com", :body => 'c[d][]=f&a=1&c[d][]=e'))
|
218
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
219
|
+
should_not match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'c[d][]=f&a=1&c[d][]=e'))
|
220
220
|
end
|
221
221
|
|
222
222
|
it "should not match when body is not url encoded" do
|
223
|
-
|
224
|
-
should_not match(RequestSignature.new(:post, "www.example.com", :body => 'foo bar'))
|
223
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
224
|
+
should_not match(WebMock::RequestSignature.new(:post, "www.example.com", :body => 'foo bar'))
|
225
225
|
end
|
226
226
|
|
227
227
|
end
|
228
228
|
|
229
229
|
describe "for request with json body and content type is set to json" do
|
230
230
|
it "should match when hash matches body" do
|
231
|
-
|
232
|
-
should match(RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/json'},
|
231
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
232
|
+
should match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/json'},
|
233
233
|
:body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}"))
|
234
234
|
end
|
235
235
|
|
236
236
|
it "should match if hash matches body in different form" do
|
237
|
-
|
238
|
-
should match(RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/json'},
|
237
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
238
|
+
should match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/json'},
|
239
239
|
:body => "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}"))
|
240
240
|
end
|
241
241
|
|
242
242
|
it "should not match when body is not json" do
|
243
|
-
|
244
|
-
should_not match(RequestSignature.new(:post, "www.example.com",
|
243
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
244
|
+
should_not match(WebMock::RequestSignature.new(:post, "www.example.com",
|
245
245
|
:headers => {:content_type => 'application/json'}, :body => "foo bar"))
|
246
246
|
end
|
247
247
|
end
|
@@ -250,20 +250,20 @@ describe RequestPattern do
|
|
250
250
|
let(:body_hash) { {"opt" => {:a => '1', :b => 'five', 'c' => {'d' => ['e', 'f']}}} }
|
251
251
|
|
252
252
|
it "should match when hash matches body" do
|
253
|
-
|
254
|
-
should match(RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/xml'},
|
253
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
254
|
+
should match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/xml'},
|
255
255
|
:body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))
|
256
256
|
end
|
257
257
|
|
258
258
|
it "should match if hash matches body in different form" do
|
259
|
-
|
260
|
-
should match(RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/xml'},
|
259
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
260
|
+
should match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/xml'},
|
261
261
|
:body => "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))
|
262
262
|
end
|
263
263
|
|
264
264
|
it "should not match when body is not xml" do
|
265
|
-
|
266
|
-
should_not match(RequestSignature.new(:post, "www.example.com",
|
265
|
+
WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
|
266
|
+
should_not match(WebMock::RequestSignature.new(:post, "www.example.com",
|
267
267
|
:headers => {:content_type => 'application/xml'}, :body => "foo bar"))
|
268
268
|
end
|
269
269
|
end
|
@@ -273,78 +273,78 @@ describe RequestPattern do
|
|
273
273
|
|
274
274
|
|
275
275
|
it "should match if pattern and request have the same headers" do
|
276
|
-
|
277
|
-
should match(RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
276
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}).
|
277
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
278
278
|
end
|
279
279
|
|
280
280
|
it "should match if pattern headers values are regexps matching request header values" do
|
281
|
-
|
282
|
-
should match(RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
281
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => %r{^image/jpeg$}}).
|
282
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
283
283
|
end
|
284
284
|
|
285
285
|
it "should not match if pattern has different value of header than request" do
|
286
|
-
|
287
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
286
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/png'}).
|
287
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
288
288
|
end
|
289
289
|
|
290
290
|
it "should not match if pattern header value regexp doesn't match request header value" do
|
291
|
-
|
292
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpegx'}))
|
291
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => %r{^image\/jpeg$}}).
|
292
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpegx'}))
|
293
293
|
end
|
294
294
|
|
295
295
|
it "should match if request has more headers than request pattern" do
|
296
|
-
|
297
|
-
should match(RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg', 'Content-Length' => '8888'}))
|
296
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}).
|
297
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg', 'Content-Length' => '8888'}))
|
298
298
|
end
|
299
299
|
|
300
300
|
it "should not match if request has less headers than the request pattern" do
|
301
|
-
|
302
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
301
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg', 'Content-Length' => '8888'}).
|
302
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'Content-Type' => 'image/jpeg'}))
|
303
303
|
end
|
304
304
|
|
305
305
|
it "should match even is header keys are declared in different form" do
|
306
|
-
|
307
|
-
should match(RequestSignature.new(:get, "www.example.com", :headers => {:ContentLength => 8888, 'content_type' => 'image/png'}))
|
306
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'ContentLength' => '8888', 'Content-type' => 'image/png'}).
|
307
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {:ContentLength => 8888, 'content_type' => 'image/png'}))
|
308
308
|
end
|
309
309
|
|
310
310
|
it "should match is pattern doesn't have specified headers" do
|
311
|
-
|
312
|
-
should match(RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}))
|
311
|
+
WebMock::RequestPattern.new(:get, "www.example.com").
|
312
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}))
|
313
313
|
end
|
314
314
|
|
315
315
|
it "should not match if pattern has nil headers but request has headers" do
|
316
|
-
|
317
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}))
|
316
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => nil).
|
317
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}))
|
318
318
|
end
|
319
319
|
|
320
320
|
it "should not match if pattern has empty headers but request has headers" do
|
321
|
-
|
322
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}))
|
321
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {}).
|
322
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {'A' => 'a'}))
|
323
323
|
end
|
324
324
|
|
325
325
|
it "should not match if pattern has specified headers but request has nil headers" do
|
326
|
-
|
327
|
-
should_not match(RequestSignature.new(:get, "www.example.com"))
|
326
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A'=>'a'}).
|
327
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
328
328
|
end
|
329
329
|
|
330
330
|
it "should not match if pattern has specified headers but request has empty headers" do
|
331
|
-
|
332
|
-
should_not match(RequestSignature.new(:get, "www.example.com", :headers => {}))
|
331
|
+
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A'=>'a'}).
|
332
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com", :headers => {}))
|
333
333
|
end
|
334
334
|
|
335
335
|
it "should match if block given in pattern evaluates request to true" do
|
336
|
-
|
337
|
-
should match(RequestSignature.new(:get, "www.example.com"))
|
336
|
+
WebMock::RequestPattern.new(:get, "www.example.com").with { |request| true }.
|
337
|
+
should match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
338
338
|
end
|
339
339
|
|
340
340
|
it "should not match if block given in pattrn evaluates request to false" do
|
341
|
-
|
342
|
-
should_not match(RequestSignature.new(:get, "www.example.com"))
|
341
|
+
WebMock::RequestPattern.new(:get, "www.example.com").with { |request| false }.
|
342
|
+
should_not match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
343
343
|
end
|
344
344
|
|
345
345
|
it "should yield block with request signature" do
|
346
|
-
signature = RequestSignature.new(:get, "www.example.com")
|
347
|
-
|
346
|
+
signature = WebMock::RequestSignature.new(:get, "www.example.com")
|
347
|
+
WebMock::RequestPattern.new(:get, "www.example.com").with { |request| request == signature }.
|
348
348
|
should match(signature)
|
349
349
|
end
|
350
350
|
|