Skip to content
Browse files

Added version 0.9.0 features to CHANGELOG and README

  • Loading branch information...
1 parent 689bd29 commit 5313e02f34917267fd19499ad12bebd4d7786509 Bartosz Blimke committed Jan 31, 2010
Showing with 191 additions and 48 deletions.
  1. +0 −36 CHANGELOG
  2. +113 −0 CHANGELOG.md
  3. +78 −12 README.md
View
36 CHANGELOG
@@ -1,36 +0,0 @@
-== 0.8.2
- * Fixed issue where WebMock was not closing IO object passed as response body after reading it.
- * Ruby 1.9.2 compat: Use File#expand_path for require path because "." will not be included in LOAD_PATH since Ruby 1.9.2
-
-== 0.8.1
- * Fixed HTTPClient adapter compatibility with Ruby 1.8.6 (reported by Piotr Usewicz)
- * Net:HTTP adapter now handles request body assigned as Net::HTTP::Post#body attribute (fixed by Mack Earnhardt)
- * Fixed issue where requests were not matching stubs with Accept header set.(reported by Piotr Usewicz)
- * Fixed compatibility with Ruby 1.9.1, 1.9.2 and JRuby 1.3.1 (reported by Diego E. “Flameeyes” Pettenò)
- * Fixed issue with response body declared as IO object and multiple requests (reported by Niels Meersschaert)
- * Fixed "undefined method `assertion_failure'" error (reported by Nick Plante)
-
-== 0.8.0
-
- * Support for HTTPClient (sync and async requests)
- * Support for dynamic responses. Response body and headers can be now declared as lambda.
- (Thanks to Ivan Vega ( @ivanyv ) for suggesting this feature)
- * Support for stubbing and expecting requests with empty body
- * Executing non-stubbed request leads to failed expectation instead of error
-
-=== Bug fixes
-
- * Basic authentication now works correctly
- * Fixed problem where WebMock didn't call a block with the response when block was provided
- * Fixed problem where uris with single slash were not matching uris without path provided
-
-== 0.7.3
-
- * Clarified documentation
- * Fixed some issues with loading of Webmock classes
- * Test::Unit and RSpec adapters have to be required separately
-
-
-== 0.7.2
-
- * Added support for matching escaped and non escaped URLs
View
113 CHANGELOG.md
@@ -0,0 +1,113 @@
+#Changelog
+
+## 0.9.0
+
+* Matching requests against provided block (by Sergio Gil)
+
+ stub_request(:post, "www.example.com").with { |request| request.body == "abc" }.to_return(:body => "def")
+ RestClient.post('www.example.com', 'abc') # ===> "def\n"
+ request(:post, "www.example.com").with { |req| req.body == "abc" }.should have_been_made
+ #or
+ assert_requested(:post, "www.example.com") { |req| req.body == "abc" }
+
+* Matching request body against regular expressions
+
+ stub_request(:post, "www.example.com").with(:body => /^.*world$/).to_return(:body => "abc")
+ RestClient.post('www.example.com', 'hello world') # ===> "abc\n"
+
+* Matching request headers against regular expressions
+
+ stub_request(:post, "www.example.com").with(:headers => {"Content-Type" => /image\/.+/}).to_return(:body => "abc")
+ RestClient.post('www.example.com', '', {'Content-Type' => 'image/png'}) # ===> "abc\n"
+
+* Replaying raw responses recorded with `curl -is`
+
+ `curl -is www.example.com > /tmp/example_curl_-is_output.txt`
+ raw_response_file = File.new("/tmp/example_curl_-is_output.txt")
+
+ from file
+
+ stub_request(:get, "www.example.com").to_return(raw_response_file)
+
+ or string
+
+ stub_request(:get, "www.example.com").to_return(raw_response_file.read)
+
+* Multiple responses for repeated requests
+
+ stub_request(:get, "www.example.com").to_return({:body => "abc"}, {:body => "def"})
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
+
+* Multiple responses using chained `to_return()` or `to_raise()` declarations
+
+ stub_request(:get, "www.example.com").
+ to_return({:body => "abc"}).then. #then() just is a syntactic sugar
+ to_return({:body => "def"}).then.
+ to_raise(MyException)
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
+ Net::HTTP.get('www.example.com', '/') # ===> MyException raised
+
+* Specifying number of times given response should be returned
+
+ stub_request(:get, "www.example.com").
+ to_return({:body => "abc"}).times(2).then.
+ to_return({:body => "def"})
+
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
+
+* Added support for `Net::HTTP::Post#body_stream`
+
+ This fixes compatibility with new versions of RestClient
+
+* WebMock doesn't suppress default request headers added by http clients anymore.
+
+ i.e. Net::HTTP adds `'Accept'=>'*/*'` to all requests by default
+
+
+
+## 0.8.2
+
+ * Fixed issue where WebMock was not closing IO object passed as response body after reading it.
+ * Ruby 1.9.2 compat: Use `File#expand_path` for require path because "." is not be included in LOAD_PATH since Ruby 1.9.2
+
+
+## 0.8.1
+
+ * Fixed HTTPClient adapter compatibility with Ruby 1.8.6 (reported by Piotr Usewicz)
+ * Net:HTTP adapter now handles request body assigned as Net::HTTP::Post#body attribute (fixed by Mack Earnhardt)
+ * Fixed issue where requests were not matching stubs with Accept header set.(reported by Piotr Usewicz)
+ * Fixed compatibility with Ruby 1.9.1, 1.9.2 and JRuby 1.3.1 (reported by Diego E. “Flameeyes” Pettenò)
+ * Fixed issue with response body declared as IO object and multiple requests (reported by Niels Meersschaert)
+ * Fixed "undefined method `assertion_failure'" error (reported by Nick Plante)
+
+
+## 0.8.0
+
+ * Support for HTTPClient (sync and async requests)
+ * Support for dynamic responses. Response body and headers can be now declared as lambda.
+ (Thanks to Ivan Vega ( @ivanyv ) for suggesting this feature)
+ * Support for stubbing and expecting requests with empty body
+ * Executing non-stubbed request leads to failed expectation instead of error
+
+
+### Bug fixes
+
+ * Basic authentication now works correctly
+ * Fixed problem where WebMock didn't call a block with the response when block was provided
+ * Fixed problem where uris with single slash were not matching uris without path provided
+
+
+## 0.7.3
+
+ * Clarified documentation
+ * Fixed some issues with loading of Webmock classes
+ * Test::Unit and RSpec adapters have to be required separately
+
+
+## 0.7.2
+
+ * Added support for matching escaped and non escaped URLs
View
90 README.md
@@ -63,10 +63,22 @@ You can also use WebMock without RSpec or Test::Unit support:
http.request(req, "abc")
} # ===> Success
+### Matching request body and headers against regular expressions
+
+ stub_request(:post, "www.example.com").
+ with(:body => /^.*world$/, :headers => {"Content-Type" => /image\/.+/}).to_return(:body => "abc")
+
+ uri = URI.parse('http://www.example.com/')
+ req = Net::HTTP::Post.new(uri.path)
+ req['Content-Type'] = 'image/png'
+ res = Net::HTTP.start(uri.host, uri.port) {|http|
+ http.request(req, 'hello world')
+ } # ===> Success
+
### Matching custom request headers
stub_request(:any, "www.example.com").
- with( :headers=>{ 'Header-Name' => 'Header-Value' } ).to_return(:body => "abc", :status => 200)
+ with(:headers=>{ 'Header-Name' => 'Header-Value' }).to_return(:body => "abc", :status => 200)
uri = URI.parse('http://www.example.com/')
req = Net::HTTP::Post.new(uri.path)
@@ -75,6 +87,27 @@ You can also use WebMock without RSpec or Test::Unit support:
http.request(req, 'abc')
} # ===> Success
+### Matching requests against provided block
+
+ stub_request(:post, "www.example.com").with { |request| request.body == "abc" }.to_return(:body => "abc")
+ RestClient.post('www.example.com', 'abc') # ===> "abc\n"
+
+### Request with basic authentication
+
+ stub_request(:get, "user:pass@www.example.com")
+
+ Net::HTTP.start('www.example.com') {|http|
+ req = Net::HTTP::Get.new('/')
+ req.basic_auth 'user', 'pass'
+ http.request(req)
+ } # ===> Success
+
+### Matching uris using regular expressions
+
+ stub_request(:any, /.*example.*/)
+
+ Net::HTTP.get('www.example.com', '/') # ===> Success
+
### Stubbing with custom response
stub_request(:any, "www.example.com").to_return(:body => "abc", :status => 200, :headers => { 'Content-Length' => 3 } )
@@ -88,6 +121,19 @@ You can also use WebMock without RSpec or Test::Unit support:
stub_request(:any, "www.example.com").to_return(:body => File.new('/tmp/response_body.txt'), :status => 200)
Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
+
+### Replaying raw responses recorded with `curl -is`
+
+ `curl -is www.example.com > /tmp/example_curl_-is_output.txt`
+ raw_response_file = File.new("/tmp/example_curl_-is_output.txt")
+
+ from file
+
+ stub_request(:get, "www.example.com").to_return(raw_response_file)
+
+ or string
+
+ stub_request(:get, "www.example.com").to_return(raw_response_file.read)
### Custom response with dynamically evaluated response
@@ -96,21 +142,36 @@ You can also use WebMock without RSpec or Test::Unit support:
RestClient.post('www.example.net', 'abc') # ===> "abc\n"
-### Request with basic authentication
+### Multiple responses for repeated requests
- stub_request(:get, "user:pass@www.example.com")
+ stub_request(:get, "www.example.com").to_return({:body => "abc"}, {:body => "def"})
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
+
+ #after all responses are used the last response will be returned infinitely
+
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
- Net::HTTP.start('www.example.com') {|http|
- req = Net::HTTP::Get.new('/')
- req.basic_auth 'user', 'pass'
- http.request(req)
- } # ===> Success
+### Multiple responses using chained `to_return()` or `to_raise()` declarations
-### Matching uris using regular expressions
+ stub_request(:get, "www.example.com").
+ to_return({:body => "abc"}).then. #then() just is a syntactic sugar
+ to_return({:body => "def"}).then.
+ to_raise(MyException)
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
+ Net::HTTP.get('www.example.com', '/') # ===> MyException raised
- stub_request(:any, /.*example.*/)
+### Specifying number of times given response should be returned
+
+ stub_request(:get, "www.example.com").
+ to_return({:body => "abc"}).times(2).then.
+ to_return({:body => "def"})
+
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
+ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
+ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
- Net::HTTP.get('www.example.com', '/') # ===> Success
### Real requests to network can be allowed or disabled
@@ -146,6 +207,8 @@ You can also use WebMock without RSpec or Test::Unit support:
assert_not_requested :get, "http://www.something.com" # ===> Success
+ assert_requested(:post, "http://www.example.com", :times => 1) { |req| req.body == "abc" }
+
### Expecting real (not stubbed) requests
WebMock.allow_net_connect!
@@ -163,6 +226,8 @@ You can also use WebMock without RSpec or Test::Unit support:
WebMock.should have_requested(:get, "www.example.com").with(:body => "abc", :headers => {'Content-Length' => 3}).twice
WebMock.should_not have_requested(:get, "www.something.com")
+
+ WebMock.should have_requested(:post, "www.example.com").with { |req| req.body == "abc" }
### Different way of setting expectations in RSpec
@@ -172,7 +237,8 @@ You can also use WebMock without RSpec or Test::Unit support:
request(:any, "www.example.com").should_not have_been_made
-
+ request(:post, "www.example.com").with { |req| req.body == "abc" }.should have_been_made
+
## Clearing stubs and request history
If you want to reset all current stubs and history of requests use `WebMock.reset_webmock`

0 comments on commit 5313e02

Please sign in to comment.
Something went wrong with that request. Please try again.