webmock 1.6.2 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,7 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ *.gem
23
+ .bundle
24
+ Gemfile.lock
25
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@webmock --create
data/CHANGELOG.md CHANGED
@@ -1,4 +1,42 @@
1
- #Changelog
1
+ # Changelog
2
+
3
+ ## 1.6.4
4
+
5
+ This is a quick slip release to regenerate the gemspec. Apparently
6
+ jeweler inserts dependencies twice if you use the `gemspec` method in
7
+ your Gemfile and declare gem dependencies in your gemspec.
8
+
9
+ https://github.com/technicalpickles/jeweler/issues/154
10
+
11
+ josevalim:
12
+
13
+ > This just bit me. I just released a gem with the wrong dependencies
14
+ > because I have updated jeweler. This should have been opt-in,
15
+ > otherwise a bunch of people using jeweler are going to release gems
16
+ > with the wrong dependencies because you are automatically importing
17
+ > from the Gemfile.
18
+
19
+ ## 1.6.3
20
+
21
+ * Update the dependency on addressable to get around an issue in v2.2.5.
22
+ Thanks to [Peter Higgins](https://github.com/phiggins).
23
+
24
+ * Add support for matching parameter values using a regular expression
25
+ as well as a string. Thanks to [Oleg M Prozorov](https://github.com/oleg).
26
+
27
+ * Fix integration with httpclient as the internal API has changed.
28
+ Thanks to [Frank Prößdorf](https://github.com/endor).
29
+
30
+ * Ensure Curl::Easy#content_type is always set. Thanks to [Peter
31
+ Higgins](https://github.com/phiggins).
32
+
33
+ * Fix bug with em-http-request adapter stubbing responses that have a
34
+ chunked transfer encoding. Thanks to [Myron
35
+ Marston](https://github.com/myronmarston).
36
+
37
+ * Fix a load of spec failures with Patron, httpclient, and specs that
38
+ depended on the behaviour of example.com. Thanks to [Alex
39
+ Grigorovich](https://github.com/grig).
2
40
 
3
41
  ## 1.6.2
4
42
 
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org/"
2
+ gemspec
data/README.md CHANGED
@@ -3,6 +3,12 @@ WebMock
3
3
 
4
4
  Library for stubbing and setting expectations on HTTP requests in Ruby.
5
5
 
6
+ WebMock is looking for a maintainer
7
+ ===================================
8
+
9
+ I'm not able to maintain WebMock until end of June 2011.
10
+ If anyone is interested in maintaining it in the meantime (at least handling pull requests and creating patch releases), please get in touch.
11
+
6
12
  Features
7
13
  --------
8
14
 
@@ -25,36 +31,36 @@ Supported HTTP libraries
25
31
 
26
32
  ##Installation
27
33
 
28
- gem install webmock --source http://gemcutter.org
34
+ gem install webmock --source http://gemcutter.org
29
35
 
30
36
  ### or to install the latest development version from github master
31
37
 
32
- git clone http://github.com/bblimke/webmock.git
33
- cd webmock
34
- rake install
38
+ git clone http://github.com/bblimke/webmock.git
39
+ cd webmock
40
+ rake install
35
41
 
36
- ### Test::Unit
42
+ ### Test::Unit
37
43
 
38
44
  Add the following code to `test/test_helper.rb`
39
45
 
40
- require 'webmock/test_unit'
46
+ require 'webmock/test_unit'
41
47
 
42
48
  ### RSpec
43
-
49
+
44
50
  Add the following code to `spec/spec_helper`:
45
51
 
46
- require 'webmock/rspec'
52
+ require 'webmock/rspec'
47
53
 
48
54
  ### Cucumber
49
55
 
50
56
  Add the following code to `features/support/env.rb`
51
57
 
52
- require 'webmock/cucumber'
58
+ require 'webmock/cucumber'
53
59
 
54
60
  You can also use WebMock outside a test framework:
55
61
 
56
- require 'webmock'
57
- include WebMock::API
62
+ require 'webmock'
63
+ include WebMock::API
58
64
 
59
65
  ## Examples
60
66
 
@@ -65,72 +71,72 @@ You can also use WebMock outside a test framework:
65
71
 
66
72
  ### Stubbed request based on uri only and with the default response
67
73
 
68
- stub_request(:any, "www.example.com")
74
+ stub_request(:any, "www.example.com")
69
75
 
70
- Net::HTTP.get("www.example.com", "/") # ===> Success
76
+ Net::HTTP.get("www.example.com", "/") # ===> Success
71
77
 
72
78
  ### Stubbing requests based on method, uri, body and headers
73
79
 
74
- stub_request(:post, "www.example.com").with(:body => "abc", :headers => { 'Content-Length' => 3 })
80
+ stub_request(:post, "www.example.com").with(:body => "abc", :headers => { 'Content-Length' => 3 })
75
81
 
76
- uri = URI.parse("http://www.example.com/")
82
+ uri = URI.parse("http://www.example.com/")
77
83
  req = Net::HTTP::Post.new(uri.path)
78
- req['Content-Length'] = 3
84
+ req['Content-Length'] = 3
79
85
  res = Net::HTTP.start(uri.host, uri.port) {|http|
80
86
  http.request(req, "abc")
81
87
  } # ===> Success
82
88
 
83
89
  ### Matching request body and headers against regular expressions
84
90
 
85
- stub_request(:post, "www.example.com").
86
- with(:body => /^.*world$/, :headers => {"Content-Type" => /image\/.+/}).to_return(:body => "abc")
91
+ stub_request(:post, "www.example.com").
92
+ with(:body => /^.*world$/, :headers => {"Content-Type" => /image\/.+/}).to_return(:body => "abc")
87
93
 
88
- uri = URI.parse('http://www.example.com/')
94
+ uri = URI.parse('http://www.example.com/')
89
95
  req = Net::HTTP::Post.new(uri.path)
90
- req['Content-Type'] = 'image/png'
96
+ req['Content-Type'] = 'image/png'
91
97
  res = Net::HTTP.start(uri.host, uri.port) {|http|
92
98
  http.request(req, 'hello world')
93
99
  } # ===> Success
94
-
100
+
95
101
  ### Matching request body against a hash. Body can be URL-Encoded, JSON or XML.
96
102
 
97
- stub_http_request(:post, "www.example.com").
98
- with(:body => {:data => {:a => '1', :b => 'five'}})
103
+ stub_http_request(:post, "www.example.com").
104
+ with(:body => {:data => {:a => '1', :b => 'five'}})
105
+
106
+ RestClient.post('www.example.com', "data[a]=1&data[b]=five",
107
+ :content_type => 'application/x-www-form-urlencoded') # ===> Success
108
+
109
+ RestClient.post('www.example.com', '{"data":{"a":"1","b":"five"}}',
110
+ :content_type => 'application/json') # ===> Success
99
111
 
100
- RestClient.post('www.example.com', "data[a]=1&data[b]=five",
101
- :content_type => 'application/x-www-form-urlencoded') # ===> Success
102
-
103
- RestClient.post('www.example.com', '{"data":{"a":"1","b":"five"}}',
104
- :content_type => 'application/json') # ===> Success
105
-
106
- RestClient.post('www.example.com', '<data a="1" b="five" />',
107
- :content_type => 'application/xml' ) # ===> Success
112
+ RestClient.post('www.example.com', '<data a="1" b="five" />',
113
+ :content_type => 'application/xml' ) # ===> Success
108
114
 
109
115
  ### Matching custom request headers
110
116
 
111
117
  stub_request(:any, "www.example.com").with(:headers=>{ 'Header-Name' => 'Header-Value' })
112
118
 
113
- uri = URI.parse('http://www.example.com/')
119
+ uri = URI.parse('http://www.example.com/')
114
120
  req = Net::HTTP::Post.new(uri.path)
115
- req['Header-Name'] = 'Header-Value'
121
+ req['Header-Name'] = 'Header-Value'
116
122
  res = Net::HTTP.start(uri.host, uri.port) {|http|
117
123
  http.request(req, 'abc')
118
124
  } # ===> Success
119
125
 
120
126
  ### Matching multiple headers with the same name
121
127
 
122
- stub_http_request(:get, 'www.example.com').with(:headers => {'Accept' => ['image/jpeg', 'image/png'] })
123
-
124
- req = Net::HTTP::Get.new("/")
125
- req['Accept'] = ['image/png']
126
- req.add_field('Accept', 'image/jpeg')
127
- Net::HTTP.start("www.example.com") {|http| http.request(req) } # ===> Success
128
+ stub_http_request(:get, 'www.example.com').with(:headers => {'Accept' => ['image/jpeg', 'image/png'] })
129
+
130
+ req = Net::HTTP::Get.new("/")
131
+ req['Accept'] = ['image/png']
132
+ req.add_field('Accept', 'image/jpeg')
133
+ Net::HTTP.start("www.example.com") {|http| http.request(req) } # ===> Success
128
134
 
129
135
  ### Matching requests against provided block
130
136
 
131
- stub_request(:post, "www.example.com").with { |request| request.body == "abc" }
132
- RestClient.post('www.example.com', 'abc') # ===> Success
133
-
137
+ stub_request(:post, "www.example.com").with { |request| request.body == "abc" }
138
+ RestClient.post('www.example.com', 'abc') # ===> Success
139
+
134
140
  ### Request with basic authentication
135
141
 
136
142
  stub_request(:get, "user:pass@www.example.com")
@@ -143,49 +149,49 @@ You can also use WebMock outside a test framework:
143
149
 
144
150
  ### Matching uris using regular expressions
145
151
 
146
- stub_request(:any, /.*example.*/)
152
+ stub_request(:any, /.*example.*/)
153
+
154
+ Net::HTTP.get('www.example.com', '/') # ===> Success
147
155
 
148
- Net::HTTP.get('www.example.com', '/') # ===> Success
149
-
150
- ### Matching query params using hash
156
+ ### Matching query params using hash
157
+
158
+ stub_http_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]})
159
+
160
+ RestClient.get("http://www.example.com/?a[]=b&a[]=c") # ===> Success
151
161
 
152
- stub_http_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]})
153
-
154
- RestClient.get("http://www.example.com/?a[]=b&a[]=c") # ===> Success
155
-
156
162
  ### Stubbing with custom response
157
163
 
158
- stub_request(:any, "www.example.com").to_return(:body => "abc", :status => 200, :headers => { 'Content-Length' => 3 } )
159
-
160
- Net::HTTP.get("www.example.com", '/') # ===> "abc"
164
+ stub_request(:any, "www.example.com").to_return(:body => "abc", :status => 200, :headers => { 'Content-Length' => 3 } )
165
+
166
+ Net::HTTP.get("www.example.com", '/') # ===> "abc"
161
167
 
162
168
  ### Response with body specified as IO object
163
169
 
164
- File.open('/tmp/response_body.txt', 'w') { |f| f.puts 'abc' }
170
+ File.open('/tmp/response_body.txt', 'w') { |f| f.puts 'abc' }
165
171
 
166
- stub_request(:any, "www.example.com").to_return(:body => File.new('/tmp/response_body.txt'), :status => 200)
172
+ stub_request(:any, "www.example.com").to_return(:body => File.new('/tmp/response_body.txt'), :status => 200)
173
+
174
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
167
175
 
168
- Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
169
-
170
176
  ### Response with custom status message
171
177
 
172
- stub_request(:any, "www.example.com").to_return(:status => [500, "Internal Server Error"])
178
+ stub_request(:any, "www.example.com").to_return(:status => [500, "Internal Server Error"])
179
+
180
+ req = Net::HTTP::Get.new("/")
181
+ Net::HTTP.start("www.example.com") { |http| http.request(req) }.message # ===> "Internal Server Error"
173
182
 
174
- req = Net::HTTP::Get.new("/")
175
- Net::HTTP.start("www.example.com") { |http| http.request(req) }.message # ===> "Internal Server Error"
176
-
177
183
  ### Replaying raw responses recorded with `curl -is`
178
184
 
179
- `curl -is www.example.com > /tmp/example_curl_-is_output.txt`
180
- raw_response_file = File.new("/tmp/example_curl_-is_output.txt")
185
+ `curl -is www.example.com > /tmp/example_curl_-is_output.txt`
186
+ raw_response_file = File.new("/tmp/example_curl_-is_output.txt")
181
187
 
182
188
  from file
183
189
 
184
- stub_request(:get, "www.example.com").to_return(raw_response_file)
190
+ stub_request(:get, "www.example.com").to_return(raw_response_file)
185
191
 
186
192
  or string
187
193
 
188
- stub_request(:get, "www.example.com").to_return(raw_response_file.read)
194
+ stub_request(:get, "www.example.com").to_return(raw_response_file.read)
189
195
 
190
196
  ### Responses dynamically evaluated from block
191
197
 
@@ -199,7 +205,7 @@ You can also use WebMock outside a test framework:
199
205
  stub_request(:any, 'www.example.net').
200
206
  to_return(lambda { |request| {:body => request.body} })
201
207
 
202
- RestClient.post('www.example.net', 'abc') # ===> "abc\n"
208
+ RestClient.post('www.example.net', 'abc') # ===> "abc\n"
203
209
 
204
210
  ### Dynamically evaluated raw responses recorded with `curl -is`
205
211
 
@@ -211,90 +217,90 @@ You can also use WebMock outside a test framework:
211
217
  stub_request(:any, 'www.example.net').
212
218
  to_return(:body => lambda { |request| request.body })
213
219
 
214
- RestClient.post('www.example.net', 'abc') # ===> "abc\n"
220
+ RestClient.post('www.example.net', 'abc') # ===> "abc\n"
215
221
 
216
222
  ### Raising errors
217
223
 
218
224
  #### Exception declared by class
219
225
 
220
- stub_request(:any, 'www.example.net').to_raise(StandardError)
226
+ stub_request(:any, 'www.example.net').to_raise(StandardError)
221
227
 
222
228
  RestClient.post('www.example.net', 'abc') # ===> StandardError
223
-
229
+
224
230
  #### or by exception instance
225
231
 
226
232
  stub_request(:any, 'www.example.net').to_raise(StandardError.new("some error"))
227
233
 
228
234
  #### or by string
229
-
235
+
230
236
  stub_request(:any, 'www.example.net').to_raise("some error")
231
237
 
232
238
  ### Raising timeout errors
233
239
 
234
- stub_request(:any, 'www.example.net').to_timeout
240
+ stub_request(:any, 'www.example.net').to_timeout
235
241
 
236
- RestClient.post('www.example.net', 'abc') # ===> RestClient::RequestTimeout
242
+ RestClient.post('www.example.net', 'abc') # ===> RestClient::RequestTimeout
237
243
 
238
244
  ### Multiple responses for repeated requests
239
245
 
240
- stub_request(:get, "www.example.com").to_return({:body => "abc"}, {:body => "def"})
241
- Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
242
- Net::HTTP.get('www.example.com', '/') # ===> "def\n"
243
-
244
- #after all responses are used the last response will be returned infinitely
245
-
246
- Net::HTTP.get('www.example.com', '/') # ===> "def\n"
246
+ stub_request(:get, "www.example.com").to_return({:body => "abc"}, {:body => "def"})
247
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
248
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
249
+
250
+ #after all responses are used the last response will be returned infinitely
251
+
252
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
247
253
 
248
254
  ### Multiple responses using chained `to_return()`, `to_raise()` or `to_timeout` declarations
249
255
 
250
- stub_request(:get, "www.example.com").
251
- to_return({:body => "abc"}).then. #then() is just a syntactic sugar
252
- to_return({:body => "def"}).then.
253
- to_raise(MyException)
254
- Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
255
- Net::HTTP.get('www.example.com', '/') # ===> "def\n"
256
- Net::HTTP.get('www.example.com', '/') # ===> MyException raised
256
+ stub_request(:get, "www.example.com").
257
+ to_return({:body => "abc"}).then. #then() is just a syntactic sugar
258
+ to_return({:body => "def"}).then.
259
+ to_raise(MyException)
260
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
261
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
262
+ Net::HTTP.get('www.example.com', '/') # ===> MyException raised
257
263
 
258
264
  ### Specifying number of times given response should be returned
259
265
 
260
- stub_request(:get, "www.example.com").
261
- to_return({:body => "abc"}).times(2).then.
262
- to_return({:body => "def"})
266
+ stub_request(:get, "www.example.com").
267
+ to_return({:body => "abc"}).times(2).then.
268
+ to_return({:body => "def"})
263
269
 
264
- Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
265
- Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
266
- Net::HTTP.get('www.example.com', '/') # ===> "def\n"
270
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
271
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
272
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
267
273
 
268
274
 
269
275
  ### Real requests to network can be allowed or disabled
270
276
 
271
- WebMock.allow_net_connect!
277
+ WebMock.allow_net_connect!
278
+
279
+ stub_request(:any, "www.example.com").to_return(:body => "abc")
272
280
 
273
- stub_request(:any, "www.example.com").to_return(:body => "abc")
281
+ Net::HTTP.get('www.example.com', '/') # ===> "abc"
274
282
 
275
- Net::HTTP.get('www.example.com', '/') # ===> "abc"
276
-
277
- Net::HTTP.get('www.something.com', '/') # ===> /.+Something.+/
278
-
279
- WebMock.disable_net_connect!
280
-
281
- Net::HTTP.get('www.something.com', '/') # ===> Failure
283
+ Net::HTTP.get('www.something.com', '/') # ===> /.+Something.+/
284
+
285
+ WebMock.disable_net_connect!
286
+
287
+ Net::HTTP.get('www.something.com', '/') # ===> Failure
282
288
 
283
289
  ### External requests can be disabled while allowing localhost
284
-
285
- WebMock.disable_net_connect!(:allow_localhost => true)
286
-
287
- Net::HTTP.get('www.something.com', '/') # ===> Failure
288
-
289
- Net::HTTP.get('localhost:9887', '/') # ===> Allowed. Perhaps to Selenium?
290
+
291
+ WebMock.disable_net_connect!(:allow_localhost => true)
292
+
293
+ Net::HTTP.get('www.something.com', '/') # ===> Failure
294
+
295
+ Net::HTTP.get('localhost:9887', '/') # ===> Allowed. Perhaps to Selenium?
290
296
 
291
297
  ### External requests can be disabled while allowing any hostname
292
298
 
293
- WebMock.disable_net_connect!(:allow => "www.example.org")
299
+ WebMock.disable_net_connect!(:allow => "www.example.org")
294
300
 
295
- Net::HTTP.get('www.something.com', '/') # ===> Failure
301
+ Net::HTTP.get('www.something.com', '/') # ===> Failure
296
302
 
297
- Net::HTTP.get('www.example.org', '/') # ===> Allowed.
303
+ Net::HTTP.get('www.example.org', '/') # ===> Allowed.
298
304
 
299
305
  ## Connecting on Net::HTTP.start
300
306
 
@@ -311,84 +317,84 @@ so when there is no request, `Net::HTTP.start` doesn't do anything.
311
317
  To workaround this issue, WebMock offers `:net_http_connect_on_start` option,
312
318
  which can be passed to `WebMock.allow_net_connect!` and `WebMock#disable_net_connect!` methods, i.e.
313
319
 
314
- WebMock.allow_net_connect!(:net_http_connect_on_start => true)
320
+ WebMock.allow_net_connect!(:net_http_connect_on_start => true)
315
321
 
316
322
  This forces WebMock Net::HTTP adapter to always connect on `Net::HTTP.start`.
317
323
 
318
324
  ## Setting Expectations
319
325
 
320
326
  ### Setting expectations in Test::Unit
321
- require 'webmock/test_unit'
327
+ require 'webmock/test_unit'
322
328
 
323
329
  stub_request(:any, "www.example.com")
324
330
 
325
- uri = URI.parse('http://www.example.com/')
331
+ uri = URI.parse('http://www.example.com/')
326
332
  req = Net::HTTP::Post.new(uri.path)
327
- req['Content-Length'] = 3
333
+ req['Content-Length'] = 3
328
334
  res = Net::HTTP.start(uri.host, uri.port) {|http|
329
335
  http.request(req, 'abc')
330
336
  }
331
337
 
332
- assert_requested :post, "http://www.example.com",
333
- :headers => {'Content-Length' => 3}, :body => "abc", :times => 1 # ===> Success
334
-
335
- assert_not_requested :get, "http://www.something.com" # ===> Success
338
+ assert_requested :post, "http://www.example.com",
339
+ :headers => {'Content-Length' => 3}, :body => "abc", :times => 1 # ===> Success
340
+
341
+ assert_not_requested :get, "http://www.something.com" # ===> Success
336
342
 
337
- assert_requested(:post, "http://www.example.com", :times => 1) { |req| req.body == "abc" }
343
+ assert_requested(:post, "http://www.example.com", :times => 1) { |req| req.body == "abc" }
338
344
 
339
345
  ### Expecting real (not stubbed) requests
340
346
 
341
- WebMock.allow_net_connect!
342
-
343
- Net::HTTP.get('www.example.com', '/') # ===> Success
347
+ WebMock.allow_net_connect!
344
348
 
345
- assert_requested :get, "http://www.example.com" # ===> Success
349
+ Net::HTTP.get('www.example.com', '/') # ===> Success
350
+
351
+ assert_requested :get, "http://www.example.com" # ===> Success
346
352
 
347
353
 
348
354
  ### Setting expectations in RSpec
349
355
  This style is borrowed from [fakeweb-matcher](http://github.com/freelancing-god/fakeweb-matcher)
350
356
 
351
- require 'webmock/rspec'
357
+ require 'webmock/rspec'
358
+
359
+ WebMock.should have_requested(:get, "www.example.com").with(:body => "abc", :headers => {'Content-Length' => 3}).twice
360
+
361
+ WebMock.should_not have_requested(:get, "www.something.com")
352
362
 
353
- WebMock.should have_requested(:get, "www.example.com").with(:body => "abc", :headers => {'Content-Length' => 3}).twice
354
-
355
- WebMock.should_not have_requested(:get, "www.something.com")
356
-
357
- WebMock.should have_requested(:post, "www.example.com").with { |req| req.body == "abc" }
358
-
359
- WebMock.should have_requested(:get, "www.example.com").with(:query => {"a" => ["b", "c"]})
363
+ WebMock.should have_requested(:post, "www.example.com").with { |req| req.body == "abc" }
360
364
 
361
- WebMock.should have_requested(:get, "www.example.com").
362
- with(:body => {"a" => ["b", "c"]}, :headers => 'Content-Type' => 'application/json')
365
+ WebMock.should have_requested(:get, "www.example.com").with(:query => {"a" => ["b", "c"]})
366
+
367
+ WebMock.should have_requested(:get, "www.example.com").
368
+ with(:body => {"a" => ["b", "c"]}, :headers => 'Content-Type' => 'application/json')
363
369
 
364
370
  ### Different way of setting expectations in RSpec
365
371
 
366
- a_request(:post, "www.example.com").with(:body => "abc", :headers => {'Content-Length' => 3}).should have_been_made.once
372
+ a_request(:post, "www.example.com").with(:body => "abc", :headers => {'Content-Length' => 3}).should have_been_made.once
367
373
 
368
- a_request(:post, "www.something.com").should have_been_made.times(3)
374
+ a_request(:post, "www.something.com").should have_been_made.times(3)
369
375
 
370
- a_request(:any, "www.example.com").should_not have_been_made
376
+ a_request(:any, "www.example.com").should_not have_been_made
371
377
 
372
- a_request(:post, "www.example.com").with { |req| req.body == "abc" }.should have_been_made
378
+ a_request(:post, "www.example.com").with { |req| req.body == "abc" }.should have_been_made
373
379
 
374
- a_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).should have_been_made
380
+ a_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).should have_been_made
375
381
 
376
- a_request(:post, "www.example.com").
377
- with(:body => {"a" => ["b", "c"]}, :headers => 'Content-Type' => 'application/json').should have_been_made
382
+ a_request(:post, "www.example.com").
383
+ with(:body => {"a" => ["b", "c"]}, :headers => 'Content-Type' => 'application/json').should have_been_made
378
384
 
379
385
  ## Clearing stubs and request history
380
386
 
381
387
  If you want to reset all current stubs and history of requests use `WebMock.reset!`
382
388
 
383
- stub_request(:any, "www.example.com")
389
+ stub_request(:any, "www.example.com")
384
390
 
385
- Net::HTTP.get('www.example.com', '/') # ===> Success
391
+ Net::HTTP.get('www.example.com', '/') # ===> Success
386
392
 
387
- WebMock.reset!
393
+ WebMock.reset!
388
394
 
389
- Net::HTTP.get('www.example.com', '/') # ===> Failure
395
+ Net::HTTP.get('www.example.com', '/') # ===> Failure
390
396
 
391
- assert_not_requested :get, "www.example.com" # ===> Success
397
+ assert_not_requested :get, "www.example.com" # ===> Success
392
398
 
393
399
 
394
400
  ## Matching requests
@@ -405,14 +411,14 @@ An executed request matches stubbed request if it passes following criteria:
405
411
 
406
412
  Always the last declared stub matching the request will be applied i.e:
407
413
 
408
- stub_request(:get, "www.example.com").to_return(:body => "abc")
409
- stub_request(:get, "www.example.com").to_return(:body => "def")
414
+ stub_request(:get, "www.example.com").to_return(:body => "abc")
415
+ stub_request(:get, "www.example.com").to_return(:body => "def")
410
416
 
411
- Net::HTTP.get('www.example.com', '/') # ====> "def"
417
+ Net::HTTP.get('www.example.com', '/') # ====> "def"
412
418
 
413
419
  ## Matching URIs
414
420
 
415
- WebMock will match all different representations of the same URI.
421
+ WebMock will match all different representations of the same URI.
416
422
 
417
423
  I.e all the following representations of the URI are equal:
418
424
 
@@ -424,36 +430,36 @@ I.e all the following representations of the URI are equal:
424
430
  "http://www.example.com/"
425
431
  "http://www.example.com:80"
426
432
  "http://www.example.com:80/"
427
-
433
+
428
434
  The following URIs with basic authentication are also equal for WebMock
429
435
 
430
- "a b:pass@www.example.com"
431
- "a b:pass@www.example.com/"
432
- "a b:pass@www.example.com:80"
433
- "a b:pass@www.example.com:80/"
434
- "http://a b:pass@www.example.com"
435
- "http://a b:pass@www.example.com/"
436
- "http://a b:pass@www.example.com:80"
437
- "http://a b:pass@www.example.com:80/"
438
- "a%20b:pass@www.example.com"
439
- "a%20b:pass@www.example.com/"
440
- "a%20b:pass@www.example.com:80"
441
- "a%20b:pass@www.example.com:80/"
442
- "http://a%20b:pass@www.example.com"
443
- "http://a%20b:pass@www.example.com/"
444
- "http://a%20b:pass@www.example.com:80"
445
- "http://a%20b:pass@www.example.com:80/"
436
+ "a b:pass@www.example.com"
437
+ "a b:pass@www.example.com/"
438
+ "a b:pass@www.example.com:80"
439
+ "a b:pass@www.example.com:80/"
440
+ "http://a b:pass@www.example.com"
441
+ "http://a b:pass@www.example.com/"
442
+ "http://a b:pass@www.example.com:80"
443
+ "http://a b:pass@www.example.com:80/"
444
+ "a%20b:pass@www.example.com"
445
+ "a%20b:pass@www.example.com/"
446
+ "a%20b:pass@www.example.com:80"
447
+ "a%20b:pass@www.example.com:80/"
448
+ "http://a%20b:pass@www.example.com"
449
+ "http://a%20b:pass@www.example.com/"
450
+ "http://a%20b:pass@www.example.com:80"
451
+ "http://a%20b:pass@www.example.com:80/"
446
452
 
447
453
  or these
448
454
 
449
- "www.example.com/my path/?a=my param&b=c"
450
- "www.example.com/my%20path/?a=my%20param&b=c"
451
- "www.example.com:80/my path/?a=my param&b=c"
452
- "www.example.com:80/my%20path/?a=my%20param&b=c"
453
- "http://www.example.com/my path/?a=my param&b=c"
454
- "http://www.example.com/my%20path/?a=my%20param&b=c"
455
- "http://www.example.com:80/my path/?a=my param&b=c"
456
- "http://www.example.com:80/my%20path/?a=my%20param&b=c"
455
+ "www.example.com/my path/?a=my param&b=c"
456
+ "www.example.com/my%20path/?a=my%20param&b=c"
457
+ "www.example.com:80/my path/?a=my param&b=c"
458
+ "www.example.com:80/my%20path/?a=my%20param&b=c"
459
+ "http://www.example.com/my path/?a=my param&b=c"
460
+ "http://www.example.com/my%20path/?a=my%20param&b=c"
461
+ "http://www.example.com:80/my path/?a=my param&b=c"
462
+ "http://www.example.com:80/my%20path/?a=my%20param&b=c"
457
463
 
458
464
 
459
465
  If you provide Regexp to match URI, WebMock will try to match it against every valid form of the same url.
@@ -509,6 +515,51 @@ If you have any suggestions on how to improve WebMock please send an email to th
509
515
 
510
516
  I'm particularly interested in how the DSL could be improved.
511
517
 
518
+ ## Development
519
+
520
+ In order to work on Webmock you first need to fork and clone the repo.
521
+ Please do any work on a dedicated branch and rebase against master
522
+ before sending a pull request.
523
+
524
+ #### Running Tests
525
+
526
+ We use RVM in order to test WebMock against 1.8.6, REE, 1.8.7, 1.9.2 and
527
+ jRuby. You can get RVM setup for WebMock development using the
528
+ following commands (if you don't have these version of Ruby installed
529
+ use `rvm install` to install each of them).
530
+
531
+ rvm use --create 1.8.6@webmock
532
+ gem install jeweler bundler
533
+ bundle install
534
+
535
+ rvm use --create ree@webmock
536
+ gem install jeweler bundler
537
+ bundle install
538
+
539
+ rvm use --create 1.8.7@webmock
540
+ gem install jeweler bundler
541
+ bundle install
542
+
543
+ rvm use --create 1.9.2@webmock
544
+ gem install jeweler bundler
545
+ bundle install
546
+
547
+ rvm use --create jruby@webmock
548
+ gem install jeweler bundler
549
+ bundle install
550
+
551
+ These commands will create a gemset named WebMock for each of the
552
+ supported versions of Ruby and `bundle install` all dependencies.
553
+
554
+ With the supported versions of Ruby installed RVM will run specs across
555
+ all version with just one command.
556
+
557
+ bundle exec rvm 1.8.6@webmock,ree@webmock,1.8.7@webmock,1.9.2@webmock,jruby@webmock rspec spec/**/*_spec.rb
558
+
559
+ This command is wrapped up in to a rake task and can be invoked like so:
560
+
561
+ rake spec:rubies
562
+
512
563
  ## Credits
513
564
 
514
565
  The initial lines of this project were written during New Bamboo [Hack Day](http://blog.new-bamboo.co.uk/2009/11/13/hackday-results)
@@ -547,10 +598,13 @@ People who submitted patches and new features or suggested improvements. Many th
547
598
  * Sam Stokes
548
599
  * Eugene Bolshakov
549
600
 
601
+ For a full list of contributors you can visit the
602
+ [contributors](https://github.com/bblimke/webmock/contributors) page.
603
+
550
604
  ## Background
551
605
 
552
606
  Thank you Fakeweb! This library was inspired by [FakeWeb](fakeweb.rubyforge.org).
553
- I imported some solutions from that project to WebMock. I also copied some code i.e Net:HTTP adapter.
607
+ I imported some solutions from that project to WebMock. I also copied some code i.e Net:HTTP adapter.
554
608
  Fakeweb architecture unfortunately didn't allow me to extend it easily with the features I needed.
555
609
  I also preferred some things to work differently i.e request stub precedence.
556
610