webmock 1.20.3 → 1.20.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/README.md +21 -22
  3. data/lib/webmock/matchers/hash_including_matcher.rb +1 -1
  4. data/lib/webmock/version.rb +1 -1
  5. data/spec/acceptance/curb/curb_spec.rb +36 -36
  6. data/spec/acceptance/em_http_request/em_http_request_spec.rb +24 -24
  7. data/spec/acceptance/excon/excon_spec.rb +11 -11
  8. data/spec/acceptance/httpclient/httpclient_spec.rb +9 -9
  9. data/spec/acceptance/net_http/net_http_shared.rb +23 -23
  10. data/spec/acceptance/net_http/net_http_spec.rb +29 -29
  11. data/spec/acceptance/patron/patron_spec.rb +11 -11
  12. data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +29 -29
  13. data/spec/acceptance/shared/callbacks.rb +18 -18
  14. data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +3 -3
  15. data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +10 -10
  16. data/spec/acceptance/shared/precedence_of_stubs.rb +2 -2
  17. data/spec/acceptance/shared/request_expectations.rb +302 -302
  18. data/spec/acceptance/shared/returning_declared_responses.rb +92 -92
  19. data/spec/acceptance/shared/stubbing_requests.rb +103 -103
  20. data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +8 -8
  21. data/spec/quality_spec.rb +3 -3
  22. data/spec/spec_helper.rb +0 -6
  23. data/spec/unit/errors_spec.rb +16 -16
  24. data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +1 -1
  25. data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +2 -2
  26. data/spec/unit/rack_response_spec.rb +14 -14
  27. data/spec/unit/request_execution_verifier_spec.rb +31 -31
  28. data/spec/unit/request_pattern_spec.rb +202 -197
  29. data/spec/unit/request_registry_spec.rb +10 -9
  30. data/spec/unit/request_signature_spec.rb +21 -20
  31. data/spec/unit/request_stub_spec.rb +54 -53
  32. data/spec/unit/response_spec.rb +44 -44
  33. data/spec/unit/stub_registry_spec.rb +15 -15
  34. data/spec/unit/stub_request_snippet_spec.rb +8 -8
  35. data/spec/unit/util/hash_counter_spec.rb +6 -6
  36. data/spec/unit/util/hash_keys_stringifier_spec.rb +1 -1
  37. data/spec/unit/util/headers_spec.rb +4 -4
  38. data/spec/unit/util/json_spec.rb +1 -1
  39. data/spec/unit/util/uri_spec.rb +30 -30
  40. data/spec/unit/util/version_checker_spec.rb +9 -9
  41. data/spec/unit/webmock_spec.rb +1 -1
  42. data/webmock.gemspec +1 -1
  43. metadata +10 -9
@@ -4,126 +4,126 @@ shared_context "declared responses" do |*adapter_info|
4
4
  describe "when request stub declares that request should raise exception" do
5
5
  it "should raise exception" do
6
6
  stub_request(:get, "www.example.com").to_raise(MyException)
7
- lambda {
7
+ expect {
8
8
  http_request(:get, "http://www.example.com/")
9
- }.should raise_error(MyException, "Exception from WebMock")
9
+ }.to raise_error(MyException, "Exception from WebMock")
10
10
  end
11
11
 
12
12
  it "should raise exception if declared as and exception instance" do
13
13
  stub_request(:get, "www.example.com").to_raise(MyException.new("hello world"))
14
- lambda {
14
+ expect {
15
15
  http_request(:get, "http://www.example.com/")
16
- }.should raise_error(MyException, "hello world")
16
+ }.to raise_error(MyException, "hello world")
17
17
  end
18
18
 
19
19
  it "should raise exception if declared as an exception instance" do
20
20
  stub_request(:get, "www.example.com").to_raise("hello world")
21
- lambda {
21
+ expect {
22
22
  http_request(:get, "http://www.example.com/")
23
- }.should raise_error("hello world")
23
+ }.to raise_error("hello world")
24
24
  end
25
25
 
26
26
  it "should raise exception after returning declared successful response first" do
27
27
  stub_request(:get, "www.example.com").to_return(:body => "abc").then.to_raise(MyException)
28
- http_request(:get, "http://www.example.com/").body.should == "abc"
29
- lambda {
28
+ expect(http_request(:get, "http://www.example.com/").body).to eq("abc")
29
+ expect {
30
30
  http_request(:get, "http://www.example.com/")
31
- }.should raise_error(MyException, "Exception from WebMock")
31
+ }.to raise_error(MyException, "Exception from WebMock")
32
32
  end
33
33
  end
34
34
 
35
35
  describe "when request stub declares that request should timeout" do
36
36
  it "should timeout" do
37
37
  stub_request(:get, "www.example.com").to_timeout
38
- lambda {
38
+ expect {
39
39
  http_request(:get, "http://www.example.com/")
40
- }.should raise_error(client_timeout_exception_class)
40
+ }.to raise_error(client_timeout_exception_class)
41
41
  end
42
42
 
43
43
  it "should timeout after returning declared successful response" do
44
44
  stub_request(:get, "www.example.com").to_return(:body => "abc").then.to_timeout
45
- http_request(:get, "http://www.example.com/").body.should == "abc"
46
- lambda {
45
+ expect(http_request(:get, "http://www.example.com/").body).to eq("abc")
46
+ expect {
47
47
  http_request(:get, "http://www.example.com/")
48
- }.should raise_error(client_timeout_exception_class)
48
+ }.to raise_error(client_timeout_exception_class)
49
49
  end
50
50
  end
51
51
 
52
52
  describe "when request stub declares that request should return a response" do
53
53
  it "should return response with declared body" do
54
54
  stub_request(:get, "www.example.com").to_return(:body => "abc")
55
- http_request(:get, "http://www.example.com/").body.should == "abc"
55
+ expect(http_request(:get, "http://www.example.com/").body).to eq("abc")
56
56
  end
57
57
 
58
58
  it "should return response with declared headers" do
59
59
  stub_request(:get, "www.example.com").to_return(:headers => SAMPLE_HEADERS)
60
60
  response = http_request(:get, "http://www.example.com/")
61
- response.headers["Content-Length"].should == "8888"
61
+ expect(response.headers["Content-Length"]).to eq("8888")
62
62
  end
63
63
 
64
64
  it "should return response with declared headers even if there are multiple headers with the same key" do
65
65
  stub_request(:get, "www.example.com").to_return(:headers => {"a" => ["b", "c"]})
66
66
  response = http_request(:get, "http://www.example.com/")
67
- response.headers["A"].should == "b, c"
67
+ expect(response.headers["A"]).to eq("b, c")
68
68
  end
69
69
 
70
70
  it "should return response with declared status code" do
71
71
  stub_request(:get, "www.example.com").to_return(:status => 500)
72
- http_request(:get, "http://www.example.com/").status.should == "500"
72
+ expect(http_request(:get, "http://www.example.com/").status).to eq("500")
73
73
  end
74
74
 
75
75
  it "should return response with declared status message", :unless => (adapter_info.include?(:no_status_message)) do
76
76
  stub_request(:get, "www.example.com").to_return(:status => [500, "Internal Server Error"])
77
77
  response = http_request(:get, "http://www.example.com/")
78
- response.message.should == "Internal Server Error"
78
+ expect(response.message).to eq("Internal Server Error")
79
79
  end
80
80
 
81
81
  it "should return response with a default status code" do
82
82
  stub_request(:get, "www.example.com")
83
- http_request(:get, "http://www.example.com/").status.should == "200"
83
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
84
84
  end
85
85
 
86
86
  it "should return default response with empty message if response was not declared", :unless => (adapter_info.include?(:no_status_message)) do
87
87
  stub_request(:get, "www.example.com")
88
88
  response = http_request(:get, "http://www.example.com/")
89
- response.message.should == ""
89
+ expect(response.message).to eq("")
90
90
  end
91
91
 
92
92
  describe "when response body was declared as IO" do
93
93
  it "should return response body" do
94
94
  stub_request(:get, "www.example.com").to_return(:body => File.new(__FILE__))
95
- http_request(:get, "http://www.example.com/").body.should == File.read(__FILE__)
95
+ expect(http_request(:get, "http://www.example.com/").body).to eq(File.read(__FILE__))
96
96
  end
97
97
 
98
98
  it "should return response body if requested many times" do
99
99
  stub_request(:get, "www.example.com").to_return(:body => File.new(__FILE__))
100
100
  2.times do
101
- http_request(:get, "http://www.example.com/").body.should == File.read(__FILE__)
101
+ expect(http_request(:get, "http://www.example.com/").body).to eq(File.read(__FILE__))
102
102
  end
103
103
  end
104
104
 
105
105
  it "should close IO after request" do
106
106
  stub_request(:get, "www.example.com").to_return(:body => @file = File.new(__FILE__))
107
- @file.should be_closed
107
+ expect(@file).to be_closed
108
108
  end
109
109
  end
110
110
 
111
111
  describe "when response parts were declared as lambdas" do
112
112
  it "should return evaluated response body" do
113
113
  stub_request(:post, "www.example.com").to_return(:body => lambda { |request| request.body })
114
- http_request(:post, "http://www.example.com/", :body => "echo").body.should == "echo"
114
+ expect(http_request(:post, "http://www.example.com/", :body => "echo").body).to eq("echo")
115
115
  end
116
116
 
117
117
  it "should return evaluated response headers" do
118
118
  stub_request(:post, "www.example.com").to_return(:headers => lambda { |request| request.headers })
119
- http_request(:post, "http://www.example.com/", :body => "abc", :headers => {'A' => 'B'}).headers['A'].should == 'B'
120
- http_request(:post, "http://www.example.com/", :body => "abc", :headers => {'A' => 'C'}).headers['A'].should == 'C'
119
+ expect(http_request(:post, "http://www.example.com/", :body => "abc", :headers => {'A' => 'B'}).headers['A']).to eq('B')
120
+ expect(http_request(:post, "http://www.example.com/", :body => "abc", :headers => {'A' => 'C'}).headers['A']).to eq('C')
121
121
  end
122
122
 
123
123
  it "should evaluate response body for each request" do
124
124
  stub_request(:post, "www.example.com").to_return(:body => lambda { |request| request.body })
125
- http_request(:post, "http://www.example.com/", :body => "echo").body.should == "echo"
126
- http_request(:post, "http://www.example.com/", :body => "foxtrot").body.should == "foxtrot"
125
+ expect(http_request(:post, "http://www.example.com/", :body => "echo").body).to eq("echo")
126
+ expect(http_request(:post, "http://www.example.com/", :body => "foxtrot").body).to eq("foxtrot")
127
127
  end
128
128
  end
129
129
 
@@ -138,27 +138,27 @@ shared_context "declared responses" do |*adapter_info|
138
138
  stub_request(:post, "www.example.com").to_return(lambda {|request|
139
139
  {:body => request.body}
140
140
  })
141
- http_request(:post, "http://www.example.com/", :body => "echo").body.should == "echo"
142
- http_request(:post, "http://www.example.com/", :body => "foxtrot").body.should == "foxtrot"
141
+ expect(http_request(:post, "http://www.example.com/", :body => "echo").body).to eq("echo")
142
+ expect(http_request(:post, "http://www.example.com/", :body => "foxtrot").body).to eq("foxtrot")
143
143
  end
144
144
 
145
145
  it "should return evaluated response headers" do
146
146
  stub_request(:get, "www.example.com").to_return(lambda { |request|
147
147
  {:headers => request.headers}
148
148
  })
149
- http_request(:get, "http://www.example.com/", :headers => {'A' => 'B'}).headers['A'].should == 'B'
149
+ expect(http_request(:get, "http://www.example.com/", :headers => {'A' => 'B'}).headers['A']).to eq('B')
150
150
  end
151
151
 
152
152
  it "should return dynamic response declared as a block" do
153
153
  stub_request(:post, "www.example.com").to_return do |request|
154
154
  {:body => request.body}
155
155
  end
156
- http_request(:post, "http://www.example.com/", :body => "echo").body.should == "echo"
156
+ expect(http_request(:post, "http://www.example.com/", :body => "echo").body).to eq("echo")
157
157
  end
158
158
 
159
159
  it "should return dynamic response declared as an object responding to call" do
160
160
  stub_request(:post, "www.example.com").to_return(Responder.new)
161
- http_request(:post, "http://www.example.com/", :body => "echo").body.should == "echo"
161
+ expect(http_request(:post, "http://www.example.com/", :body => "echo").body).to eq("echo")
162
162
  end
163
163
  end
164
164
 
@@ -171,29 +171,29 @@ shared_context "declared responses" do |*adapter_info|
171
171
  end
172
172
 
173
173
  it "should return recorded headers" do
174
- @response.headers.should == {
174
+ expect(@response.headers).to eq({
175
175
  "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
176
176
  "Content-Type"=>"text/html; charset=UTF-8",
177
177
  "Content-Length"=>"419",
178
178
  "Connection"=>"Keep-Alive",
179
179
  "Accept"=>"image/jpeg, image/png"
180
- }
180
+ })
181
181
  end
182
182
 
183
183
  it "should return recorded body" do
184
- @response.body.size.should == 419
184
+ expect(@response.body.size).to eq(419)
185
185
  end
186
186
 
187
187
  it "should return recorded status" do
188
- @response.status.should == "202"
188
+ expect(@response.status).to eq("202")
189
189
  end
190
190
 
191
191
  it "should return recorded status message", :unless => (adapter_info.include?(:no_status_message)) do
192
- @response.message.should == "OK"
192
+ expect(@response.message).to eq("OK")
193
193
  end
194
194
 
195
195
  it "should ensure file is closed" do
196
- @file.should be_closed
196
+ expect(@file).to be_closed
197
197
  end
198
198
  end
199
199
 
@@ -205,25 +205,25 @@ shared_context "declared responses" do |*adapter_info|
205
205
  end
206
206
 
207
207
  it "should return recorded headers" do
208
- @response.headers.should == {
208
+ expect(@response.headers).to eq({
209
209
  "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
210
210
  "Content-Type"=>"text/html; charset=UTF-8",
211
211
  "Content-Length"=>"419",
212
212
  "Connection"=>"Keep-Alive",
213
213
  "Accept"=>"image/jpeg, image/png"
214
- }
214
+ })
215
215
  end
216
216
 
217
217
  it "should return recorded body" do
218
- @response.body.size.should == 419
218
+ expect(@response.body.size).to eq(419)
219
219
  end
220
220
 
221
221
  it "should return recorded status" do
222
- @response.status.should == "202"
222
+ expect(@response.status).to eq("202")
223
223
  end
224
224
 
225
225
  it "should return recorded status message", :unless => (adapter_info.include?(:no_status_message)) do
226
- @response.message.should == "OK"
226
+ expect(@response.message).to eq("OK")
227
227
  end
228
228
  end
229
229
 
@@ -236,24 +236,24 @@ shared_context "declared responses" do |*adapter_info|
236
236
 
237
237
  it "should return response from evaluated file" do
238
238
  stub_request(:get, "www.example.com").to_return(lambda {|request| @files[request.uri.host.to_s] })
239
- http_request(:get, "http://www.example.com/").body.size.should == 419
239
+ expect(http_request(:get, "http://www.example.com/").body.size).to eq(419)
240
240
  end
241
241
 
242
242
  it "should return response from evaluated string" do
243
243
  stub_request(:get, "www.example.com").to_return(lambda {|request| @files[request.uri.host.to_s].read })
244
- http_request(:get, "http://www.example.com/").body.size.should == 419
244
+ expect(http_request(:get, "http://www.example.com/").body.size).to eq(419)
245
245
  end
246
246
  end
247
247
 
248
248
  describe "when response is declared as an Rack app" do
249
249
  it "should return response returned by the rack app" do
250
250
  stub_request(:any, "http://www.example.com/greet").to_rack(MyRackApp)
251
- http_request(:post, 'http://www.example.com/greet', :body => 'name=Jimmy').body.should == 'Good to meet you, Jimmy!'
251
+ expect(http_request(:post, 'http://www.example.com/greet', :body => 'name=Jimmy').body).to eq('Good to meet you, Jimmy!')
252
252
  end
253
253
 
254
254
  it "should pass along the port number to the rack app" do
255
255
  stub_request(:get, "http://www.example.com/compute").to_rack(MyRackApp)
256
- http_request(:get, "http://www.example.com/compute").status.should == "200"
256
+ expect(http_request(:get, "http://www.example.com/compute").status).to eq("200")
257
257
  end
258
258
 
259
259
  it "preserves content-type header when proxying to a rack app" do
@@ -266,30 +266,30 @@ shared_context "declared responses" do |*adapter_info|
266
266
  }
267
267
 
268
268
  http_request(:get, url, :headers => headers)
269
- WebMock.should have_requested(:get, url).with(:headers => headers)
269
+ expect(WebMock).to have_requested(:get, url).with(:headers => headers)
270
270
  end
271
271
  end
272
272
 
273
273
  describe "when sequences of responses are declared" do
274
274
  it "should return responses one by one if declared in array" do
275
275
  stub_request(:get, "www.example.com").to_return([ {:body => "1"}, {:body => "2"}, {:body => "3"} ])
276
- http_request(:get, "http://www.example.com/").body.should == "1"
277
- http_request(:get, "http://www.example.com/").body.should == "2"
278
- http_request(:get, "http://www.example.com/").body.should == "3"
276
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
277
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
278
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
279
279
  end
280
280
 
281
281
  it "should repeat returning last declared response from a sequence after all responses were returned" do
282
282
  stub_request(:get, "www.example.com").to_return([ {:body => "1"}, {:body => "2"} ])
283
- http_request(:get, "http://www.example.com/").body.should == "1"
284
- http_request(:get, "http://www.example.com/").body.should == "2"
285
- http_request(:get, "http://www.example.com/").body.should == "2"
283
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
284
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
285
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
286
286
  end
287
287
 
288
288
  it "should return responses one by one if declared as comma separated params" do
289
289
  stub_request(:get, "www.example.com").to_return({:body => "1"}, {:body => "2"}, {:body => "3"})
290
- http_request(:get, "http://www.example.com/").body.should == "1"
291
- http_request(:get, "http://www.example.com/").body.should == "2"
292
- http_request(:get, "http://www.example.com/").body.should == "3"
290
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
291
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
292
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
293
293
  end
294
294
 
295
295
  it "should return responses one by one if declared with several to_return invokations" do
@@ -297,17 +297,17 @@ shared_context "declared responses" do |*adapter_info|
297
297
  to_return({:body => "1"}).
298
298
  to_return({:body => "2"}).
299
299
  to_return({:body => "3"})
300
- http_request(:get, "http://www.example.com/").body.should == "1"
301
- http_request(:get, "http://www.example.com/").body.should == "2"
302
- http_request(:get, "http://www.example.com/").body.should == "3"
300
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
301
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
302
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
303
303
  end
304
304
 
305
305
  it "should return responses one by one if declared with to_return invocations separated with then syntactic sugar" do
306
306
  stub_request(:get, "www.example.com").to_return({:body => "1"}).then.
307
307
  to_return({:body => "2"}).then.to_return({:body => "3"})
308
- http_request(:get, "http://www.example.com/").body.should == "1"
309
- http_request(:get, "http://www.example.com/").body.should == "2"
310
- http_request(:get, "http://www.example.com/").body.should == "3"
308
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
309
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
310
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
311
311
  end
312
312
 
313
313
  end
@@ -317,9 +317,9 @@ shared_context "declared responses" do |*adapter_info|
317
317
  stub_request(:get, "www.example.com").
318
318
  to_return({:body => "1"}).times(2).
319
319
  to_return({:body => "2"})
320
- http_request(:get, "http://www.example.com/").body.should == "1"
321
- http_request(:get, "http://www.example.com/").body.should == "1"
322
- http_request(:get, "http://www.example.com/").body.should == "2"
320
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
321
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
322
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
323
323
  end
324
324
 
325
325
 
@@ -327,26 +327,26 @@ shared_context "declared responses" do |*adapter_info|
327
327
  stub_request(:get, "www.example.com").
328
328
  to_return({:body => "1"}, {:body => "2"}).times(2).
329
329
  to_return({:body => "3"})
330
- http_request(:get, "http://www.example.com/").body.should == "1"
331
- http_request(:get, "http://www.example.com/").body.should == "2"
332
- http_request(:get, "http://www.example.com/").body.should == "1"
333
- http_request(:get, "http://www.example.com/").body.should == "2"
334
- http_request(:get, "http://www.example.com/").body.should == "3"
330
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
331
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
332
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
333
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
334
+ expect(http_request(:get, "http://www.example.com/").body).to eq("3")
335
335
  end
336
336
 
337
337
 
338
338
  it "should repeat infinitely last response even if number of declared times is lower" do
339
339
  stub_request(:get, "www.example.com").
340
340
  to_return({:body => "1"}).times(2)
341
- http_request(:get, "http://www.example.com/").body.should == "1"
342
- http_request(:get, "http://www.example.com/").body.should == "1"
343
- http_request(:get, "http://www.example.com/").body.should == "1"
341
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
342
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
343
+ expect(http_request(:get, "http://www.example.com/").body).to eq("1")
344
344
  end
345
345
 
346
346
  it "should give error if times is declared without specifying response" do
347
- lambda {
347
+ expect {
348
348
  stub_request(:get, "www.example.com").times(3)
349
- }.should raise_error("Invalid WebMock stub declaration. times(N) can be declared only after response declaration.")
349
+ }.to raise_error("Invalid WebMock stub declaration. times(N) can be declared only after response declaration.")
350
350
  end
351
351
 
352
352
  end
@@ -356,32 +356,32 @@ shared_context "declared responses" do |*adapter_info|
356
356
  stub_request(:get, "www.example.com").
357
357
  to_raise(MyException).times(2).
358
358
  to_return({:body => "2"})
359
- lambda {
359
+ expect {
360
360
  http_request(:get, "http://www.example.com/")
361
- }.should raise_error(MyException, "Exception from WebMock")
362
- lambda {
361
+ }.to raise_error(MyException, "Exception from WebMock")
362
+ expect {
363
363
  http_request(:get, "http://www.example.com/")
364
- }.should raise_error(MyException, "Exception from WebMock")
365
- http_request(:get, "http://www.example.com/").body.should == "2"
364
+ }.to raise_error(MyException, "Exception from WebMock")
365
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
366
366
  end
367
367
 
368
368
  it "should repeat raising sequence of exceptions declared number of times" do
369
369
  stub_request(:get, "www.example.com").
370
370
  to_raise(MyException, ArgumentError).times(2).
371
371
  to_return({:body => "2"})
372
- lambda {
372
+ expect {
373
373
  http_request(:get, "http://www.example.com/")
374
- }.should raise_error(MyException, "Exception from WebMock")
375
- lambda {
374
+ }.to raise_error(MyException, "Exception from WebMock")
375
+ expect {
376
376
  http_request(:get, "http://www.example.com/")
377
- }.should raise_error(ArgumentError)
378
- lambda {
377
+ }.to raise_error(ArgumentError)
378
+ expect {
379
379
  http_request(:get, "http://www.example.com/")
380
- }.should raise_error(MyException, "Exception from WebMock")
381
- lambda {
380
+ }.to raise_error(MyException, "Exception from WebMock")
381
+ expect {
382
382
  http_request(:get, "http://www.example.com/")
383
- }.should raise_error(ArgumentError)
384
- http_request(:get, "http://www.example.com/").body.should == "2"
383
+ }.to raise_error(ArgumentError)
384
+ expect(http_request(:get, "http://www.example.com/").body).to eq("2")
385
385
  end
386
386
  end
387
387
  end
@@ -5,37 +5,37 @@ shared_examples_for "stubbing requests" do |*adapter_info|
5
5
  describe "based on uri" do
6
6
  it "should return stubbed response even if request have escaped parameters" do
7
7
  stub_request(:get, "www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}").to_return(:body => "abc")
8
- http_request(:get, "http://www.example.com/hello%2B/?#{ESCAPED_PARAMS}").body.should == "abc"
8
+ expect(http_request(:get, "http://www.example.com/hello%2B/?#{ESCAPED_PARAMS}").body).to eq("abc")
9
9
  end
10
10
 
11
11
  it "should return stubbed response even if query params have integer values" do
12
12
  stub_request(:get, "www.example.com").with(:query => {"a" => 1}).to_return(:body => "abc")
13
- http_request(:get, "http://www.example.com/?a=1").body.should == "abc"
13
+ expect(http_request(:get, "http://www.example.com/?a=1").body).to eq("abc")
14
14
  end
15
15
 
16
16
  it "should return stubbed response even if request has non escaped params" do
17
17
  stub_request(:get, "www.example.com/hello%2B/?#{ESCAPED_PARAMS}").to_return(:body => "abc")
18
- http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}").body.should == "abc"
18
+ expect(http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}").body).to eq("abc")
19
19
  end
20
20
 
21
21
  it "should return stubbed response for url with non utf query params", "ruby>1.9" => true do
22
22
  param = 'aäoöuü'.encode('iso-8859-1')
23
23
  param = CGI.escape(param)
24
24
  stub_request(:get, "www.example.com/?#{param}").to_return(:body => "abc")
25
- http_request(:get, "http://www.example.com/?#{param}").body.should == "abc"
25
+ expect(http_request(:get, "http://www.example.com/?#{param}").body).to eq("abc")
26
26
  end
27
27
 
28
28
  it "should return stubbed response even if stub uri is declared as regexp and request params are escaped" do
29
29
  stub_request(:get, /.*x=ab c.*/).to_return(:body => "abc")
30
- http_request(:get, "http://www.example.com/hello/?#{ESCAPED_PARAMS}").body.should == "abc"
30
+ expect(http_request(:get, "http://www.example.com/hello/?#{ESCAPED_PARAMS}").body).to eq("abc")
31
31
  end
32
32
 
33
33
  it "should raise error specifying stubbing instructions with escaped characters in params if there is no matching stub" do
34
34
  begin
35
35
  http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}")
36
36
  rescue WebMock::NetConnectNotAllowedError => e
37
- e.message.should match /Unregistered request: GET http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m/m
38
- e.message.should match /stub_request\(:get, "http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m"\)/m
37
+ expect(e.message).to match /Unregistered request: GET http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m/m
38
+ expect(e.message).to match /stub_request\(:get, "http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m"\)/m
39
39
  end
40
40
 
41
41
  stub_request(:get, "http://www.example.com/hello+/?x=ab%20c&z='Stop!'%20said%20Fred%20m")
@@ -46,42 +46,42 @@ shared_examples_for "stubbing requests" do |*adapter_info|
46
46
  describe "based on query params" do
47
47
  it "should return stubbed response when stub declares query params as a hash" do
48
48
  stub_request(:get, "www.example.com").with(:query => {"a" => ["b x", "c d"]}).to_return(:body => "abc")
49
- http_request(:get, "http://www.example.com/?a[]=b+x&a[]=c%20d").body.should == "abc"
49
+ expect(http_request(:get, "http://www.example.com/?a[]=b+x&a[]=c%20d").body).to eq("abc")
50
50
  end
51
51
 
52
52
  it "should return stubbed response when stub declares query params as a hash" do
53
53
  stub_request(:get, "www.example.com").with(:query => "a[]=b&a[]=c").to_return(:body => "abc")
54
- http_request(:get, "http://www.example.com/?a[]=b&a[]=c").body.should == "abc"
54
+ expect(http_request(:get, "http://www.example.com/?a[]=b&a[]=c").body).to eq("abc")
55
55
  end
56
56
 
57
57
  it "should return stubbed response when stub declares query params both in uri and as a hash" do
58
58
  stub_request(:get, "www.example.com/?x=3").with(:query => {"a" => ["b", "c"]}).to_return(:body => "abc")
59
- http_request(:get, "http://www.example.com/?x=3&a[]=b&a[]=c").body.should == "abc"
59
+ expect(http_request(:get, "http://www.example.com/?x=3&a[]=b&a[]=c").body).to eq("abc")
60
60
  end
61
61
 
62
62
  it "should return stubbed response when stub expects only part of query params" do
63
63
  stub_request(:get, "www.example.com").with(:query => hash_including({"a" => ["b", "c"]})).to_return(:body => "abc")
64
- http_request(:get, "http://www.example.com/?a[]=b&a[]=c&b=1").body.should == "abc"
64
+ expect(http_request(:get, "http://www.example.com/?a[]=b&a[]=c&b=1").body).to eq("abc")
65
65
  end
66
66
  end
67
67
 
68
68
  describe "based on method" do
69
69
  it "should return stubbed response" do
70
70
  stub_request(:get, "www.example.com")
71
- http_request(:get, "http://www.example.com/").status.should == "200"
71
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
72
72
  end
73
73
 
74
74
  it "should match stubbed request when http request was made with method given as string" do
75
75
  stub_request(:get, "www.example.com")
76
- http_request('get', "http://www.example.com/").status.should == "200"
76
+ expect(http_request('get', "http://www.example.com/").status).to eq("200")
77
77
  end
78
78
 
79
79
  it "should raise error if stubbed request has different method" do
80
80
  stub_request(:get, "www.example.com")
81
- http_request(:get, "http://www.example.com/").status.should == "200"
82
- lambda {
81
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
82
+ expect {
83
83
  http_request(:delete, "http://www.example.com/")
84
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: DELETE http://www.example.com/)
84
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: DELETE http://www.example.com/)
85
85
  )
86
86
  end
87
87
  end
@@ -89,38 +89,38 @@ shared_examples_for "stubbing requests" do |*adapter_info|
89
89
  describe "based on body" do
90
90
  it "should match requests if body is the same" do
91
91
  stub_request(:post, "www.example.com").with(:body => "abc")
92
- http_request(
92
+ expect(http_request(
93
93
  :post, "http://www.example.com/",
94
- :body => "abc").status.should == "200"
94
+ :body => "abc").status).to eq("200")
95
95
  end
96
96
 
97
97
  it "should match requests if body is not set in the stub" do
98
98
  stub_request(:post, "www.example.com")
99
- http_request(
99
+ expect(http_request(
100
100
  :post, "http://www.example.com/",
101
- :body => "abc").status.should == "200"
101
+ :body => "abc").status).to eq("200")
102
102
  end
103
103
 
104
104
  it "should not match requests if body is different" do
105
105
  stub_request(:post, "www.example.com").with(:body => "abc")
106
- lambda {
106
+ expect {
107
107
  http_request(:post, "http://www.example.com/", :body => "def")
108
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'def'))
108
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'def'))
109
109
  end
110
110
 
111
111
  describe "with regular expressions" do
112
112
  it "should match requests if body matches regexp" do
113
113
  stub_request(:post, "www.example.com").with(:body => /\d+abc$/)
114
- http_request(
114
+ expect(http_request(
115
115
  :post, "http://www.example.com/",
116
- :body => "123abc").status.should == "200"
116
+ :body => "123abc").status).to eq("200")
117
117
  end
118
118
 
119
119
  it "should not match requests if body doesn't match regexp" do
120
120
  stub_request(:post, "www.example.com").with(:body => /^abc/)
121
- lambda {
121
+ expect {
122
122
  http_request(:post, "http://www.example.com/", :body => "xabc")
123
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'xabc'))
123
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'xabc'))
124
124
  end
125
125
  end
126
126
 
@@ -132,55 +132,55 @@ shared_examples_for "stubbing requests" do |*adapter_info|
132
132
 
133
133
  describe "for request with url encoded body" do
134
134
  it "should match request if hash matches body" do
135
- http_request(
135
+ expect(http_request(
136
136
  :post, "http://www.example.com/",
137
- :body => 'a=1&c[d][]=e&c[d][]=f&b=five+x').status.should == "200"
137
+ :body => 'a=1&c[d][]=e&c[d][]=f&b=five+x').status).to eq("200")
138
138
  end
139
139
 
140
140
  it "should match request if hash matches body in different order of params" do
141
- http_request(
141
+ expect(http_request(
142
142
  :post, "http://www.example.com/",
143
- :body => 'a=1&c[d][]=e&b=five+x&c[d][]=f').status.should == "200"
143
+ :body => 'a=1&c[d][]=e&b=five+x&c[d][]=f').status).to eq("200")
144
144
  end
145
145
 
146
146
  it "should not match if hash doesn't match url encoded body" do
147
- lambda {
147
+ expect {
148
148
  http_request(
149
149
  :post, "http://www.example.com/",
150
150
  :body => 'c[d][]=f&a=1&c[d][]=e')
151
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'c\[d\]\[\]=f&a=1&c\[d\]\[\]=e'))
151
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'c\[d\]\[\]=f&a=1&c\[d\]\[\]=e'))
152
152
  end
153
153
  end
154
154
 
155
155
 
156
156
  describe "for request with json body and content type is set to json" do
157
157
  it "should match if hash matches body" do
158
- http_request(
158
+ expect(http_request(
159
159
  :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
160
- :body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five x\"}").status.should == "200"
160
+ :body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five x\"}").status).to eq("200")
161
161
  end
162
162
 
163
163
  it "should match if hash matches body in different form" do
164
- http_request(
164
+ expect(http_request(
165
165
  :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
166
- :body => "{\"a\":\"1\",\"b\":\"five x\",\"c\":{\"d\":[\"e\",\"f\"]}}").status.should == "200"
166
+ :body => "{\"a\":\"1\",\"b\":\"five x\",\"c\":{\"d\":[\"e\",\"f\"]}}").status).to eq("200")
167
167
  end
168
168
 
169
169
  it "should match if hash contains date string" do #Crack creates date object
170
170
  WebMock.reset!
171
171
  stub_request(:post, "www.example.com").
172
172
  with(:body => {"foo" => "2010-01-01"})
173
- http_request(
173
+ expect(http_request(
174
174
  :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
175
- :body => "{\"foo\":\"2010-01-01\"}").status.should == "200"
175
+ :body => "{\"foo\":\"2010-01-01\"}").status).to eq("200")
176
176
  end
177
177
 
178
178
  it "should match if any of the strings have spaces" do
179
179
  WebMock.reset!
180
180
  stub_request(:post, "www.example.com").with(:body => {"foo" => "a b c"})
181
- http_request(
181
+ expect(http_request(
182
182
  :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
183
- :body => "{\"foo\":\"a b c\"}").status.should == "200"
183
+ :body => "{\"foo\":\"a b c\"}").status).to eq("200")
184
184
  end
185
185
  end
186
186
 
@@ -192,24 +192,24 @@ shared_examples_for "stubbing requests" do |*adapter_info|
192
192
  end
193
193
 
194
194
  it "should match if hash matches body" do
195
- http_request(
195
+ expect(http_request(
196
196
  :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
197
- :body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n").status.should == "200"
197
+ :body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n").status).to eq("200")
198
198
  end
199
199
 
200
200
  it "should match if hash matches body in different form" do
201
- http_request(
201
+ expect(http_request(
202
202
  :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
203
- :body => "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n").status.should == "200"
203
+ :body => "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n").status).to eq("200")
204
204
  end
205
205
 
206
206
  it "should match if hash contains date string" do #Crack creates date object
207
207
  WebMock.reset!
208
208
  stub_request(:post, "www.example.com").
209
209
  with(:body => {"opt" => {"foo" => "2010-01-01"}})
210
- http_request(
210
+ expect(http_request(
211
211
  :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
212
- :body => "<opt foo=\"2010-01-01\">\n</opt>\n").status.should == "200"
212
+ :body => "<opt foo=\"2010-01-01\">\n</opt>\n").status).to eq("200")
213
213
  end
214
214
  end
215
215
  end
@@ -233,15 +233,15 @@ shared_examples_for "stubbing requests" do |*adapter_info|
233
233
  end
234
234
 
235
235
  it "should not match if hash doesn't match url encoded body" do
236
- lambda { wrong_request }.should raise_error
236
+ expect { wrong_request }.to raise_error
237
237
  end
238
238
  end
239
239
 
240
240
  describe "for request with json body and content type is set to json" do
241
241
  it "should match if hash matches body" do
242
- http_request(
242
+ expect(http_request(
243
243
  :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
244
- :body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}").status.should == "200"
244
+ :body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}").status).to eq("200")
245
245
  end
246
246
  end
247
247
  end
@@ -258,15 +258,15 @@ shared_examples_for "stubbing requests" do |*adapter_info|
258
258
  end
259
259
 
260
260
  it "should not match if hash doesn't match url encoded body" do
261
- lambda { wrong_request }.should raise_error
261
+ expect { wrong_request }.to raise_error
262
262
  end
263
263
  end
264
264
 
265
265
  describe "for request with json body and content type is set to json" do
266
266
  it "should match if hash matches body" do
267
- http_request(
267
+ expect(http_request(
268
268
  :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
269
- :body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}").status.should == "200"
269
+ :body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}").status).to eq("200")
270
270
  end
271
271
  end
272
272
  end
@@ -277,87 +277,87 @@ shared_examples_for "stubbing requests" do |*adapter_info|
277
277
  describe "based on headers" do
278
278
  it "should match requests if headers are the same" do
279
279
  stub_request(:get, "www.example.com").with(:headers => SAMPLE_HEADERS )
280
- http_request(
280
+ expect(http_request(
281
281
  :get, "http://www.example.com/",
282
- :headers => SAMPLE_HEADERS).status.should == "200"
282
+ :headers => SAMPLE_HEADERS).status).to eq("200")
283
283
  end
284
284
 
285
285
  it "should match requests if headers are the same and declared as array" do
286
286
  stub_request(:get, "www.example.com").with(:headers => {"a" => ["b"]} )
287
- http_request(
287
+ expect(http_request(
288
288
  :get, "http://www.example.com/",
289
- :headers => {"a" => "b"}).status.should == "200"
289
+ :headers => {"a" => "b"}).status).to eq("200")
290
290
  end
291
291
 
292
292
  describe "when multiple headers with the same key are used" do
293
293
  it "should match requests if headers are the same" do
294
294
  stub_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]} )
295
- http_request(
295
+ expect(http_request(
296
296
  :get, "http://www.example.com/",
297
- :headers => {"a" => ["b", "c"]}).status.should == "200"
297
+ :headers => {"a" => ["b", "c"]}).status).to eq("200")
298
298
  end
299
299
 
300
300
  it "should match requests if headers are the same but in different order" do
301
301
  stub_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]} )
302
- http_request(
302
+ expect(http_request(
303
303
  :get, "http://www.example.com/",
304
- :headers => {"a" => ["c", "b"]}).status.should == "200"
304
+ :headers => {"a" => ["c", "b"]}).status).to eq("200")
305
305
  end
306
306
 
307
307
  it "should not match requests if headers are different" do
308
308
  stub_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]})
309
309
 
310
- lambda {
310
+ expect {
311
311
  http_request(
312
312
  :get, "http://www.example.com/",
313
313
  :headers => {"a" => ["b", "d"]})
314
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
314
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
315
315
  end
316
316
  end
317
317
 
318
318
  it "should match requests if request headers are not stubbed" do
319
319
  stub_request(:get, "www.example.com")
320
- http_request(
320
+ expect(http_request(
321
321
  :get, "http://www.example.com/",
322
- :headers => SAMPLE_HEADERS).status.should == "200"
322
+ :headers => SAMPLE_HEADERS).status).to eq("200")
323
323
  end
324
324
 
325
325
  it "should not match requests if headers are different" do
326
326
  stub_request(:get, "www.example.com").with(:headers => SAMPLE_HEADERS)
327
327
 
328
- lambda {
328
+ expect {
329
329
  http_request(
330
330
  :get, "http://www.example.com/",
331
331
  :headers => { 'Content-Length' => '9999'})
332
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
332
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
333
333
  end
334
334
 
335
335
  it "should not match if accept header is different" do
336
336
  stub_request(:get, "www.example.com").
337
337
  with(:headers => { 'Accept' => 'application/json'})
338
- lambda {
338
+ expect {
339
339
  http_request(
340
340
  :get, "http://www.example.com/",
341
341
  :headers => { 'Accept' => 'application/xml'})
342
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
342
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
343
343
  end
344
344
 
345
345
  describe "declared as regular expressions" do
346
346
  it "should match requests if header values match regular expression" do
347
347
  stub_request(:get, "www.example.com").with(:headers => { :some_header => /^MyAppName$/ })
348
- http_request(
348
+ expect(http_request(
349
349
  :get, "http://www.example.com/",
350
- :headers => { 'some-header' => 'MyAppName' }).status.should == "200"
350
+ :headers => { 'some-header' => 'MyAppName' }).status).to eq("200")
351
351
  end
352
352
 
353
353
  it "should not match requests if headers values do not match regular expression" do
354
354
  stub_request(:get, "www.example.com").with(:headers => { :some_header => /^MyAppName$/ })
355
355
 
356
- lambda {
356
+ expect {
357
357
  http_request(
358
358
  :get, "http://www.example.com/",
359
359
  :headers => { 'some-header' => 'xMyAppName' })
360
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
360
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
361
361
  end
362
362
  end
363
363
  end
@@ -365,28 +365,28 @@ shared_examples_for "stubbing requests" do |*adapter_info|
365
365
  describe "when stubbing request with basic authentication", :unless => (adapter_info.include?(:no_url_auth)) do
366
366
  it "should match if credentials are the same" do
367
367
  stub_request(:get, "user:pass@www.example.com")
368
- http_request(:get, "http://user:pass@www.example.com/").status.should == "200"
368
+ expect(http_request(:get, "http://user:pass@www.example.com/").status).to eq("200")
369
369
  end
370
370
 
371
371
  it "should not match if credentials are different" do
372
372
  stub_request(:get, "user:pass@www.example.com")
373
- lambda {
374
- http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
375
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
373
+ expect {
374
+ expect(http_request(:get, "http://user:pazz@www.example.com/").status).to eq("200")
375
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
376
376
  end
377
377
 
378
378
  it "should not match if credentials are stubbed but not provided in the request" do
379
379
  stub_request(:get, "user:pass@www.example.com")
380
- lambda {
381
- http_request(:get, "http://www.example.com/").status.should == "200"
382
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
380
+ expect {
381
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
382
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
383
383
  end
384
384
 
385
385
  it "should not match if credentials are not stubbed but exist in the request" do
386
386
  stub_request(:get, "www.example.com")
387
- lambda {
388
- http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
389
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
387
+ expect {
388
+ expect(http_request(:get, "http://user:pazz@www.example.com/").status).to eq("200")
389
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
390
390
  end
391
391
  end
392
392
 
@@ -400,7 +400,7 @@ shared_examples_for "stubbing requests" do |*adapter_info|
400
400
  { :body => "global stub body" }
401
401
  end
402
402
 
403
- http_request(:get, "http://www.example.com/").body.should == "global stub body"
403
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
404
404
  end
405
405
 
406
406
  it 'does not get cleared when a user calls WebMock.reset!' do
@@ -408,14 +408,14 @@ shared_examples_for "stubbing requests" do |*adapter_info|
408
408
  { :body => "global stub body" }
409
409
  end
410
410
  WebMock.reset!
411
- http_request(:get, "http://www.example.com/").body.should == "global stub body"
411
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
412
412
  end
413
413
 
414
414
  it "does not stub the request if the hook does not return anything" do
415
415
  WebMock.globally_stub_request { |r| }
416
- lambda {
416
+ expect {
417
417
  http_request(:get, "http://www.example.com/")
418
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
418
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
419
419
  end
420
420
 
421
421
  it "passes the request to the block" do
@@ -426,7 +426,7 @@ shared_examples_for "stubbing requests" do |*adapter_info|
426
426
  end
427
427
 
428
428
  http_request(:get, "http://www.example.com:456/bar")
429
- passed_request.uri.to_s.should == "http://www.example.com:456/bar"
429
+ expect(passed_request.uri.to_s).to eq("http://www.example.com:456/bar")
430
430
  end
431
431
 
432
432
  it "should call the block only once per request" do
@@ -436,7 +436,7 @@ shared_examples_for "stubbing requests" do |*adapter_info|
436
436
  { :body => "global stub body" }
437
437
  end
438
438
  http_request(:get, "http://www.example.com/")
439
- call_count.should == 1
439
+ expect(call_count).to eq(1)
440
440
  end
441
441
 
442
442
  it 'supports multiple global stubs; the first registered one that returns a non-nil value determines the stub' do
@@ -451,8 +451,8 @@ shared_examples_for "stubbing requests" do |*adapter_info|
451
451
  { :body => "global stub body" }
452
452
  end
453
453
 
454
- http_request(:get, "http://www.example.com/").body.should == "global stub body"
455
- stub_invocation_order.should eq([:nil_stub, :hash_stub])
454
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
455
+ expect(stub_invocation_order).to eq([:nil_stub, :hash_stub])
456
456
  end
457
457
 
458
458
  [:before, :after].each do |before_or_after|
@@ -469,12 +469,12 @@ shared_examples_for "stubbing requests" do |*adapter_info|
469
469
 
470
470
  it 'uses the response from the global stub if the block returns a non-nil value' do
471
471
  register_stubs(lambda { |req| { :body => 'global stub body' } })
472
- http_request(:get, "http://www.example.com/").body.should == "global stub body"
472
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
473
473
  end
474
474
 
475
475
  it 'uses the response from the non-global stub if the block returns a nil value' do
476
476
  register_stubs(lambda { |req| nil })
477
- http_request(:get, "http://www.example.com/").body.should == "non-global stub body"
477
+ expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
478
478
  end
479
479
  end
480
480
  end
@@ -483,31 +483,31 @@ shared_examples_for "stubbing requests" do |*adapter_info|
483
483
  describe "when stubbing request with a block evaluated on request" do
484
484
  it "should match if block returns true" do
485
485
  stub_request(:get, "www.example.com").with { |request| true }
486
- http_request(:get, "http://www.example.com/").status.should == "200"
486
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
487
487
  end
488
488
 
489
489
  it "should not match if block returns false" do
490
490
  stub_request(:get, "www.example.com").with { |request| false }
491
- lambda {
491
+ expect {
492
492
  http_request(:get, "http://www.example.com/")
493
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
493
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
494
494
  end
495
495
 
496
496
  it "should pass the request to the block" do
497
497
  stub_request(:post, "www.example.com").with { |request| request.body == "wadus" }
498
- http_request(
498
+ expect(http_request(
499
499
  :post, "http://www.example.com/",
500
- :body => "wadus").status.should == "200"
501
- lambda {
500
+ :body => "wadus").status).to eq("200")
501
+ expect {
502
502
  http_request(:post, "http://www.example.com/", :body => "jander")
503
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'jander'))
503
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'jander'))
504
504
  end
505
505
 
506
506
  it "should call the block only once per request" do
507
507
  call_count = 0
508
508
  stub_request(:get, "www.example.com").with { |request| call_count += 1; true }
509
- http_request(:get, "http://www.example.com/").status.should == "200"
510
- call_count.should == 1
509
+ expect(http_request(:get, "http://www.example.com/").status).to eq("200")
510
+ expect(call_count).to eq(1)
511
511
  end
512
512
  end
513
513
  end
@@ -520,9 +520,9 @@ shared_examples_for "stubbing requests" do |*adapter_info|
520
520
 
521
521
  remove_request_stub(stub)
522
522
 
523
- lambda {
523
+ expect {
524
524
  http_request(:get, "http://www.example.com/")
525
- }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
525
+ }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
526
526
  end
527
527
  end
528
528
  end