Skip to content

HTTPS clone URL

Subversion checkout URL

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