Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 566 lines (357 sloc) 18.903 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
7c2b9cf @bblimke WebMock is looking for a maintainer
authored
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
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
12 Features
13 --------
14
0016b13 Minor changes to README
Bartosz Blimke authored
15 * 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
16 * Setting and verifying expectations on HTTP requests
17 * Matching requests based on method, URI, headers and body
18 * Smart matching of the same URIs in different representations (also encoded and non encoded forms)
19 * Smart matching of the same headers in different representations.
9c8c463 Updated README with information about RSpec 2 support.
Bartosz Blimke authored
20 * Support for Test::Unit
21 * Support for RSpec 1.x and RSpec 2.x
fb18a01 Updated README with info about matching request body against hash
Bartosz Blimke authored
22
23 Supported HTTP libraries
24 ------------------------
25
3d84ef6 Added EM-HTTP-Request to the list of supported http clients
Bartosz Blimke authored
26 * 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
27 * HTTPClient
28 * Patron
3d84ef6 Added EM-HTTP-Request to the list of supported http clients
Bartosz Blimke authored
29 * EM-HTTP-Request
ed9ff32 @bblimke WebMock currently doesn't support Curb::Multi
authored
30 * Curb (currently only Curb::Easy)
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
31
f25a213 @bblimke Improved README on how to include WebMock in Test::Unit, RSpec and Cu…
authored
32 ##Installation
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
33
7a8bab1 @bblimke Added info on how to install the latest development version of WebMoc…
authored
34 gem install webmock --source http://gemcutter.org
35
36 ### or to install the latest development version from github master
37
38 git clone http://github.com/bblimke/webmock.git
39 cd webmock
40 rake install
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
41
f25a213 @bblimke Improved README on how to include WebMock in Test::Unit, RSpec and Cu…
authored
42 ### Test::Unit
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
43
f25a213 @bblimke Improved README on how to include WebMock in Test::Unit, RSpec and Cu…
authored
44 Add the following code to `test/test_helper.rb`
45
46 require 'webmock/test_unit'
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
47
f25a213 @bblimke Improved README on how to include WebMock in Test::Unit, RSpec and Cu…
authored
48 ### RSpec
49
50 Add the following code to `spec/spec_helper`:
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
51
52 require 'webmock/rspec'
53
f25a213 @bblimke Improved README on how to include WebMock in Test::Unit, RSpec and Cu…
authored
54 ### Cucumber
55
56 Add the following code to `features/support/env.rb`
3ca443e WebMock module has to be included manually and is not included by RSp…
Bartosz Blimke authored
57
5d4559b @bblimke Adding WebMock support to cucumber now requires only: require 'webmoc…
authored
58 require 'webmock/cucumber'
f25a213 @bblimke Improved README on how to include WebMock in Test::Unit, RSpec and Cu…
authored
59
60 You can also use WebMock outside a test framework:
61
62 require 'webmock'
08d6cce @bblimke Moved all WebMock instance methods to WebMock::API module and depreca…
authored
63 include WebMock::API
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
64
65 ## Examples
66
67
68
69 ## Stubbing
70
71
72 ### Stubbed request based on uri only and with the default response
73
32c653c Replaced google with example in README
Bartosz Blimke authored
74 stub_request(:any, "www.example.com")
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
75
32c653c Replaced google with example in README
Bartosz Blimke authored
76 Net::HTTP.get("www.example.com", "/") # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
77
78 ### Stubbing requests based on method, uri, body and headers
79
32c653c Replaced google with example in README
Bartosz Blimke authored
80 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
81
32c653c Replaced google with example in README
Bartosz Blimke authored
82 uri = URI.parse("http://www.example.com/")
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
83 req = Net::HTTP::Post.new(uri.path)
84 req['Content-Length'] = 3
85 res = Net::HTTP.start(uri.host, uri.port) {|http|
86 http.request(req, "abc")
87 } # ===> Success
88
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
89 ### Matching request body and headers against regular expressions
90
91 stub_request(:post, "www.example.com").
92 with(:body => /^.*world$/, :headers => {"Content-Type" => /image\/.+/}).to_return(:body => "abc")
93
94 uri = URI.parse('http://www.example.com/')
95 req = Net::HTTP::Post.new(uri.path)
96 req['Content-Type'] = 'image/png'
97 res = Net::HTTP.start(uri.host, uri.port) {|http|
98 http.request(req, 'hello world')
99 } # ===> Success
fb18a01 Updated README with info about matching request body against hash
Bartosz Blimke authored
100
354af66 Updated CHANGELOG width version 1.3.0 changes
Bartosz Blimke authored
101 ### 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
102
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
111
112 RestClient.post('www.example.com', '<data a="1" b="five" />',
113 :content_type => 'application/xml' ) # ===> Success
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
114
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
115 ### Matching custom request headers
116
0016b13 Minor changes to README
Bartosz Blimke authored
117 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
118
32c653c Replaced google with example in README
Bartosz Blimke authored
119 uri = URI.parse('http://www.example.com/')
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
120 req = Net::HTTP::Post.new(uri.path)
121 req['Header-Name'] = 'Header-Value'
122 res = Net::HTTP.start(uri.host, uri.port) {|http|
123 http.request(req, 'abc')
124 } # ===> Success
125
176482c Updated README with 1.1.0 changes
Bartosz Blimke authored
126 ### Matching multiple headers with the same name
127
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
134
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
135 ### Matching requests against provided block
136
0016b13 Minor changes to README
Bartosz Blimke authored
137 stub_request(:post, "www.example.com").with { |request| request.body == "abc" }
138 RestClient.post('www.example.com', 'abc') # ===> Success
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
139
140 ### Request with basic authentication
141
142 stub_request(:get, "user:pass@www.example.com")
143
144 Net::HTTP.start('www.example.com') {|http|
145 req = Net::HTTP::Get.new('/')
146 req.basic_auth 'user', 'pass'
147 http.request(req)
148 } # ===> Success
149
150 ### Matching uris using regular expressions
151
152 stub_request(:any, /.*example.*/)
153
154 Net::HTTP.get('www.example.com', '/') # ===> Success
316263c Added info about declaring query params inside stubs as a hash
Bartosz Blimke authored
155
156 ### Matching query params using hash
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
157
316263c Added info about declaring query params inside stubs as a hash
Bartosz Blimke authored
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
161
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
162 ### Stubbing with custom response
163
32c653c Replaced google with example in README
Bartosz Blimke authored
164 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
165
32c653c Replaced google with example in README
Bartosz Blimke authored
166 Net::HTTP.get("www.example.com", '/') # ===> "abc"
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
167
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
168 ### Response with body specified as IO object
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
169
170 File.open('/tmp/response_body.txt', 'w') { |f| f.puts 'abc' }
171
32c653c Replaced google with example in README
Bartosz Blimke authored
172 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
173
32c653c Replaced google with example in README
Bartosz Blimke authored
174 Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
175
3314aad Added support for status messages
Bartosz Blimke authored
176 ### Response with custom status message
177
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"
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
182
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
183 ### Replaying raw responses recorded with `curl -is`
184
185 `curl -is www.example.com > /tmp/example_curl_-is_output.txt`
186 raw_response_file = File.new("/tmp/example_curl_-is_output.txt")
187
188 from file
189
190 stub_request(:get, "www.example.com").to_return(raw_response_file)
191
192 or string
193
194 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
195
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
196 ### Responses dynamically evaluated from block
197
4e0568a Added information about dynamic responses to README
Bartosz Blimke authored
198 stub_request(:any, 'www.example.net').
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
199 to_return { |request| {:body => request.body} }
4e0568a Added information about dynamic responses to README
Bartosz Blimke authored
200
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
201 RestClient.post('www.example.net', 'abc') # ===> "abc\n"
f0408f8 @bblimke Added support for dynamically evaluated raw responses recorded with `…
authored
202
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
203 ### Responses dynamically evaluated from lambda
f0408f8 @bblimke Added support for dynamically evaluated raw responses recorded with `…
authored
204
5b1c97b @tomafro Added complete dynamic request, where headers, body and status can al…
tomafro authored
205 stub_request(:any, 'www.example.net').
206 to_return(lambda { |request| {:body => request.body} })
207
208 RestClient.post('www.example.net', 'abc') # ===> "abc\n"
4e0568a Added information about dynamic responses to README
Bartosz Blimke authored
209
f0408f8 @bblimke Added support for dynamically evaluated raw responses recorded with `…
authored
210 ### Dynamically evaluated raw responses recorded with `curl -is`
211
212 `curl -is www.example.com > /tmp/www.example.com.txt`
213 stub_request(:get, "www.example.com").to_return(lambda { |request| File.new("/tmp/#{request.uri.host.to_s}.txt" }))
214
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
215 ### Responses with dynamically evaluated parts
216
217 stub_request(:any, 'www.example.net').
218 to_return(:body => lambda { |request| request.body })
219
220 RestClient.post('www.example.net', 'abc') # ===> "abc\n"
221
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
222 ### Raising errors
223
207443e `to_raise()` now accepts exception instance or a string as argument i…
Bartosz Blimke authored
224 #### Exception declared by class
225
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
226 stub_request(:any, 'www.example.net').to_raise(StandardError)
227
228 RestClient.post('www.example.net', 'abc') # ===> StandardError
207443e `to_raise()` now accepts exception instance or a string as argument i…
Bartosz Blimke authored
229
230 #### or by exception instance
231
232 stub_request(:any, 'www.example.net').to_raise(StandardError.new("some error"))
233
234 #### or by string
235
236 stub_request(:any, 'www.example.net').to_raise("some error")
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
237
238 ### Raising timeout errors
239
240 stub_request(:any, 'www.example.net').to_timeout
241
242 RestClient.post('www.example.net', 'abc') # ===> RestClient::RequestTimeout
243
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
244 ### Multiple responses for repeated requests
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
245
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
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"
bb41263 Improved section about basic authentication support in readme.
Bartosz Blimke authored
253
af52fe7 Added support for declaring timeout errors using `to_timeout`
Bartosz Blimke authored
254 ### 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
255
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
256 stub_request(:get, "www.example.com").
0f3bb21 Updated README regarding dynamic responses
Bartosz Blimke authored
257 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
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
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
263
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
264 ### Specifying number of times given response should be returned
265
266 stub_request(:get, "www.example.com").
267 to_return({:body => "abc"}).times(2).then.
268 to_return({:body => "def"})
269
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"
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
273
274
275 ### Real requests to network can be allowed or disabled
276
277 WebMock.allow_net_connect!
278
32c653c Replaced google with example in README
Bartosz Blimke authored
279 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
280
32c653c Replaced google with example in README
Bartosz Blimke authored
281 Net::HTTP.get('www.example.com', '/') # ===> "abc"
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
282
283 Net::HTTP.get('www.something.com', '/') # ===> /.+Something.+/
284
285 WebMock.disable_net_connect!
286
287 Net::HTTP.get('www.something.com', '/') # ===> Failure
288
8859deb @MacksMind Change the locahost option syntax and update README
MacksMind authored
289 ### External requests can be disabled while allowing localhost
290
4c6c6a9 Fixed code formatting in README
Bartosz Blimke authored
291 WebMock.disable_net_connect!(:allow_localhost => true)
8859deb @MacksMind Change the locahost option syntax and update README
MacksMind authored
292
4c6c6a9 Fixed code formatting in README
Bartosz Blimke authored
293 Net::HTTP.get('www.something.com', '/') # ===> Failure
8859deb @MacksMind Change the locahost option syntax and update README
MacksMind authored
294
4c6c6a9 Fixed code formatting in README
Bartosz Blimke authored
295 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
296
67a0819 @bblimke Version 1.3.5 changelog + updated docs
authored
297 ### External requests can be disabled while allowing any hostname
298
299 WebMock.disable_net_connect!(:allow => "www.example.org")
300
301 Net::HTTP.get('www.something.com', '/') # ===> Failure
302
303 Net::HTTP.get('www.example.org', '/') # ===> Allowed.
304
4e313c2 @bblimke Updated CHANGELOG and README with information about net_http_connect_…
authored
305 ## Connecting on Net::HTTP.start
306
c92144f @bblimke Fixed text formatting in README
authored
307 HTTP protocol has 3 steps: connect, request and response (or 4 with close). Most Ruby HTTP client libraries
308 treat connect as a part of request step, with the exception of `Net::HTTP` which
309 allows opening connection to the server separately to the request, by using `Net::HTTP.start`.
4e313c2 @bblimke Updated CHANGELOG and README with information about net_http_connect_…
authored
310
c92144f @bblimke Fixed text formatting in README
authored
311 WebMock API was also designed with connect being part of request step, and it only allows stubbing
312 requests, not connections. When `Net::HTTP.start` is called, WebMock doesn't know yet whether
313 a request is stubbed or not. WebMock by default delays a connection until the request is invoked,
314 so when there is no request, `Net::HTTP.start` doesn't do anything.
315 **This means that WebMock breaks the Net::HTTP behaviour by default!**
4e313c2 @bblimke Updated CHANGELOG and README with information about net_http_connect_…
authored
316
079a719 @bblimke Updated changelog with version 1.5.0 changes
authored
317 To workaround this issue, WebMock offers `:net_http_connect_on_start` option,
318 which can be passed to `WebMock.allow_net_connect!` and `WebMock#disable_net_connect!` methods, i.e.
4e313c2 @bblimke Updated CHANGELOG and README with information about net_http_connect_…
authored
319
c92144f @bblimke Fixed text formatting in README
authored
320 WebMock.allow_net_connect!(:net_http_connect_on_start => true)
4e313c2 @bblimke Updated CHANGELOG and README with information about net_http_connect_…
authored
321
c92144f @bblimke Fixed text formatting in README
authored
322 This forces WebMock Net::HTTP adapter to always connect on `Net::HTTP.start`.
4e313c2 @bblimke Updated CHANGELOG and README with information about net_http_connect_…
authored
323
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
324 ## Setting Expectations
325
326 ### Setting expectations in Test::Unit
327 require 'webmock/test_unit'
328
32c653c Replaced google with example in README
Bartosz Blimke authored
329 stub_request(:any, "www.example.com")
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
330
32c653c Replaced google with example in README
Bartosz Blimke authored
331 uri = URI.parse('http://www.example.com/')
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
332 req = Net::HTTP::Post.new(uri.path)
333 req['Content-Length'] = 3
334 res = Net::HTTP.start(uri.host, uri.port) {|http|
335 http.request(req, 'abc')
336 }
337
32c653c Replaced google with example in README
Bartosz Blimke authored
338 assert_requested :post, "http://www.example.com",
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
339 :headers => {'Content-Length' => 3}, :body => "abc", :times => 1 # ===> Success
340
341 assert_not_requested :get, "http://www.something.com" # ===> Success
342
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
343 assert_requested(:post, "http://www.example.com", :times => 1) { |req| req.body == "abc" }
344
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
345 ### Expecting real (not stubbed) requests
346
347 WebMock.allow_net_connect!
348
32c653c Replaced google with example in README
Bartosz Blimke authored
349 Net::HTTP.get('www.example.com', '/') # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
350
32c653c Replaced google with example in README
Bartosz Blimke authored
351 assert_requested :get, "http://www.example.com" # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
352
353
354 ### Setting expectations in RSpec
355 This style is borrowed from [fakeweb-matcher](http://github.com/freelancing-god/fakeweb-matcher)
356
357 require 'webmock/rspec'
358
32c653c Replaced google with example in README
Bartosz Blimke authored
359 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
360
361 WebMock.should_not have_requested(:get, "www.something.com")
5313e02 Added version 0.9.0 features to CHANGELOG and README
Bartosz Blimke authored
362
363 WebMock.should have_requested(:post, "www.example.com").with { |req| req.body == "abc" }
fa4ab29 Updated README with info about setting expectations on query params o…
Bartosz Blimke authored
364
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')
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
369
370 ### Different way of setting expectations in RSpec
371
6cb45ed @bblimke Renames WebMock#request to WebMock#a_request to avoid conflicts with …
authored
372 a_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
373
6cb45ed @bblimke Renames WebMock#request to WebMock#a_request to avoid conflicts with …
authored
374 a_request(:post, "www.something.com").should have_been_made.times(3)
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
375
6cb45ed @bblimke Renames WebMock#request to WebMock#a_request to avoid conflicts with …
authored
376 a_request(:any, "www.example.com").should_not have_been_made
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
377
6cb45ed @bblimke Renames WebMock#request to WebMock#a_request to avoid conflicts with …
authored
378 a_request(:post, "www.example.com").with { |req| req.body == "abc" }.should have_been_made
379
380 a_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).should have_been_made
381
382 a_request(:post, "www.example.com").
fa4ab29 Updated README with info about setting expectations on query params o…
Bartosz Blimke authored
383 with(:body => {"a" => ["b", "c"]}, :headers => 'Content-Type' => 'application/json').should have_been_made
6cb45ed @bblimke Renames WebMock#request to WebMock#a_request to avoid conflicts with …
authored
384
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
385 ## Clearing stubs and request history
386
473b709 @bblimke Added WebMock.reset! method. WebMock.reset_webmock is now deprecated
authored
387 If you want to reset all current stubs and history of requests use `WebMock.reset!`
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
388
32c653c Replaced google with example in README
Bartosz Blimke authored
389 stub_request(:any, "www.example.com")
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
390
32c653c Replaced google with example in README
Bartosz Blimke authored
391 Net::HTTP.get('www.example.com', '/') # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
392
473b709 @bblimke Added WebMock.reset! method. WebMock.reset_webmock is now deprecated
authored
393 WebMock.reset!
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
394
32c653c Replaced google with example in README
Bartosz Blimke authored
395 Net::HTTP.get('www.example.com', '/') # ===> Failure
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
396
32c653c Replaced google with example in README
Bartosz Blimke authored
397 assert_not_requested :get, "www.example.com" # ===> Success
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
398
399
400 ## Matching requests
401
402 An executed request matches stubbed request if it passes following criteria:
403
4306efa Ability to register and expect requests with empty body.
Bartosz Blimke authored
404 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
405 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
406 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
407 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/>
408 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
409
410 ## Precedence of stubs
411
412 Always the last declared stub matching the request will be applied i.e:
413
32c653c Replaced google with example in README
Bartosz Blimke authored
414 stub_request(:get, "www.example.com").to_return(:body => "abc")
415 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
416
32c653c Replaced google with example in README
Bartosz Blimke authored
417 Net::HTTP.get('www.example.com', '/') # ====> "def"
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
418
419 ## Matching URIs
420
421 WebMock will match all different representations of the same URI.
422
423 I.e all the following representations of the URI are equal:
424
32c653c Replaced google with example in README
Bartosz Blimke authored
425 "www.example.com"
426 "www.example.com/"
427 "www.example.com:80"
428 "www.example.com:80/"
429 "http://www.example.com"
430 "http://www.example.com/"
431 "http://www.example.com:80"
432 "http://www.example.com:80/"
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
433
434 The following URIs with basic authentication are also equal for WebMock
435
32c653c Replaced google with example in README
Bartosz Blimke authored
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/"
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
452
453 or these
454
78414b7 Improved examples with equality of URIs with the same parameters
Bartosz Blimke authored
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"
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
463
464
465 If you provide Regexp to match URI, WebMock will try to match it against every valid form of the same url.
466
78414b7 Improved examples with equality of URIs with the same parameters
Bartosz Blimke authored
467 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
468
469
470 ## Matching headers
471
472 WebMock will match request headers against stubbed request headers in the following situations:
473
474 1. Stubbed request has headers specified and request headers are the same as stubbed headers <br/>
475 i.e stubbed headers: `{ 'Header1' => 'Value1', 'Header1' => 'Value1' }`, requested: `{ 'Header1' => 'Value1', 'Header1' => 'Value1' }`
476
477 2. Stubbed request has headers specified and stubbed request headers are a subset of request headers <br/>
478 i.e stubbed headers: `{ 'Header1' => 'Value1' }`, requested: `{ 'Header1' => 'Value1', 'Header1' => 'Value1' }`
479
480 3. Stubbed request has no headers <br/>
481 i.e stubbed headers: `nil`, requested: `{ 'Header1' => 'Value1', 'Header1' => 'Value1' }`
482
483 WebMock normalises headers and treats all forms of same headers as equal:
484 i.e the following two sets of headers are equal:
485
486 `{ "Header1" => "value1", :content_length => 123, :X_CuStOm_hEAder => :value }`
487
488 `{ :header1 => "value1", "Content-Length" => 123, "x-cuSTOM-HeAder" => "value" }`
489
176482c Updated README with 1.1.0 changes
Bartosz Blimke authored
490 ## Recording real requests and responses and replaying them later
491
492 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
493
5331132 Updated README with information about request callbacks
Bartosz Blimke authored
494 ## Request callbacks
495
354af66 Updated CHANGELOG width version 1.3.0 changes
Bartosz Blimke authored
496 ####WebMock can invoke callbacks stubbed or real requests:
5331132 Updated README with information about request callbacks
Bartosz Blimke authored
497
498 WebMock.after_request do |request_signature, response|
354af66 Updated CHANGELOG width version 1.3.0 changes
Bartosz Blimke authored
499 puts "Request #{request_signature} was made and #{response} was returned"
5331132 Updated README with information about request callbacks
Bartosz Blimke authored
500 end
501
502 #### invoke callbacks for real requests only and except requests made with Patron
503
504 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
505 puts "Request #{request_signature} was made and #{response} was returned"
5331132 Updated README with information about request callbacks
Bartosz Blimke authored
506 end
507
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
508 ## Bugs and Issues
509
510 Please submit them here [http://github.com/bblimke/webmock/issues](http://github.com/bblimke/webmock/issues)
511
512 ## Suggestions
513
514 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)
515
516 I'm particularly interested in how the DSL could be improved.
517
518 ## Credits
519
00424d9 Updated credits in README
Bartosz Blimke authored
520 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
521 Thanks to my fellow [Bambinos](http://new-bamboo.co.uk/) for all the great suggestions!
522
00424d9 Updated credits in README
Bartosz Blimke authored
523 People who submitted patches and new features or suggested improvements. Many thanks to these people:
524
525 * Ben Pickles
526 * Mark Evans
527 * Ivan Vega
528 * Piotr Usewicz
529 * Nick Plante
530 * Nick Quaranto
531 * Diego E. "Flameeyes" Pettenò
532 * Niels Meersschaert
533 * Mack Earnhardt
534 * Arvicco
535 * Sergio Gil
536 * Jeffrey Jones
537 * Tekin Suleyman
538 * Tom Ward
539 * Nadim Bitar
ee7b3b4 Fixed spelling
Bartosz Blimke authored
540 * Myron Marston
9c8c463 Updated README with information about RSpec 2 support.
Bartosz Blimke authored
541 * Sam Phillips
2e88f99 Updated info on how to include WebMock in Test::Unit and RSpec withou…
Bartosz Blimke authored
542 * Jose Angel Cortinas
52698d8 Updated credits
Bartosz Blimke authored
543 * Razic
fd2472a Version 1.2.2 changelog
Bartosz Blimke authored
544 * Steve Tooke
fb18a01 Updated README with info about matching request body against hash
Bartosz Blimke authored
545 * Nathaniel Bibler
15f888e @bblimke The less hacky way to get the stream behaviour working for em-http-re…
authored
546 * Martyn Loughran
60fa244 @bblimke Updated changelog
authored
547 * Muness Alrubaie
67a0819 @bblimke Version 1.3.5 changelog + updated docs
authored
548 * Charles Li
549 * Ryan Bigg
aaf774b @bblimke Added info to changelog and readme about Curb support, implemented by…
authored
550 * Pete Higgins
ffbcdb3 @bblimke Updated changelog with the latest changes in master branch
authored
551 * Hans de Graaff
4e313c2 @bblimke Updated CHANGELOG and README with information about net_http_connect_…
authored
552 * Alastair Brunton
e6af079 @bblimke Updated 1.6.2 changelog and credits
authored
553 * Sam Stokes
554 * Eugene Bolshakov
00424d9 Updated credits in README
Bartosz Blimke authored
555
556 ## Background
557
95e8298 Revert "WebMock module has to be included manually and is not include…
Bartosz Blimke authored
558 Thank you Fakeweb! This library was inspired by [FakeWeb](fakeweb.rubyforge.org).
00424d9 Updated credits in README
Bartosz Blimke authored
559 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
560 Fakeweb architecture unfortunately didn't allow me to extend it easily with the features I needed.
561 I also preferred some things to work differently i.e request stub precedence.
562
563 ## Copyright
564
bf18e89 Changed license from GPL to MIT
Bartosz Blimke authored
565 Copyright (c) 2009-2010 Bartosz Blimke. See LICENSE for details.
Something went wrong with that request. Please try again.