Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 512 lines (321 sloc) 16.782 kb
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
1 WebMock
2 =======
3
0016b13 Minor changes to README
Bartosz Blimke authored
4 Library for stubbing and setting expectations on HTTP requests in Ruby.
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
5
6 Features
7 --------
8
0016b13 Minor changes to README
Bartosz Blimke authored
9 * Stubbing HTTP requests at low http client lib level (no need to change tests when you change HTTP library)
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
10 * Setting and verifying expectations on HTTP requests
11 * Matching requests based on method, URI, headers and body
12 * Smart matching of the same URIs in different representations (also encoded and non encoded forms)
13 * Smart matching of the same headers in different representations.
9c8c463 Updated README with information about RSpec 2 support.
Bartosz Blimke authored
14 * Support for Test::Unit
15 * Support for RSpec 1.x and RSpec 2.x
fb18a01 Updated README with info about matching request body against hash
Bartosz Blimke authored
16
17 Supported HTTP libraries
18 ------------------------
19
3d84ef6 Added EM-HTTP-Request to the list of supported http clients
Bartosz Blimke authored
20 * Net::HTTP and libraries based on Net::HTTP (i.e RightHttpConnection, REST Client, HTTParty)
fb18a01 Updated README with info about matching request body against hash
Bartosz Blimke authored
21 * HTTPClient
22 * Patron
3d84ef6 Added EM-HTTP-Request to the list of supported http clients
Bartosz Blimke authored
23 * EM-HTTP-Request
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
24
25 Installation
26 ------------
27
28 gem install webmock --source http://gemcutter.org
29
30 In your `test/test_helper.rb` add these two lines:
31
32 require 'webmock/test_unit'
33
2e88f99 Updated info on how to include WebMock in Test::Unit and RSpec without p...
Bartosz Blimke authored
34 class Test::Unit::TestCase
35 include WebMock
36 end
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
37
38 or if you use RSpec add these lines to `spec/spec_helper`:
39
40 require 'webmock/rspec'
41
2e88f99 Updated info on how to include WebMock in Test::Unit and RSpec without p...
Bartosz Blimke authored
42 Spec::Runner.configure do |config|
43 config.include WebMock
44 end
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
45
feb8ba5 Updated version to 0.7.3
Bartosz Blimke authored
46 You can also use WebMock without RSpec or Test::Unit support:
3ca443e WebMock module has to be included manually and is not included by RSpec ...
Bartosz Blimke authored
47
48 require 'webmock'
49
50 include WebMock
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
51
52 ## Examples
53
54
55
56 ## Stubbing
57
58
59 ### Stubbed request based on uri only and with the default response
60
32c653c Replaced google with example in README
Bartosz Blimke authored
61 stub_request(:any, "www.example.com")
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
62
32c653c Replaced google with example in README
Bartosz Blimke authored
63 Net::HTTP.get("www.example.com", "/") # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
64
65 ### Stubbing requests based on method, uri, body and headers
66
32c653c Replaced google with example in README
Bartosz Blimke authored
67 stub_request(:post, "www.example.com").with(:body => "abc", :headers => { 'Content-Length' => 3 })
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
68
32c653c Replaced google with example in README
Bartosz Blimke authored
69 uri = URI.parse("http://www.example.com/")
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
70 req = Net::HTTP::Post.new(uri.path)
71 req['Content-Length'] = 3
72 res = Net::HTTP.start(uri.host, uri.port) {|http|
73 http.request(req, "abc")
74 } # ===> Success
75
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
76 ### Matching request body and headers against regular expressions
77
78 stub_request(:post, "www.example.com").
79 with(:body => /^.*world$/, :headers => {"Content-Type" => /image\/.+/}).to_return(:body => "abc")
80
81 uri = URI.parse('http://www.example.com/')
82 req = Net::HTTP::Post.new(uri.path)
83 req['Content-Type'] = 'image/png'
84 res = Net::HTTP.start(uri.host, uri.port) {|http|
85 http.request(req, 'hello world')
86 } # ===> Success
fb18a01 Updated README with info about matching request body against hash
Bartosz Blimke authored
87
354af66 Updated CHANGELOG width version 1.3.0 changes
Bartosz Blimke authored
88 ### Matching request body against a hash. Body can be URL-Encoded, JSON or XML.
fb18a01 Updated README with info about matching request body against hash
Bartosz Blimke authored
89
90 stub_http_request(:post, "www.example.com").
91 with(:body => {:data => {:a => '1', :b => 'five'}})
92
93 RestClient.post('www.example.com', "data[a]=1&data[b]=five",
94 :content_type => 'application/x-www-form-urlencoded') # ===> Success
95
96 RestClient.post('www.example.com', '{"data":{"a":"1","b":"five"}}',
97 :content_type => 'application/json') # ===> Success
98
99 RestClient.post('www.example.com', '<data a="1" b="five" />',
100 :content_type => 'application/xml' ) # ===> Success
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
101
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
102 ### Matching custom request headers
103
0016b13 Minor changes to README
Bartosz Blimke authored
104 stub_request(:any, "www.example.com").with(:headers=>{ 'Header-Name' => 'Header-Value' })
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
105
32c653c Replaced google with example in README
Bartosz Blimke authored
106 uri = URI.parse('http://www.example.com/')
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
107 req = Net::HTTP::Post.new(uri.path)
108 req['Header-Name'] = 'Header-Value'
109 res = Net::HTTP.start(uri.host, uri.port) {|http|
110 http.request(req, 'abc')
111 } # ===> Success
112
176482c Updated README with 1.1.0 changes
Bartosz Blimke authored
113 ### Matching multiple headers with the same name
114
115 stub_http_request(:get, 'www.example.com').with(:headers => {'Accept' => ['image/jpeg', 'image/png'] })
116
117 req = Net::HTTP::Get.new("/")
118 req['Accept'] = ['image/png']
119 req.add_field('Accept', 'image/jpeg')
120 Net::HTTP.start("www.example.com") {|http| http.request(req) } # ===> Success
121
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
122 ### Matching requests against provided block
123
0016b13 Minor changes to README
Bartosz Blimke authored
124 stub_request(:post, "www.example.com").with { |request| request.body == "abc" }
125 RestClient.post('www.example.com', 'abc') # ===> Success
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
126
127 ### Request with basic authentication
128
129 stub_request(:get, "user:pass@www.example.com")
130
131 Net::HTTP.start('www.example.com') {|http|
132 req = Net::HTTP::Get.new('/')
133 req.basic_auth 'user', 'pass'
134 http.request(req)
135 } # ===> Success
136
137 ### Matching uris using regular expressions
138
139 stub_request(:any, /.*example.*/)
140
141 Net::HTTP.get('www.example.com', '/') # ===> Success
316263c Added info about declaring query params inside stubs as a hash
Bartosz Blimke authored
142
143 ### Matching query params using hash
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
144
316263c Added info about declaring query params inside stubs as a hash
Bartosz Blimke authored
145 stub_http_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]})
146
147 RestClient.get("http://www.example.com/?a[]=b&a[]=c") # ===> Success
148
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
149 ### Stubbing with custom response
150
32c653c Replaced google with example in README
Bartosz Blimke authored
151 stub_request(:any, "www.example.com").to_return(:body => "abc", :status => 200, :headers => { 'Content-Length' => 3 } )
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
152
32c653c Replaced google with example in README
Bartosz Blimke authored
153 Net::HTTP.get("www.example.com", '/') # ===> "abc"
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
154
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
155 ### Response with body specified as IO object
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
156
157 File.open('/tmp/response_body.txt', 'w') { |f| f.puts 'abc' }
158
32c653c Replaced google with example in README
Bartosz Blimke authored
159 stub_request(:any, "www.example.com").to_return(:body => File.new('/tmp/response_body.txt'), :status => 200)
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
160
32c653c Replaced google with example in README
Bartosz Blimke authored
161 Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
162
3314aad Added support for status messages
Bartosz Blimke authored
163 ### Response with custom status message
164
165 stub_request(:any, "www.example.com").to_return(:status => [500, "Internal Server Error"])
166
167 req = Net::HTTP::Get.new("/")
168 Net::HTTP.start("www.example.com") { |http| http.request(req) }.message # ===> "Internal Server Error"
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
169
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
170 ### Replaying raw responses recorded with `curl -is`
171
172 `curl -is www.example.com > /tmp/example_curl_-is_output.txt`
173 raw_response_file = File.new("/tmp/example_curl_-is_output.txt")
174
175 from file
176
177 stub_request(:get, "www.example.com").to_return(raw_response_file)
178
179 or string
180
181 stub_request(:get, "www.example.com").to_return(raw_response_file.read)
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
182
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
183 ### Responses dynamically evaluated from block
184
4e0568a Added information about dynamic responses to README
Bartosz Blimke authored
185 stub_request(:any, 'www.example.net').
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
186 to_return { |request| {:body => request.body} }
4e0568a Added information about dynamic responses to README
Bartosz Blimke authored
187
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
188 RestClient.post('www.example.net', 'abc') # ===> "abc\n"
5b1c97b @tomafro Added complete dynamic request, where headers, body and status can all b...
tomafro authored
189
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
190 ### Responses dynamically evaluated from lambda
5b1c97b @tomafro Added complete dynamic request, where headers, body and status can all b...
tomafro authored
191
192 stub_request(:any, 'www.example.net').
193 to_return(lambda { |request| {:body => request.body} })
194
195 RestClient.post('www.example.net', 'abc') # ===> "abc\n"
4e0568a Added information about dynamic responses to README
Bartosz Blimke authored
196
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
197 ### Responses with dynamically evaluated parts
198
199 stub_request(:any, 'www.example.net').
200 to_return(:body => lambda { |request| request.body })
201
202 RestClient.post('www.example.net', 'abc') # ===> "abc\n"
203
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
204 ### Raising errors
205
207443e `to_raise()` now accepts exception instance or a string as argument in a...
Bartosz Blimke authored
206 #### Exception declared by class
207
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
208 stub_request(:any, 'www.example.net').to_raise(StandardError)
209
210 RestClient.post('www.example.net', 'abc') # ===> StandardError
207443e `to_raise()` now accepts exception instance or a string as argument in a...
Bartosz Blimke authored
211
212 #### or by exception instance
213
214 stub_request(:any, 'www.example.net').to_raise(StandardError.new("some error"))
215
216 #### or by string
217
218 stub_request(:any, 'www.example.net').to_raise("some error")
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
219
220 ### Raising timeout errors
221
222 stub_request(:any, 'www.example.net').to_timeout
223
224 RestClient.post('www.example.net', 'abc') # ===> RestClient::RequestTimeout
225
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
226 ### Multiple responses for repeated requests
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
227
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
228 stub_request(:get, "www.example.com").to_return({:body => "abc"}, {:body => "def"})
229 Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
230 Net::HTTP.get('www.example.com', '/') # ===> "def\n"
231
232 #after all responses are used the last response will be returned infinitely
233
234 Net::HTTP.get('www.example.com', '/') # ===> "def\n"
bb41263 Improved section about basic authentication support in readme.
Bartosz Blimke authored
235
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
236 ### Multiple responses using chained `to_return()`, `to_raise()` or `to_timeout` declarations
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
237
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
238 stub_request(:get, "www.example.com").
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
239 to_return({:body => "abc"}).then. #then() is just a syntactic sugar
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
240 to_return({:body => "def"}).then.
241 to_raise(MyException)
242 Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
243 Net::HTTP.get('www.example.com', '/') # ===> "def\n"
244 Net::HTTP.get('www.example.com', '/') # ===> MyException raised
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
245
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
246 ### Specifying number of times given response should be returned
247
248 stub_request(:get, "www.example.com").
249 to_return({:body => "abc"}).times(2).then.
250 to_return({:body => "def"})
251
252 Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
253 Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
254 Net::HTTP.get('www.example.com', '/') # ===> "def\n"
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
255
256
257 ### Real requests to network can be allowed or disabled
258
259 WebMock.allow_net_connect!
260
32c653c Replaced google with example in README
Bartosz Blimke authored
261 stub_request(:any, "www.example.com").to_return(:body => "abc")
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
262
32c653c Replaced google with example in README
Bartosz Blimke authored
263 Net::HTTP.get('www.example.com', '/') # ===> "abc"
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
264
265 Net::HTTP.get('www.something.com', '/') # ===> /.+Something.+/
266
267 WebMock.disable_net_connect!
268
269 Net::HTTP.get('www.something.com', '/') # ===> Failure
270
8859deb @macksmind Change the locahost option syntax and update README
macksmind authored
271 ### External requests can be disabled while allowing localhost
272
4c6c6a9 Fixed code formatting in README
Bartosz Blimke authored
273 WebMock.disable_net_connect!(:allow_localhost => true)
8859deb @macksmind Change the locahost option syntax and update README
macksmind authored
274
4c6c6a9 Fixed code formatting in README
Bartosz Blimke authored
275 Net::HTTP.get('www.something.com', '/') # ===> Failure
8859deb @macksmind Change the locahost option syntax and update README
macksmind authored
276
4c6c6a9 Fixed code formatting in README
Bartosz Blimke authored
277 Net::HTTP.get('localhost:9887', '/') # ===> Allowed. Perhaps to Selenium?
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
278
279 ## Setting Expectations
280
281 ### Setting expectations in Test::Unit
282 require 'webmock/test_unit'
283
32c653c Replaced google with example in README
Bartosz Blimke authored
284 stub_request(:any, "www.example.com")
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
285
32c653c Replaced google with example in README
Bartosz Blimke authored
286 uri = URI.parse('http://www.example.com/')
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
287 req = Net::HTTP::Post.new(uri.path)
288 req['Content-Length'] = 3
289 res = Net::HTTP.start(uri.host, uri.port) {|http|
290 http.request(req, 'abc')
291 }
292
32c653c Replaced google with example in README
Bartosz Blimke authored
293 assert_requested :post, "http://www.example.com",
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
294 :headers => {'Content-Length' => 3}, :body => "abc", :times => 1 # ===> Success
295
296 assert_not_requested :get, "http://www.something.com" # ===> Success
297
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
298 assert_requested(:post, "http://www.example.com", :times => 1) { |req| req.body == "abc" }
299
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
300 ### Expecting real (not stubbed) requests
301
302 WebMock.allow_net_connect!
303
32c653c Replaced google with example in README
Bartosz Blimke authored
304 Net::HTTP.get('www.example.com', '/') # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
305
32c653c Replaced google with example in README
Bartosz Blimke authored
306 assert_requested :get, "http://www.example.com" # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
307
308
309 ### Setting expectations in RSpec
310 This style is borrowed from [fakeweb-matcher](http://github.com/freelancing-god/fakeweb-matcher)
311
312 require 'webmock/rspec'
313
32c653c Replaced google with example in README
Bartosz Blimke authored
314 WebMock.should have_requested(:get, "www.example.com").with(:body => "abc", :headers => {'Content-Length' => 3}).twice
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
315
316 WebMock.should_not have_requested(:get, "www.something.com")
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
317
318 WebMock.should have_requested(:post, "www.example.com").with { |req| req.body == "abc" }
fa4ab29 Updated README with info about setting expectations on query params or b...
Bartosz Blimke authored
319
320 WebMock.should have_requested(:get, "www.example.com").with(:query => {"a" => ["b", "c"]})
321
322 WebMock.should have_requested(:get, "www.example.com").
323 with(:body => {"a" => ["b", "c"]}, :headers => 'Content-Type' => 'application/json')
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
324
325 ### Different way of setting expectations in RSpec
326
32c653c Replaced google with example in README
Bartosz Blimke authored
327 request(:post, "www.example.com").with(:body => "abc", :headers => {'Content-Length' => 3}).should have_been_made.once
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
328
329 request(:post, "www.something.com").should have_been_made.times(3)
330
331 request(:any, "www.example.com").should_not have_been_made
332
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
333 request(:post, "www.example.com").with { |req| req.body == "abc" }.should have_been_made
334
fa4ab29 Updated README with info about setting expectations on query params or b...
Bartosz Blimke authored
335 request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).should have_been_made
336
337 request(:post, "www.example.com").
338 with(:body => {"a" => ["b", "c"]}, :headers => 'Content-Type' => 'application/json').should have_been_made
339
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
340 ## Clearing stubs and request history
341
342 If you want to reset all current stubs and history of requests use `WebMock.reset_webmock`
343
32c653c Replaced google with example in README
Bartosz Blimke authored
344 stub_request(:any, "www.example.com")
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
345
32c653c Replaced google with example in README
Bartosz Blimke authored
346 Net::HTTP.get('www.example.com', '/') # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
347
348 reset_webmock
349
32c653c Replaced google with example in README
Bartosz Blimke authored
350 Net::HTTP.get('www.example.com', '/') # ===> Failure
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
351
32c653c Replaced google with example in README
Bartosz Blimke authored
352 assert_not_requested :get, "www.example.com" # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
353
354
355 ## Matching requests
356
357 An executed request matches stubbed request if it passes following criteria:
358
4306efa Ability to register and expect requests with empty body.
Bartosz Blimke authored
359 When request URI matches stubbed request URI string or Regexp pattern<br/>
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
360 And request method is the same as stubbed request method or stubbed request method is :any<br/>
4306efa Ability to register and expect requests with empty body.
Bartosz Blimke authored
361 And request body is the same as stubbed request body or stubbed request body is not specified<br/>
0016b13 Minor changes to README
Bartosz Blimke authored
362 And request headers match stubbed request headers, or stubbed request headers match a subset of request headers, or stubbed request headers are not specified<br/>
363 And request matches provided block or block is not provided
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
364
365 ## Precedence of stubs
366
367 Always the last declared stub matching the request will be applied i.e:
368
32c653c Replaced google with example in README
Bartosz Blimke authored
369 stub_request(:get, "www.example.com").to_return(:body => "abc")
370 stub_request(:get, "www.example.com").to_return(:body => "def")
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
371
32c653c Replaced google with example in README
Bartosz Blimke authored
372 Net::HTTP.get('www.example.com', '/') # ====> "def"
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
373
374 ## Matching URIs
375
376 WebMock will match all different representations of the same URI.
377
378 I.e all the following representations of the URI are equal:
379
32c653c Replaced google with example in README
Bartosz Blimke authored
380 "www.example.com"
381 "www.example.com/"
382 "www.example.com:80"
383 "www.example.com:80/"
384 "http://www.example.com"
385 "http://www.example.com/"
386 "http://www.example.com:80"
387 "http://www.example.com:80/"
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
388
389 The following URIs with basic authentication are also equal for WebMock
390
32c653c Replaced google with example in README
Bartosz Blimke authored
391 "a b:pass@www.example.com"
392 "a b:pass@www.example.com/"
393 "a b:pass@www.example.com:80"
394 "a b:pass@www.example.com:80/"
395 "http://a b:pass@www.example.com"
396 "http://a b:pass@www.example.com/"
397 "http://a b:pass@www.example.com:80"
398 "http://a b:pass@www.example.com:80/"
399 "a%20b:pass@www.example.com"
400 "a%20b:pass@www.example.com/"
401 "a%20b:pass@www.example.com:80"
402 "a%20b:pass@www.example.com:80/"
403 "http://a%20b:pass@www.example.com"
404 "http://a%20b:pass@www.example.com/"
405 "http://a%20b:pass@www.example.com:80"
406 "http://a%20b:pass@www.example.com:80/"
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
407
408 or these
409
78414b7 Improved examples with equality of URIs with the same parameters
Bartosz Blimke authored
410 "www.example.com/my path/?a=my param&b=c"
411 "www.example.com/my%20path/?a=my%20param&b=c"
412 "www.example.com:80/my path/?a=my param&b=c"
413 "www.example.com:80/my%20path/?a=my%20param&b=c"
414 "http://www.example.com/my path/?a=my param&b=c"
415 "http://www.example.com/my%20path/?a=my%20param&b=c"
416 "http://www.example.com:80/my path/?a=my param&b=c"
417 "http://www.example.com:80/my%20path/?a=my%20param&b=c"
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
418
419
420 If you provide Regexp to match URI, WebMock will try to match it against every valid form of the same url.
421
78414b7 Improved examples with equality of URIs with the same parameters
Bartosz Blimke authored
422 I.e `/.*my param.*/` will match `www.example.com/my%20path` because it is equivalent of `www.example.com/my path`
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
423
424
425 ## Matching headers
426
427 WebMock will match request headers against stubbed request headers in the following situations:
428
429 1. Stubbed request has headers specified and request headers are the same as stubbed headers <br/>
430 i.e stubbed headers: `{ 'Header1' => 'Value1', 'Header1' => 'Value1' }`, requested: `{ 'Header1' => 'Value1', 'Header1' => 'Value1' }`
431
432 2. Stubbed request has headers specified and stubbed request headers are a subset of request headers <br/>
433 i.e stubbed headers: `{ 'Header1' => 'Value1' }`, requested: `{ 'Header1' => 'Value1', 'Header1' => 'Value1' }`
434
435 3. Stubbed request has no headers <br/>
436 i.e stubbed headers: `nil`, requested: `{ 'Header1' => 'Value1', 'Header1' => 'Value1' }`
437
438 WebMock normalises headers and treats all forms of same headers as equal:
439 i.e the following two sets of headers are equal:
440
441 `{ "Header1" => "value1", :content_length => 123, :X_CuStOm_hEAder => :value }`
442
443 `{ :header1 => "value1", "Content-Length" => 123, "x-cuSTOM-HeAder" => "value" }`
444
176482c Updated README with 1.1.0 changes
Bartosz Blimke authored
445 ## Recording real requests and responses and replaying them later
446
447 To record your application's real HTTP interactions and replay them later in tests you can use [VCR](http://github.com/myronmarston/vcr) with WebMock.
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
448
5331132 Updated README with information about request callbacks
Bartosz Blimke authored
449 ## Request callbacks
450
354af66 Updated CHANGELOG width version 1.3.0 changes
Bartosz Blimke authored
451 ####WebMock can invoke callbacks stubbed or real requests:
5331132 Updated README with information about request callbacks
Bartosz Blimke authored
452
453 WebMock.after_request do |request_signature, response|
354af66 Updated CHANGELOG width version 1.3.0 changes
Bartosz Blimke authored
454 puts "Request #{request_signature} was made and #{response} was returned"
5331132 Updated README with information about request callbacks
Bartosz Blimke authored
455 end
456
457 #### invoke callbacks for real requests only and except requests made with Patron
458
459 WebMock.after_request(:except => [:patron], :real_requests_only => true) do |request_signature, response|
354af66 Updated CHANGELOG width version 1.3.0 changes
Bartosz Blimke authored
460 puts "Request #{request_signature} was made and #{response} was returned"
5331132 Updated README with information about request callbacks
Bartosz Blimke authored
461 end
462
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
463 ## Bugs and Issues
464
465 Please submit them here [http://github.com/bblimke/webmock/issues](http://github.com/bblimke/webmock/issues)
466
467 ## Suggestions
468
469 If you have any suggestions on how to improve WebMock please send an email to the mailing list [groups.google.com/group/webmock-users](http://groups.google.com/group/webmock-users)
470
471 I'm particularly interested in how the DSL could be improved.
472
473 ## Credits
474
00424d9 Updated credits in README
Bartosz Blimke authored
475 The initial lines of this project were written during New Bamboo [Hack Day](http://blog.new-bamboo.co.uk/2009/11/13/hackday-results)
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
476 Thanks to my fellow [Bambinos](http://new-bamboo.co.uk/) for all the great suggestions!
477
00424d9 Updated credits in README
Bartosz Blimke authored
478 People who submitted patches and new features or suggested improvements. Many thanks to these people:
479
480 * Ben Pickles
481 * Mark Evans
482 * Ivan Vega
483 * Piotr Usewicz
484 * Nick Plante
485 * Nick Quaranto
486 * Diego E. "Flameeyes" Pettenò
487 * Niels Meersschaert
488 * Mack Earnhardt
489 * Arvicco
490 * Sergio Gil
491 * Jeffrey Jones
492 * Tekin Suleyman
493 * Tom Ward
494 * Nadim Bitar
ee7b3b4 Fixed spelling
Bartosz Blimke authored
495 * Myron Marston
9c8c463 Updated README with information about RSpec 2 support.
Bartosz Blimke authored
496 * Sam Phillips
2e88f99 Updated info on how to include WebMock in Test::Unit and RSpec without p...
Bartosz Blimke authored
497 * Jose Angel Cortinas
52698d8 Updated credits
Bartosz Blimke authored
498 * Razic
fd2472a Version 1.2.2 changelog
Bartosz Blimke authored
499 * Steve Tooke
fb18a01 Updated README with info about matching request body against hash
Bartosz Blimke authored
500 * Nathaniel Bibler
00424d9 Updated credits in README
Bartosz Blimke authored
501
502 ## Background
503
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
504 Thank you Fakeweb! This library was inspired by [FakeWeb](fakeweb.rubyforge.org).
00424d9 Updated credits in README
Bartosz Blimke authored
505 I imported some solutions from that project to WebMock. I also copied some code i.e Net:HTTP adapter.
95e8298 Revert "WebMock module has to be included manually and is not included b...
Bartosz Blimke authored
506 Fakeweb architecture unfortunately didn't allow me to extend it easily with the features I needed.
507 I also preferred some things to work differently i.e request stub precedence.
508
509 ## Copyright
510
bf18e89 Changed license from GPL to MIT
Bartosz Blimke authored
511 Copyright (c) 2009-2010 Bartosz Blimke. See LICENSE for details.
Something went wrong with that request. Please try again.