Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Indent files correctly and remove trailing whitespace

This makes it much easier moving using motions and editing files in a
number of editors.
  • Loading branch information...
commit a251cb3657cd2032c8c03f02108a1bce9113e72b 1 parent b986955
James Conroy-Finn jcf authored
Showing with 399 additions and 397 deletions.
  1. +118 −118 CHANGELOG.md
  2. +1 −1  Gemfile
  3. +1 −1  LICENSE
  4. +3 −3 lib/webmock/api.rb
  5. +1 −1  lib/webmock/assertion_failure.rb
  6. +1 −1  lib/webmock/callback_registry.rb
  7. +2 −2 lib/webmock/config.rb
  8. +1 −1  lib/webmock/cucumber.rb
  9. +2 −2 lib/webmock/errors.rb
  10. +9 −9 lib/webmock/http_lib_adapters/curb.rb
  11. +6 −6 lib/webmock/http_lib_adapters/httpclient.rb
  12. +4 −4 lib/webmock/http_lib_adapters/net_http.rb
  13. +2 −2 lib/webmock/http_lib_adapters/net_http_response.rb
  14. +3 −3 lib/webmock/http_lib_adapters/patron.rb
  15. +1 −1  lib/webmock/request_pattern.rb
  16. +2 −2 lib/webmock/request_stub.rb
  17. +2 −2 lib/webmock/responses_sequence.rb
  18. +2 −2 lib/webmock/rspec.rb
  19. +4 −4 lib/webmock/rspec/matchers.rb
  20. +1 −1  lib/webmock/rspec/matchers/webmock_matcher.rb
  21. +1 −1  lib/webmock/stub_registry.rb
  22. +4 −4 lib/webmock/util/hash_keys_stringifier.rb
  23. +3 −3 lib/webmock/util/headers.rb
  24. +1 −1  lib/webmock/util/uri.rb
  25. +2 −2 lib/webmock/webmock.rb
  26. +7 −7 spec/curb_spec.rb
  27. +2 −2 spec/curb_spec_helper.rb
  28. +9 −9 spec/em_http_request_spec_helper.rb
  29. +3 −3 spec/errors_spec.rb
  30. +22 −22 spec/example_curl_output.txt
  31. +1 −1  spec/httpclient_spec.rb
  32. +3 −3 spec/httpclient_spec_helper.rb
  33. +6 −6 spec/net_http_spec_helper.rb
  34. +1 −1  spec/network_connection.rb
  35. +2 −2 spec/patron_spec_helper.rb
  36. +8 −8 spec/request_execution_verifier_spec.rb
  37. +3 −3 spec/request_pattern_spec.rb
  38. +19 −19 spec/request_stub_spec.rb
  39. +8 −8 spec/response_spec.rb
  40. +2 −2 spec/spec_helper.rb
  41. +7 −7 spec/stub_request_snippet_spec.rb
  42. +5 −5 spec/util/headers_spec.rb
  43. +1 −1  spec/util/uri_spec.rb
  44. +1 −0  spec/vendor/addressable/lib/uri.rb
  45. +1 −0  spec/vendor/crack/lib/crack.rb
  46. +4 −4 spec/vendor/right_http_connection-1.2.4/History.txt
  47. +4 −4 spec/vendor/right_http_connection-1.2.4/README.txt
  48. +3 −3 spec/vendor/right_http_connection-1.2.4/Rakefile
  49. +4 −4 spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb
  50. +4 −4 spec/vendor/right_http_connection-1.2.4/setup.rb
  51. +92 −92 spec/webmock_shared.rb
236 CHANGELOG.md
View
@@ -52,9 +52,9 @@ josevalim:
* Simplified integration with Test::Unit, RSpec and Cucumber. Now only a single file has to be required i.e.
- require 'webmock/test_unit'
- require 'webmock/rspec'
- require 'webmock/cucumber'
+ require 'webmock/test_unit'
+ require 'webmock/rspec'
+ require 'webmock/cucumber'
* The error message on unstubbed request now contains code snippet which can be used to stub this request. Thanks to Martyn Loughran for suggesting this feature.
@@ -66,12 +66,12 @@ josevalim:
This technique is borrowed from em-http-request native mocking module. It allows switching WebMock adapter on an off, and using it interchangeably with em-http-request native mocking i.e:
- EventMachine::WebMockHttpRequest.activate!
- EventMachine::WebMockHttpRequest.deactivate!
+ EventMachine::WebMockHttpRequest.activate!
+ EventMachine::WebMockHttpRequest.deactivate!
- Thanks to Martyn Loughran for suggesting this feature.
-
-* `WebMock.reset_webmock` is deprecated in favour of new `WebMock.reset!`
+ Thanks to Martyn Loughran for suggesting this feature.
+
+* `WebMock.reset_webmock` is deprecated in favour of new `WebMock.reset!`
* Fixed integration with Cucumber. Previously documented example didn't work with new versions of Cucumber.
@@ -88,12 +88,12 @@ josevalim:
* Support for dynamically evaluated raw responses recorded with `curl -is` <br/>
i.e.
- `curl -is www.example.com > /tmp/www.example.com.txt`
- stub_request(:get, "www.example.com").to_return(lambda { |request| File.new("/tmp/#{request.uri.host.to_s}.txt" }))
+ `curl -is www.example.com > /tmp/www.example.com.txt`
+ stub_request(:get, "www.example.com").to_return(lambda { |request| File.new("/tmp/#{request.uri.host.to_s}.txt" }))
* `:net_http_connect_on_start` option can be passed to `WebMock.allow_net_connect!` and `WebMock.disable_net_connect!` methods, i.e.
- WebMock.allow_net_connect!(:net_http_connect_on_start => true)
+ WebMock.allow_net_connect!(:net_http_connect_on_start => true)
This forces WebMock Net::HTTP adapter to always connect on `Net::HTTP.start`. Check 'Connecting on Net::HTTP.start' in README for more information.
@@ -112,7 +112,7 @@ josevalim:
* `include WebMock` is now deprecated to avoid method and constant name conflicts. Please `include WebMock::API` instead.
-* `WebMock::API#request` is renamed to `WebMock::API#a_request` to prevent method name conflicts with i.e. Rails controller specs.
+* `WebMock::API#request` is renamed to `WebMock::API#a_request` to prevent method name conflicts with i.e. Rails controller specs.
WebMock.request is still available.
* Deprecated `WebMock#request`, `WebMock#allow_net_connect!`, `WebMock#net_connect_allowed?`, `WebMock#registered_request?`, `WebMock#reset_callbacks`, `WebMock#after_request` instance methods. These methods are still available, but only as WebMock class methods.
@@ -135,11 +135,11 @@ josevalim:
This feature was available before only for localhost with `:allow_localhost => true`
- WebMock.disable_net_connect!(:allow => "www.example.org")
+ WebMock.disable_net_connect!(:allow => "www.example.org")
- Net::HTTP.get('www.something.com', '/') # ===> Failure
+ Net::HTTP.get('www.something.com', '/') # ===> Failure
- Net::HTTP.get('www.example.org', '/') # ===> Allowed.
+ Net::HTTP.get('www.example.org', '/') # ===> Allowed.
* Fixed Net::HTTP adapter so that it preserves the original behavior of Net::HTTP.
@@ -169,53 +169,53 @@ josevalim:
* Added support for [em-http-request](http://github.com/igrigorik/em-http-request)
-* Matching query params using a hash
+* Matching query params using a hash
+
+ stub_http_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]})
+
+ RestClient.get("http://www.example.com/?a[]=b&a[]=c") # ===> Success
- stub_http_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]})
-
- RestClient.get("http://www.example.com/?a[]=b&a[]=c") # ===> Success
-
- request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).should have_been_made # ===> Success
+ request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).should have_been_made # ===> Success
* Matching request body against a hash. Body can be URL-Encoded, JSON or XML.
(Thanks to Steve Tooke for the idea and a solution for url-encoded bodies)
- stub_http_request(:post, "www.example.com").
- with(:body => {:data => {:a => '1', :b => 'five'}})
-
- RestClient.post('www.example.com', "data[a]=1&data[b]=five",
- :content_type => 'application/x-www-form-urlencoded') # ===> Success
-
- RestClient.post('www.example.com', '{"data":{"a":"1","b":"five"}}',
- :content_type => 'application/json') # ===> Success
-
- RestClient.post('www.example.com', '<data a="1" b="five" />',
- :content_type => 'application/xml' ) # ===> Success
-
- request(:post, "www.example.com").
- with(:body => {:data => {:a => '1', :b => 'five'}},
- :headers => 'Content-Type' => 'application/json').should have_been_made # ===> Success
+ stub_http_request(:post, "www.example.com").
+ with(:body => {:data => {:a => '1', :b => 'five'}})
+
+ RestClient.post('www.example.com', "data[a]=1&data[b]=five",
+ :content_type => 'application/x-www-form-urlencoded') # ===> Success
+
+ RestClient.post('www.example.com', '{"data":{"a":"1","b":"five"}}',
+ :content_type => 'application/json') # ===> Success
+
+ RestClient.post('www.example.com', '<data a="1" b="five" />',
+ :content_type => 'application/xml' ) # ===> Success
+
+ request(:post, "www.example.com").
+ with(:body => {:data => {:a => '1', :b => 'five'}},
+ :headers => 'Content-Type' => 'application/json').should have_been_made # ===> Success
* Request callbacks (Thanks to Myron Marston for all suggestions)
WebMock can now invoke callbacks for stubbed or real requests:
- WebMock.after_request do |request_signature, response|
- puts "Request #{request_signature} was made and #{response} was returned"
- end
-
+ WebMock.after_request do |request_signature, response|
+ puts "Request #{request_signature} was made and #{response} was returned"
+ end
+
invoke callbacks for real requests only and except requests made with Patron client
- WebMock.after_request(:except => [:patron], :real_requests_only => true) do |request_signature, response|
- puts "Request #{request_signature} was made and #{response} was returned"
- end
+ WebMock.after_request(:except => [:patron], :real_requests_only => true) do |request_signature, response|
+ puts "Request #{request_signature} was made and #{response} was returned"
+ end
* `to_raise()` now accepts an exception instance or a string as argument in addition to an exception class
- stub_request(:any, 'www.example.net').to_raise(StandardError.new("some error"))
-
- stub_request(:any, 'www.example.net').to_raise("some error")
+ stub_request(:any, 'www.example.net').to_raise(StandardError.new("some error"))
+
+ stub_request(:any, 'www.example.net').to_raise("some error")
* Matching requests based on a URI is 30% faster
@@ -231,7 +231,7 @@ josevalim:
* Fixed gemspec file. Thanks to Razic
-## 1.2.0
+## 1.2.0
* RSpec 2 compatibility. Thanks to Sam Phillips!
@@ -243,14 +243,14 @@ josevalim:
## 1.1.0
* [VCR](http://github.com/myronmarston/vcr/) compatibility. Many thanks to Myron Marston for all suggestions.
-
-* Support for stubbing requests and returning responses with multiple headers with the same name. i.e multiple Accept headers.
- stub_http_request(:get, 'www.example.com').
- with(:headers => {'Accept' => ['image/png', 'image/jpeg']}).
- to_return(:body => 'abc')
- RestClient.get('www.example.com',
- {"Accept" => ['image/png', 'image/jpeg']}) # ===> "abc\n"
+* Support for stubbing requests and returning responses with multiple headers with the same name. i.e multiple Accept headers.
+
+ stub_http_request(:get, 'www.example.com').
+ with(:headers => {'Accept' => ['image/png', 'image/jpeg']}).
+ to_return(:body => 'abc')
+ RestClient.get('www.example.com',
+ {"Accept" => ['image/png', 'image/jpeg']}) # ===> "abc\n"
* When real net connections are disabled and unstubbed request is made, WebMock throws WebMock::NetConnectNotAllowedError instead of assertion error or StandardError.
@@ -263,38 +263,38 @@ josevalim:
* Responses dynamically evaluated from block (idea and implementation by Tom Ward)
- stub_request(:any, 'www.example.net').
- to_return { |request| {:body => request.body} }
+ stub_request(:any, 'www.example.net').
+ to_return { |request| {:body => request.body} }
- RestClient.post('www.example.net', 'abc') # ===> "abc\n"
+ RestClient.post('www.example.net', 'abc') # ===> "abc\n"
* Responses dynamically evaluated from lambda (idea and implementation by Tom Ward)
- stub_request(:any, 'www.example.net').
- to_return(lambda { |request| {:body => request.body} })
+ stub_request(:any, 'www.example.net').
+ to_return(lambda { |request| {:body => request.body} })
- RestClient.post('www.example.net', 'abc') # ===> "abc\n"
+ RestClient.post('www.example.net', 'abc') # ===> "abc\n"
-* Response with custom status message
+* Response with custom status message
- stub_request(:any, "www.example.com").to_return(:status => [500, "Internal Server Error"])
+ stub_request(:any, "www.example.com").to_return(:status => [500, "Internal Server Error"])
- req = Net::HTTP::Get.new("/")
- Net::HTTP.start("www.example.com") { |http| http.request(req) }.message # ===> "Internal Server Error"
+ req = Net::HTTP::Get.new("/")
+ Net::HTTP.start("www.example.com") { |http| http.request(req) }.message # ===> "Internal Server Error"
* Raising timeout errors (suggested by Jeffrey Jones) (compatibility with Ruby 1.8.6 by Mack Earnhardt)
- stub_request(:any, 'www.example.net').to_timeout
+ stub_request(:any, 'www.example.net').to_timeout
- RestClient.post('www.example.net', 'abc') # ===> RestClient::RequestTimeout
+ RestClient.post('www.example.net', 'abc') # ===> RestClient::RequestTimeout
* External requests can be disabled while allowing localhost (idea and implementation by Mack Earnhardt)
- WebMock.disable_net_connect!(:allow_localhost => true)
+ WebMock.disable_net_connect!(:allow_localhost => true)
- Net::HTTP.get('www.something.com', '/') # ===> Failure
+ Net::HTTP.get('www.something.com', '/') # ===> Failure
- Net::HTTP.get('localhost:9887', '/') # ===> Allowed. Perhaps to Selenium?
+ Net::HTTP.get('localhost:9887', '/') # ===> Allowed. Perhaps to Selenium?
### Bug fixes
@@ -307,82 +307,82 @@ josevalim:
* Fixed issue where response status code was not read from raw (curl -is) responses
## 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" }
+ 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 (suggested by Ben Pickles)
- stub_request(:post, "www.example.com").with(:body => /^.*world$/).to_return(:body => "abc")
- RestClient.post('www.example.com', 'hello world') # ===> "abc\n"
-
+ 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 (suggested by Ben Pickles)
- 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"
+ 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)
+ `curl -is www.example.com > /tmp/example_curl_-is_output.txt`
+ raw_response_file = File.new("/tmp/example_curl_-is_output.txt")
- or string
-
- stub_request(:get, "www.example.com").to_return(raw_response_file.read)
+ 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"
+ 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
-
+ 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"
-
+ 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
-
+ 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
-
-
-
+ 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)
@@ -394,8 +394,8 @@ josevalim:
## 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 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
2  Gemfile
View
@@ -9,4 +9,4 @@ end
platforms :jruby do
gem 'jruby-openssl', '~> 0.7'
-end
+end
2  LICENSE
View
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 lib/webmock/api.rb
View
@@ -1,7 +1,7 @@
module WebMock
module API
extend self
-
+
def stub_request(method, uri)
WebMock::StubRegistry.instance.register_request_stub(WebMock::RequestStub.new(method, uri))
end
@@ -11,7 +11,7 @@ def stub_request(method, uri)
def a_request(method, uri)
WebMock::RequestPattern.new(method, uri)
end
-
+
class << self
alias :request :a_request
end
@@ -29,4 +29,4 @@ def assert_not_requested(method, uri, options = {}, &block)
WebMock::AssertionFailure.failure(verifier.negative_failure_message) unless verifier.does_not_match?
end
end
-end
+end
2  lib/webmock/assertion_failure.rb
View
@@ -8,4 +8,4 @@ def failure(message)
end
end
end
-end
+end
2  lib/webmock/callback_registry.rb
View
@@ -26,7 +26,7 @@ def self.invoke_callbacks(options, request_signature, response)
def self.reset
@@callbacks = []
end
-
+
def self.any_callbacks?
!@@callbacks.empty?
end
4 lib/webmock/config.rb
View
@@ -1,7 +1,7 @@
module WebMock
- class Config
+ class Config
include Singleton
-
+
attr_accessor :allow_net_connect
attr_accessor :allow_localhost
attr_accessor :allow
2  lib/webmock/cucumber.rb
View
@@ -5,4 +5,4 @@
After do
WebMock.reset!
-end
+end
4 lib/webmock/errors.rb
View
@@ -1,5 +1,5 @@
module WebMock
-
+
class NetConnectNotAllowedError < StandardError
def initialize(request_signature)
text = "Real HTTP connections are disabled. Unregistered request: #{request_signature}"
@@ -18,4 +18,4 @@ def stubbing_instructions(request_signature)
end
end
-end
+end
18 lib/webmock/http_lib_adapters/curb.rb
View
@@ -19,7 +19,7 @@ def curb_or_webmock
webmock_response = build_webmock_response
WebMock::CallbackRegistry.invoke_callbacks(
{:lib => :curb, :real_request => true}, request_signature,
- webmock_response)
+ webmock_response)
end
res
else
@@ -54,15 +54,15 @@ def build_request_signature
end
def build_curb_response(webmock_response)
- raise Curl::Err::TimeoutError if webmock_response.should_timeout
+ raise Curl::Err::TimeoutError if webmock_response.should_timeout
webmock_response.raise_error_if_any
-
+
@body_str = webmock_response.body
@response_code = webmock_response.status[0]
@header_str = "HTTP/1.1 #{webmock_response.status[0]} #{webmock_response.status[1]}\r\n"
if webmock_response.headers
- @header_str << webmock_response.headers.map do |k,v|
+ @header_str << webmock_response.headers.map do |k,v|
"#{k}: #{v.is_a?(Array) ? v.join(", ") : v}"
end.join("\r\n")
@@ -115,7 +115,7 @@ def build_webmock_response
###
### Mocks of Curl::Easy methods below here.
- ###
+ ###
def http_with_webmock(method)
@webmock_method = method
@@ -163,11 +163,11 @@ def perform_with_webmock
@webmock_method ||= :get
curb_or_webmock do
perform_without_webmock
- end
+ end
end
alias :perform_without_webmock :perform
alias :perform :perform_with_webmock
-
+
def put_data_with_webmock= data
@webmock_method = :put
@put_data = data
@@ -175,7 +175,7 @@ def put_data_with_webmock= data
end
alias_method :put_data_without_webmock=, :put_data=
alias_method :put_data=, :put_data_with_webmock=
-
+
def post_body_with_webmock= data
@webmock_method = :post
self.post_body_without_webmock = data
@@ -261,7 +261,7 @@ def self.http_#{verb}(url, data, &block)
end
METHOD
end
-
+
module WebmockHelper
# Borrowed from Patron:
# http://github.com/toland/patron/blob/master/lib/patron/response.rb
12 lib/webmock/http_lib_adapters/httpclient.rb
View
@@ -20,7 +20,7 @@ def do_get_with_webmock(req, proxy, conn, stream = false, &block)
response = build_httpclient_response(webmock_response, stream, &block)
res = conn.push(response)
WebMock::CallbackRegistry.invoke_callbacks(
- {:lib => :http_client}, request_signature, webmock_response)
+ {:lib => :http_client}, request_signature, webmock_response)
res
elsif WebMock.net_connect_allowed?(request_signature.uri)
res = if stream
@@ -45,7 +45,7 @@ def do_get_with_webmock(req, proxy, conn, stream = false, &block)
def do_request_async_with_webmock(method, uri, query, body, extheader)
req = create_request(method, uri, query, body, extheader)
request_signature = build_request_signature(req)
-
+
if WebMock::StubRegistry.instance.registered_request?(request_signature) ||
WebMock.net_connect_allowed?(request_signature.uri)
do_request_async_without_webmock(method, uri, query, body, extheader)
@@ -70,7 +70,7 @@ def build_httpclient_response(webmock_response, stream = false, &block)
response.reason=webmock_response.status[1]
webmock_response.headers.to_a.each { |name, value| response.header.set(name, value) }
- raise HTTPClient::TimeoutError if webmock_response.should_timeout
+ raise HTTPClient::TimeoutError if webmock_response.should_timeout
webmock_response.raise_error_if_any
block.call(nil, body) if block
@@ -78,7 +78,7 @@ def build_httpclient_response(webmock_response, stream = false, &block)
response
end
end
-
+
def build_webmock_response(httpclient_response)
webmock_response = WebMock::Response.new
webmock_response.status = [httpclient_response.status, httpclient_response.reason]
@@ -102,8 +102,8 @@ def build_request_signature(req)
auth = www_auth.basic_auth
auth.challenge(req.header.request_uri, nil)
-
- headers = req.header.all.inject({}) do |headers, header|
+
+ headers = req.header.all.inject({}) do |headers, header|
headers[header[0]] ||= [];
headers[header[0]] << header[1]
headers
8 lib/webmock/http_lib_adapters/net_http.rb
View
@@ -92,12 +92,12 @@ def connect_with_webmock
def build_net_http_response(webmock_response, &block)
response = Net::HTTPResponse.send(:response_class, webmock_response.status[0].to_s).new("1.0", webmock_response.status[0].to_s, webmock_response.status[1])
response.instance_variable_set(:@body, webmock_response.body)
- webmock_response.headers.to_a.each do |name, values|
+ webmock_response.headers.to_a.each do |name, values|
values = [values] unless values.is_a?(Array)
values.each do |value|
response.add_field(name, value)
end
- end
+ end
response.instance_variable_set(:@read, true)
@@ -111,14 +111,14 @@ def build_net_http_response(webmock_response, &block)
response
end
-
+
def build_webmock_response(net_http_response)
webmock_response = WebMock::Response.new
webmock_response.status = [
net_http_response.code.to_i,
net_http_response.message]
webmock_response.headers = net_http_response.to_hash
- webmock_response.body = net_http_response.body
+ webmock_response.body = net_http_response.body
webmock_response
end
4 lib/webmock/http_lib_adapters/net_http_response.rb
View
@@ -1,4 +1,4 @@
-# This code is entierly copied from VCR (http://github.com/myronmarston/vcr) by courtesy of Myron Marston
+# This code is entierly copied from VCR (http://github.com/myronmarston/vcr) by courtesy of Myron Marston
# A Net::HTTP response that has already been read raises an IOError when #read_body
# is called with a destination string or block.
@@ -29,4 +29,4 @@ def read_body(dest = nil, &block)
end
end
end
-end
+end
6 lib/webmock/http_lib_adapters/patron.rb
View
@@ -21,7 +21,7 @@ def handle_request_with_webmock(req)
webmock_response = build_webmock_response(res)
WebMock::CallbackRegistry.invoke_callbacks(
{:lib => :patron, :real_request => true}, request_signature,
- webmock_response)
+ webmock_response)
end
res
else
@@ -75,7 +75,7 @@ def build_request_signature(req)
end
def build_patron_response(webmock_response)
- raise Patron::TimeoutError if webmock_response.should_timeout
+ raise Patron::TimeoutError if webmock_response.should_timeout
webmock_response.raise_error_if_any
res = Patron::Response.new
res.instance_variable_set(:@body, webmock_response.body)
@@ -84,7 +84,7 @@ def build_patron_response(webmock_response)
res.instance_variable_set(:@headers, webmock_response.headers)
res
end
-
+
def build_webmock_response(patron_response)
webmock_response = WebMock::Response.new
reason = patron_response.status_line.scan(%r(\AHTTP/(\d+\.\d+)\s+(\d\d\d)\s*([^\r\n]+)?\r?\z))[0][2]
2  lib/webmock/request_pattern.rb
View
@@ -40,7 +40,7 @@ def assign_options(options)
@headers_pattern = HeadersPattern.new(options[:headers]) if options.has_key?(:headers)
@uri_pattern.add_query_params(options[:query]) if options.has_key?(:query)
end
-
+
def create_uri_pattern(uri)
if uri.is_a?(Regexp)
URIRegexpPattern.new(uri)
4 lib/webmock/request_stub.rb
View
@@ -24,12 +24,12 @@ def to_return(*response_hashes, &block)
end
def to_raise(*exceptions)
- @responses_sequences << ResponsesSequence.new([*exceptions].flatten.map {|e|
+ @responses_sequences << ResponsesSequence.new([*exceptions].flatten.map {|e|
ResponseFactory.response_for(:exception => e)
})
self
end
-
+
def to_timeout
@responses_sequences << ResponsesSequence.new([ResponseFactory.response_for(:should_timeout => true)])
self
4 lib/webmock/responses_sequence.rb
View
@@ -1,5 +1,5 @@
module WebMock
-
+
class ResponsesSequence
attr_accessor :times_to_repeat
@@ -36,5 +36,5 @@ def increase_position
end
end
-
+
end
4 lib/webmock/rspec.rb
View
@@ -6,7 +6,7 @@
elsif defined?(Spec)
RSPEC_NAMESPACE = Spec
RSPEC_CONFIGURER = Spec::Runner
-else
+else
begin
require 'rspec/core'
require 'rspec/expectations'
@@ -19,7 +19,7 @@
end
require 'webmock/rspec/matchers'
-
+
RSPEC_CONFIGURER.configure { |config|
config.include WebMock::API
8 lib/webmock/rspec/matchers.rb
View
@@ -7,17 +7,17 @@ module Matchers
def have_been_made
WebMock::RequestPatternMatcher.new
end
-
+
def have_not_been_made
WebMock::RequestPatternMatcher.new.times(0)
end
-
+
def have_requested(method, uri)
WebMock::WebMockMatcher.new(method, uri)
end
-
+
def have_not_requested(method, uri)
WebMock::WebMockMatcher.new(method, uri).times(0)
end
end
-end
+end
2  lib/webmock/rspec/matchers/webmock_matcher.rb
View
@@ -29,7 +29,7 @@ def times(times)
def matches?(webmock)
@request_execution_verifier.matches?
end
-
+
def does_not_match?(webmock)
@request_execution_verifier.does_not_match?
end
2  lib/webmock/stub_registry.rb
View
@@ -40,4 +40,4 @@ def evaluate_response_for_request(response, request_signature)
end
end
-end
+end
8 lib/webmock/util/hash_keys_stringifier.rb
View
@@ -1,14 +1,14 @@
module WebMock
module Util
class HashKeysStringifier
-
+
def self.stringify_keys!(arg)
case arg
when Array
arg.map { |elem| stringify_keys!(elem) }
when Hash
Hash[
- *arg.map { |key, value|
+ *arg.map { |key, value|
k = key.is_a?(Symbol) ? key.to_s : key
v = stringify_keys!(value)
[k,v]
@@ -17,7 +17,7 @@ def self.stringify_keys!(arg)
arg
end
end
-
+
end
end
-end
+end
6 lib/webmock/util/headers.rb
View
@@ -26,12 +26,12 @@ def self.sorted_headers_string(headers)
when Regexp then v.inspect
when Array then "["+v.map{|v| "'#{v.to_s}'"}.join(", ")+"]"
else "'#{v.to_s}'"
- end
+ end
"'#{k}'=>#{v}"
- end.sort.join(", ")
+ end.sort.join(", ")
str << '}'
end
-
+
def self.decode_userinfo_from_header(header)
header.sub(/^Basic /, "").unpack("m").first
end
2  lib/webmock/util/uri.rb
View
@@ -67,7 +67,7 @@ def self.encode_unsafe_chars_in_userinfo(userinfo)
end
def self.is_uri_localhost?(uri)
- uri.is_a?(Addressable::URI) &&
+ uri.is_a?(Addressable::URI) &&
%w(localhost 127.0.0.1 0.0.0.0).include?(uri.host)
end
4 lib/webmock/webmock.rb
View
@@ -50,12 +50,12 @@ def self.reset!
WebMock::RequestRegistry.instance.reset!
WebMock::StubRegistry.instance.reset!
end
-
+
def self.reset_webmock
WebMock::Deprecation.warning("WebMock.reset_webmock is deprecated. Please use WebMock.reset! method instead")
reset!
end
-
+
def self.reset_callbacks
WebMock::CallbackRegistry.reset
end
14 spec/curb_spec.rb
View
@@ -6,7 +6,7 @@
shared_examples_for "Curb" do
include CurbSpecHelper
-
+
it_should_behave_like "WebMock"
describe "when doing PUTs" do
@@ -35,7 +35,7 @@
stub_request(:any, "example.com").to_return(:body => body)
test = nil
- @curl.on_success do |c|
+ @curl.on_success do |c|
test = c.body_str
end
@curl.http_get
@@ -48,7 +48,7 @@
to_return(:status => [response_code, "Server On Fire"])
test = nil
- @curl.on_failure do |c, code|
+ @curl.on_failure do |c, code|
test = code
end
@curl.http_get
@@ -61,19 +61,19 @@
to_return(:body => body)
test = nil
- @curl.on_body do |data|
+ @curl.on_body do |data|
test = data
end
@curl.http_get
test.should == body
end
-
+
it "should call on_header when response headers are read" do
stub_request(:any, "example.com").
to_return(:headers => {:one => 1})
test = nil
- @curl.on_header do |data|
+ @curl.on_header do |data|
test = data
end
@curl.http_get
@@ -217,7 +217,7 @@
end
end
end
-
+
describe "#content_type" do
before(:each) do
@curl = Curl::Easy.new
4 spec/curb_spec_helper.rb
View
@@ -17,7 +17,7 @@ def http_request(method, uri, options = {}, &block)
def setup_request(uri, curl, options={})
curl ||= Curl::Easy.new
- curl.url = uri.omit(:userinfo).to_s
+ curl.url = uri.omit(:userinfo).to_s
curl.username = uri.user
curl.password = uri.password
curl.timeout = 10
@@ -54,7 +54,7 @@ def curb_http_request(uri, method, body, options)
curl.post_body = body
when :put
curl.put_data = body
- end
+ end
curl.http(method)
curl
18 spec/em_http_request_spec_helper.rb
View
@@ -12,23 +12,23 @@ def http_request(method, uri, options = {}, &block)
EventMachine.run {
request = EventMachine::HttpRequest.new("#{uri.omit(:userinfo).normalize.to_s}")
http = request.send(:setup_request, method, {
- :timeout => 10,
+ :timeout => 10,
:body => options[:body],
:query => options[:query],
'authorization' => [uri.user, uri.password],
:head => options[:headers]}, &block)
http.errback {
error = if http.respond_to?(:errors)
- http.errors
+ http.errors
else
http.error
- end
- failed
+ end
+ failed
}
- http.callback {
+ http.callback {
response = OpenStruct.new({
:body => http.response,
- :headers => WebMock::Util::Headers.normalize_headers(extract_response_headers(http)),
+ :headers => WebMock::Util::Headers.normalize_headers(extract_response_headers(http)),
:message => http.response_header.http_reason,
:status => http.response_header.status.to_s
})
@@ -53,15 +53,15 @@ def setup_expectations_for_real_request(options = {})
def http_library
:em_http_request
end
-
+
private
-
+
def extract_response_headers(http)
headers = {}
if http.response_header
http.response_header.each do |k,v|
v = v.join(", ") if v.is_a?(Array)
- headers[k] = v
+ headers[k] = v
end
end
headers
6 spec/errors_spec.rb
View
@@ -9,9 +9,9 @@
with(request_signature).and_return(mock(:to_s => "bbb"))
expected = "Real HTTP connections are disabled. Unregistered request: aaa" +
"\n\nYou can stub this request with the following snippet:\n\n" +
- "bbb\n\n============================================================"
- WebMock::NetConnectNotAllowedError.new(request_signature).message.should == expected
+ "bbb\n\n============================================================"
+ WebMock::NetConnectNotAllowedError.new(request_signature).message.should == expected
end
end
end
-end
+end
44 spec/example_curl_output.txt
View
@@ -1,22 +1,22 @@
-HTTP/1.1 202 OK
-Content-Type: text/html; charset=UTF-8
-Connection: Keep-Alive
-Date: Sat, 23 Jan 2010 01:01:05 GMT
-Content-Length: 438
-Accept: image/jpeg
-Accept: image/png
-
-<HTML>
-<HEAD>
- <TITLE>Example Web Page</TITLE>
-</HEAD>
-<body>
-<p>You have reached this web page by typing &quot;example.com&quot;,
-&quot;example.net&quot;,
- or &quot;example.org&quot; into your web browser.</p>
-<p>These domain names are reserved for use in documentation and are not available
- for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
- 2606</a>, Section 3.</p>
-</BODY>
-</HTML>
-
+HTTP/1.1 202 OK
+Content-Type: text/html; charset=UTF-8
+Connection: Keep-Alive
+Date: Sat, 23 Jan 2010 01:01:05 GMT
+Content-Length: 419
+Accept: image/jpeg
+Accept: image/png
+
+<HTML>
+<HEAD>
+ <TITLE>Example Web Page</TITLE>
+</HEAD>
+<body>
+<p>You have reached this web page by typing &quot;example.com&quot;,
+&quot;example.net&quot;,
+ or &quot;example.org&quot; into your web browser.</p>
+<p>These domain names are reserved for use in documentation and are not available
+ for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
+ 2606</a>, Section 3.</p>
+</BODY>
+</HTML>
+
2  spec/httpclient_spec.rb
View
@@ -28,7 +28,7 @@
:get, "http://www.example.com/",
:headers => {"a" => ["c", "b"]}).status.should == "200"
end
-
+
describe "async requests" do
6 spec/httpclient_spec_helper.rb
View
@@ -2,7 +2,7 @@ module HTTPClientSpecHelper
class << self
attr_accessor :async_mode
end
-
+
def http_request(method, uri, options = {}, &block)
uri = Addressable::URI.heuristic_parse(uri)
c = HTTPClient.new
@@ -17,7 +17,7 @@ def http_request(method, uri, options = {}, &block)
else
response = c.request(*params, &block)
end
- headers = response.header.all.inject({}) do |headers, header|
+ headers = response.header.all.inject({}) do |headers, header|
if !headers.has_key?(header[0])
headers[header[0]] = header[1]
else
@@ -75,7 +75,7 @@ def setup_expectations_for_real_request(options = {})
socket.stub!(:eof?).and_return(true)
socket.stub!(:close).and_return(true)
end
-
+
def http_library
:http_client
end
12 spec/net_http_spec_helper.rb
View
@@ -8,14 +8,14 @@ def http_request(method, uri, options = {}, &block)
response = nil
clazz = Net::HTTP.const_get("#{method.to_s.capitalize}")
req = clazz.new("#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", nil)
- options[:headers].each do |k,v|
+ options[:headers].each do |k,v|
if v.is_a?(Array)
v.each_with_index do |v,i|
i == 0 ? (req[k] = v) : req.add_field(k, v)
end
else
req[k] = v
- end
+ end
end if options[:headers]
req.basic_auth uri.user, uri.password if uri.user
@@ -34,11 +34,11 @@ def http_request(method, uri, options = {}, &block)
OpenStruct.new({
:body => response.body,
:headers => WebMock::Util::Headers.normalize_headers(headers),
- :status => response.code,
+ :status => response.code,
:message => response.message
})
end
-
+
def client_timeout_exception_class
Timeout::Error
end
@@ -71,12 +71,12 @@ def setup_expectations_for_real_request(options = {})
# Request/response handling
request_parts = ["#{options[:method]} #{options[:path]} HTTP/1.1", "Host: #{options[:host]}"]
socket.should_receive(:write).with(/#{request_parts[0]}.*#{request_parts[1]}.*/m).and_return(100)
-
+
read_method = RUBY_VERSION >= "1.9.2" ? :read_nonblock : :sysread
socket.should_receive(read_method).once.and_return("HTTP/1.1 #{options[:response_code]} #{options[:response_message]}\nContent-Length: #{options[:response_body].length}\n\n#{options[:response_body]}")
socket.should_receive(read_method).any_number_of_times.and_raise(EOFError)
end
-
+
def http_library
:net_http
end
2  spec/network_connection.rb
View
@@ -22,4 +22,4 @@ def self.is_network_available?
false
end
end
-end
+end
4 spec/patron_spec_helper.rb
View
@@ -11,7 +11,7 @@ def http_request(method, uri, options = {}, &block)
sess.connect_timeout = 10
sess.timeout = 10
sess.max_redirects = 0
-
+
response = sess.request(method, "#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", options[:headers] || {}, {
:data => options[:body]
})
@@ -19,7 +19,7 @@ def http_request(method, uri, options = {}, &block)
if response.headers
response.headers.each do |k,v|
v = v.join(", ") if v.is_a?(Array)
- headers[k] = v
+ headers[k] = v
end
end
OpenStruct.new({
16 spec/request_execution_verifier_spec.rb
View
@@ -17,7 +17,7 @@
@verifier.expected_times_executed = 2
expected_text = "The request www.example.com was expected to execute 2 times but it executed 0 times"
expected_text << @executed_requests_info
- @verifier.failure_message.should == expected_text
+ @verifier.failure_message.should == expected_text
end
it "should report failure message correctly when executed times is one" do
@@ -29,7 +29,7 @@
end
end
-
+
describe "negative failure message" do
it "should report failure message if it executed number of times specified" do
@@ -66,26 +66,26 @@
end
end
-
+
describe "does_not_match?" do
it "should fail if request executed expected number of times" do
WebMock::RequestRegistry.instance.
should_receive(:times_executed).with(@request_pattern).and_return(10)
@verifier.expected_times_executed = 10
- @verifier.does_not_match?.should be_false
+ @verifier.does_not_match?.should be_false
end
-
+
it "should succeed if request was not executed at all and expected number of times was not set" do
WebMock::RequestRegistry.instance.
should_receive(:times_executed).with(@request_pattern).and_return(0)
- @verifier.does_not_match?.should be_true
+ @verifier.does_not_match?.should be_true
end
-
+
it "should fail if request was executed and expected number of times was not set" do
WebMock::RequestRegistry.instance.
should_receive(:times_executed).with(@request_pattern).and_return(1)
- @verifier.does_not_match?.should be_false
+ @verifier.does_not_match?.should be_false
end
it "should succeed if request was not executed expected number of times" do
6 spec/request_pattern_spec.rb
View
@@ -13,7 +13,7 @@
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).with {|req| true}.to_s.should ==
"GET http://www.example.com/ with body \"abc\" with headers {'A'=>'a', 'B'=>'b'} with given block"
end
-
+
it "should report string describing itself with query params" do
WebMock::RequestPattern.new(:get, /.*example.*/, :query => {'a' => ['b', 'c']}).to_s.should ==
"GET /.*example.*/ with query params {\"a\"=>[\"b\", \"c\"]}"
@@ -140,12 +140,12 @@ def match(request_signature)
WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]}).
should match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
end
-
+
it "should not match for query params are different than the declared in hash" do
WebMock::RequestPattern.new(:get, "www.example.com", :query => {"a" => ["b", "c"]}).
should_not match(WebMock::RequestSignature.new(:get, "www.example.com?x[]=b&a[]=c"))
end
-
+
it "should match for query params are the same as declared as string" do
WebMock::RequestPattern.new(:get, "www.example.com", :query => "a[]=b&a[]=c").
should match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
38 spec/request_stub_spec.rb
View
@@ -23,7 +23,7 @@
it "should assign normalized headers to request pattern" do
@request_stub.with(:headers => {'A' => 'a'})
- @request_stub.request_pattern.to_s.should ==
+ @request_stub.request_pattern.to_s.should ==
WebMock::RequestPattern.new(:get, "www.example.com", :headers => {'A' => 'a'}).to_s
end
@@ -69,13 +69,13 @@
@request_stub.response
@request_stub.response.body.should == "def"
end
-
+
it "should return responses in a sequence passed as comma separated params" do
@request_stub.to_return({:body => "abc"}, {:body => "def"})
@request_stub.response.body.should == "abc"
@request_stub.response.body.should == "def"
end
-
+
it "should return responses declared in multiple to_return declarations" do
@request_stub.to_return({:body => "abc"}).to_return({:body => "def"})
@request_stub.response.body.should == "abc"
@@ -92,7 +92,7 @@
@request_stub.response.raise_error_if_any
}.should raise_error(ArgumentError, "Exception from WebMock")
end
-
+
it "should assign sequence of responses with response with exception to be thrown" do
@request_stub.to_return(:body => "abc").then.to_raise(ArgumentError)
@request_stub.response.body.should == "abc"
@@ -110,7 +110,7 @@
@request_stub.response.raise_error_if_any
}.should raise_error(IndexError, "Exception from WebMock")
end
-
+
it "should raise exceptions declared in multiple to_raise declarations" do
@request_stub.to_raise(ArgumentError).then.to_raise(IndexError)
lambda {
@@ -122,7 +122,7 @@
end
end
-
+
describe "to_timeout" do
it "should assign response with timeout" do
@@ -144,30 +144,30 @@
end
end
-
-
+
+
describe "times" do
-
+
it "should give error if declared before any response declaration is declared" do
lambda {
@request_stub.times(3)
- }.should raise_error("Invalid WebMock stub declaration. times(N) can be declared only after response declaration.")
+ }.should raise_error("Invalid WebMock stub declaration. times(N) can be declared only after response declaration.")
end
-
+
it "should repeat returning last declared response declared number of times" do
@request_stub.to_return({:body => "abc"}).times(2).then.to_return({:body => "def"})
@request_stub.response.body.should == "abc"
@request_stub.response.body.should == "abc"
@request_stub.response.body.should == "def"
end
-
+
it "should repeat raising last declared exception declared number of times" do
@request_stub.to_return({:body => "abc"}).times(2).then.to_return({:body => "def"})
@request_stub.response.body.should == "abc"
@request_stub.response.body.should == "abc"
@request_stub.response.body.should == "def"
end
-
+
it "should repeat returning last declared sequence of responses declared number of times" do
@request_stub.to_return({:body => "abc"}, {:body => "def"}).times(2).then.to_return({:body => "ghj"})
@request_stub.response.body.should == "abc"
@@ -176,23 +176,23 @@
@request_stub.response.body.should == "def"
@request_stub.response.body.should == "ghj"
end
-
+
it "should return self" do
@request_stub.to_return({:body => "abc"}).times(1).should == @request_stub
end
-
+
it "should raise error if argument is not integer" do
lambda {
@request_stub.to_return({:body => "abc"}).times("not number")
- }.should raise_error("times(N) accepts integers >= 1 only")
+ }.should raise_error("times(N) accepts integers >= 1 only")
end
-
+
it "should raise error if argument is < 1" do
lambda {
@request_stub.to_return({:body => "abc"}).times(0)
- }.should raise_error("times(N) accepts integers >= 1 only")
+ }.should raise_error("times(N) accepts integers >= 1 only")
end
-
+
end
end
16 spec/response_spec.rb
View
@@ -139,14 +139,14 @@
@response.headers.should == {
"Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
"Content-Type"=>"text/html; charset=UTF-8",
- "Content-Length"=>"438",
+ "Content-Length"=>"419",
"Connection"=>"Keep-Alive",
"Accept"=>"image/jpeg, image/png"
}
end
it "should read body" do
- @response.body.size.should == 438
+ @response.body.size.should == 419
end
it "should close IO" do
@@ -169,20 +169,20 @@
@response.headers.should == {
"Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
"Content-Type"=>"text/html; charset=UTF-8",
- "Content-Length"=>"438",
+ "Content-Length"=>"419",
"Connection"=>"Keep-Alive",
"Accept"=>"image/jpeg, image/png"
}
end
it "should read body" do
- @response.body.size.should == 438
+ @response.body.size.should == 419
end
it "should work with transfer-encoding set to chunked" do
- @input.gsub!("Content-Length: 438", "Transfer-Encoding: chunked")
+ @input.gsub!("Content-Length: 419", "Transfer-Encoding: chunked")
@response = WebMock::Response.new(@input)
- @response.body.size.should == 438
+ @response.body.size.should == 419
end
end
@@ -249,14 +249,14 @@
describe "as a file" do
it "should return response" do
response = WebMock::DynamicResponse.new(lambda {|request| @files[request.uri.host.to_s] })
- response.evaluate(@request_signature).body.size.should == 438
+ response.evaluate(@request_signature).body.size.should == 419
end
end
describe "as a string" do
it "should return response" do
response = WebMock::DynamicResponse.new(lambda {|request| @files[request.uri.host.to_s].read })
- response.evaluate(@request_signature).body.size.should == 438
+ response.evaluate(@request_signature).body.size.should == 419
end
end
end
4 spec/spec_helper.rb
View
@@ -2,7 +2,7 @@
require 'httpclient'
unless RUBY_PLATFORM =~ /java/
require 'curb'
- require 'patron'
+ require 'patron'
require 'em-http'
end
@@ -15,7 +15,7 @@
require 'network_connection'
RSpec.configure do |config|
- config.include WebMock::API
+ config.include WebMock::API
unless NetworkConnection.is_network_available?
warn("No network connectivity. Only examples which do not make real network connections will run.")
no_network_connection = true
14 spec/stub_request_snippet_spec.rb
View
@@ -13,32 +13,32 @@
it "should print stub request snippet with body if available" do
@request_signature.body = "abcdef"
- expected = %Q(stub_request(:get, "http://www.example.com/?a=b&c=d").)+
+ expected = %Q(stub_request(:get, "http://www.example.com/?a=b&c=d").)+
"\n with(:body => \"abcdef\")." +
"\n to_return(:status => 200, :body => \"\", :headers => {})"
WebMock::StubRequestSnippet.new(@request_signature).to_s.should == expected
end
-
+
it "should print stub request snippet with multiline body" do
@request_signature.body = "abc\ndef"
- expected = %Q(stub_request(:get, "http://www.example.com/?a=b&c=d").)+
+ expected = %Q(stub_request(:get, "http://www.example.com/?a=b&c=d").)+
"\n with(:body => \"abc\\ndef\")." +
"\n to_return(:status => 200, :body => \"\", :headers => {})"
WebMock::StubRequestSnippet.new(@request_signature).to_s.should == expected
end
-
+
it "should print stub request snippet with headers if any" do
@request_signature.headers = {'B' => 'b', 'A' => 'a'}
- expected = 'stub_request(:get, "http://www.example.com/?a=b&c=d").'+
+ expected = 'stub_request(:get, "http://www.example.com/?a=b&c=d").'+
"\n with(:headers => {\'A\'=>\'a\', \'B\'=>\'b\'})." +
"\n to_return(:status => 200, :body => \"\", :headers => {})"
WebMock::StubRequestSnippet.new(@request_signature).to_s.should == expected
end
-
+
it "should print stub request snippet with body and headers" do
@request_signature.body = "abcdef"
@request_signature.headers = {'B' => 'b', 'A' => 'a'}
- expected = 'stub_request(:get, "http://www.example.com/?a=b&c=d").'+
+ expected = 'stub_request(:get, "http://www.example.com/?a=b&c=d").'+
"\n with(:body => \"abcdef\", \n :headers => {\'A\'=>\'a\', \'B\'=>\'b\'})." +
"\n to_return(:status => 200, :body => \"\", :headers => {})"
WebMock::StubRequestSnippet.new(@request_signature).to_s.should == expected
10 spec/util/headers_spec.rb
View
@@ -9,20 +9,20 @@
end
describe "sorted_headers_string" do
-
+
it "should return nice string for hash with string values" do
WebMock::Util::Headers.sorted_headers_string({"a" => "b"}).should == "{'A'=>'b'}"
end
-
+
it "should return nice string for hash with array values" do
WebMock::Util::Headers.sorted_headers_string({"a" => ["b", "c"]}).should == "{'A'=>['b', 'c']}"
end
-
+
it "should return nice string for hash with array values and string values" do
WebMock::Util::Headers.sorted_headers_string({"a" => ["b", "c"], "d" => "e"}).should == "{'A'=>['b', 'c'], 'D'=>'e'}"
end
-
-
+
+
end
end
2  spec/util/uri_spec.rb
View
@@ -171,7 +171,7 @@
uri = 'http://www.example.com:80/path?a[]=b&a[]=c'
lambda { WebMock::Util::URI.normalize_uri(uri) }.should_not raise_error(ArgumentError)
end
-
+
end
describe "stripping default port" do
1  spec/vendor/addressable/lib/uri.rb
View
@@ -0,0 +1 @@
+
1  spec/vendor/crack/lib/crack.rb
View
@@ -0,0 +1 @@
+
8 spec/vendor/right_http_connection-1.2.4/History.txt
View
@@ -26,8 +26,8 @@ Initial public release
== 1.2.0 2007-10-05
* r1867, konstantin, 2007-10-05 06:19:45
- * # 220, (re)open connection to server if none exists or connection params
- have changed
+ * # 220, (re)open connection to server if none exists or connection params
+ have changed
== 1.2.1
@@ -37,7 +37,7 @@ Initial public release
* r2764, konstantin, 02-08-08 00:05:00 +03:00
* "RightAws: incompatible Net::HTTP monkey-patch" exception is raised if our net_fix
- patch was overriden (by attachment_fu for example, to avoid this load attachment_fu
+ patch was overriden (by attachment_fu for example, to avoid this load attachment_fu
before loading the right_http_connection gem).
== 1.2.2
@@ -51,7 +51,7 @@ Initial public release
- Improve handling of data streams during upload: if there is a failure and a retry, reset
the seek pointer for the subsequent re-request
-== 1.2.4
+== 1.2.4
* r4984, konstantin, 2008-08-11 14:49:18 +0400
* fixed a bug: <NoMethodError: You have a nil object when you didn't expect it!
8 spec/vendor/right_http_connection-1.2.4/README.txt
View
@@ -1,6 +1,6 @@
RightScale::HttpConnection
by RightScale, Inc.
- www.RightScale.com
+ www.RightScale.com
== DESCRIPTION:
@@ -12,7 +12,7 @@ algorithm for low-level network errors.
- provides put/get streaming
- does configurable retries on connect and read timeouts, DNS failures, etc.
- HTTPS certificate checking
-
+
== SYNOPSIS:
@@ -20,7 +20,7 @@ algorithm for low-level network errors.
- 2/11/08: If you use RightScale::HttpConnection in conjunction with attachment_fu, the
HttpConnection gem must be included (using the require statement) AFTER
- attachment_fu.
+ attachment_fu.
This is due to a conflict between the HttpConnection gem and another
gem required by attachment_fu.
@@ -32,7 +32,7 @@ sudo gem install right_http_connection
== LICENSE:
-Copyright (c) 2007-2008 RightScale, Inc.
+Copyright (c) 2007-2008 RightScale, Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
6 spec/vendor/right_http_connection-1.2.4/Rakefile
View
@@ -25,7 +25,7 @@ VERS = RightHttpConnection::VERSION::STRING + (REV ? ".#{REV}" : "")
CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
RDOC_OPTS = ['--quiet', '--title', 'right_http_connection documentation',
"--opname", "index.html",
- "--line-numbers",
+ "--line-numbers",
"--main", "README",
"--inline-source"]
@@ -51,7 +51,7 @@ end
# Generate all the Rake tasks
# Run 'rake -T' to see list of generated tasks (from gem root directory)
hoe = Hoe.new(GEM_NAME, VERS) do |p|
- p.author = AUTHOR
+ p.author = AUTHOR
p.description = DESCRIPTION
p.email = EMAIL
p.summary = DESCRIPTION
@@ -60,7 +60,7 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
p.test_globs = ["test/**/test_*.rb"]
p.clean_globs = CLEAN #An array of file patterns to delete on clean.
p.remote_rdoc_dir = "right_http_gem_doc"
-
+
# == Optional
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
8 spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb
View
@@ -22,12 +22,12 @@
#
#
-# Net::HTTP and Net::HTTPGenericRequest fixes to support 100-continue on
+# Net::HTTP and Net::HTTPGenericRequest fixes to support 100-continue on
# POST and PUT. The request must have 'expect' field set to '100-continue'.
module Net
-
+
class BufferedIO #:nodoc:
# Monkey-patch Net::BufferedIO to read > 1024 bytes from the socket at a time
@@ -117,12 +117,12 @@ def send_request_with_body_stream(sock, ver, path, f, send_only=nil)
end
end
end
- end
+ end
end
#-- Net::HTTP --
-
+
class HTTP
def request(req, body = nil, &block) # :yield: +response+
unless started?
8 spec/vendor/right_http_connection-1.2.4/setup.rb
View
@@ -659,7 +659,7 @@ def command(*args)
def ruby(*args)
command config('rubyprog'), *args
end
-
+
def make(task = nil)
command(*[config('makeprog'), task].compact)
end
@@ -722,7 +722,7 @@ def srcexist?(path)
def srcdirectory?(path)
File.dir?(srcfile(path))
end
-
+
def srcfile?(path)
File.file?(srcfile(path))
end
@@ -826,7 +826,7 @@ def invoke
__send__ "exec_#{task}"
end
end
-
+
def run_metaconfigs
@config.load_script "#{@ardir}/metaconfig"
end
@@ -1404,7 +1404,7 @@ def mapdir(ents)
end
# picked up many entries from cvs-1.11.1/src/ignore.c
- JUNK_FILES = %w(
+ JUNK_FILES = %w(
core RCSLOG tags TAGS .make.state
.nse_depinfo #* .#* cvslog.* ,* .del-* *.olb
*~ *.old *.bak *.BAK *.orig *.rej _$* *$
184 spec/webmock_shared.rb
View
@@ -61,7 +61,7 @@ class MyException < StandardError; end;
stub_http_request(:get, "www.example.com").to_return(:body => "abc")
http_request(:get, "http://www.example.com/").body.should == "abc"
end
-
+
it "should return stubbed response if request with path was stubbed" do
stub_http_request(:get, "www.example.com/hello_world").to_return(:body => "abc")
http_request(:get, "http://www.example.com/hello_world").body.should == "abc"
@@ -108,7 +108,7 @@ class MyException < StandardError; end;
}.should raise_error(connection_refused_exception_class)
end
end
-
+
describe "is not allowed with exception for allowed domains" do
before(:each) do
WebMock.disable_net_connect!(:allow => ["www.example.org"])
@@ -149,26 +149,26 @@ class MyException < StandardError; end;
stub_http_request(:get, /.*x=ab c.*/).to_return(:body => "abc")
http_request(:get, "http://www.example.com/hello/?#{ESCAPED_PARAMS}").body.should == "abc"
end
-
+
end
describe "on query params" do
-
+
it "should match the request by query params declared as a hash" do
stub_http_request(:get, "www.example.com").with(:query => {"a" => ["b", "c"]}).to_return(:body => "abc")
http_request(:get, "http://www.example.com/?a[]=b&a[]=c").body.should == "abc"
end
-
+
it "should match the request by query declared as a string" do
stub_http_request(:get, "www.example.com").with(:query => "a[]=b&a[]=c").to_return(:body => "abc")
http_request(:get, "http://www.example.com/?a[]=b&a[]=c").body.should == "abc"
end
-
+
it "should match the request by query params declared both in uri and query option" do
stub_http_request(:get, "www.example.com/?x=3").with(:query => {"a" => ["b", "c"]}).to_return(:body => "abc")
http_request(:get, "http://www.example.com/?x=3&a[]=b&a[]=c").body.should == "abc"
end
-
+
end
describe "on method" do
@@ -229,27 +229,27 @@ class MyException < StandardError; end;
end
end
-
- describe "when body is declared as a hash" do
+
+ describe "when body is declared as a hash" do
before(:each) do
stub_http_request(:post, "www.example.com").
with(:body => {:a => '1', :b => 'five', 'c' => {'d' => ['e', 'f']} })
end
-
+
describe "for request with url encoded body" do
-
+
it "should match request if hash matches body" do
http_request(
:post, "http://www.example.com/",
:body => 'a=1&c[d][]=e&c[d][]=f&b=five').status.should == "200"
end
-
+
it "should match request if hash matches body in different order of params" do
http_request(
:post, "http://www.example.com/",
:body => 'a=1&c[d][]=e&b=five&c[d][]=f').status.should == "200"
end
-
+
it "should not match if hash doesn't match url encoded body" do
lambda {
http_request(
@@ -257,47 +257,47 @@ class MyException < StandardError; end;
:body => 'c[d][]=f&a=1&c[d][]=e').status.should == "200"
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'c\[d\]\[\]=f&a=1&c\[d\]\[\]=e'))
end
-
+
end
-
-
+
+
describe "for request with json body and content type is set to json" do
-
+
it "should match if hash matches body" do
http_request(
:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
:body => "{\"a\":\"1\",\"c\":{\"d\":[\"e\",\"f\"]},\"b\":\"five\"}").status.should == "200"
end
-
+
it "should match if hash matches body in different form" do
http_request(
:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'},
:body => "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}").status.should == "200"
end
-
+
end
-
+
describe "for request with xml body and content type is set to xml" do
before(:each) do
WebMock.reset!
stub_http_request(:post, "www.example.com").
with(:body => { "opt" => {:a => '1', :b => 'five', 'c' => {'d' => ['e', 'f']} }})
end
-
+
it "should match if hash matches body" do
http_request(
- :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
+ :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
:body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n").status.should == "200"
end
-
+
it "should match if hash matches body in different form" do
http_request(
- :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
+ :post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'},
:body => "<opt b=\"five\" a=\"1\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n").status.should == "200"
end
-
+
end
-
+
end
end
@@ -310,30 +310,30 @@ class MyException < StandardError; end;
:get, "http://www.example.com/",
:headers => SAMPLE_HEADERS).status.should == "200"
end
-
+
it "should match requests if headers are the same and declared as array" do
stub_http_request(:get, "www.example.com").with(:headers => {"a" => ["b"]} )
http_request(
:get, "http://www.example.com/",
:headers => {"a" => "b"}).status.should == "200"
end
-
+
describe "when multiple headers with the same key are used" do
-
+
it "should match requests if headers are the same" do
stub_http_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]} )
http_request(
:get, "http://www.example.com/",
:headers => {"a" => ["b", "c"]}).status.should == "200"
end
-
+
it "should match requests if headers are the same but in different order" do
stub_http_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]} )
http_request(
:get, "http://www.example.com/",
:headers => {"a" => ["c", "b"]}).status.should == "200"
end
-
+
it "should not match requests if headers are different" do
stub_http_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]})
@@ -343,7 +343,7 @@ class MyException < StandardError; end;
:headers => {"a" => ["b", "d"]})
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
end
-
+
end
it "should match requests if request headers are not stubbed" do
@@ -461,14 +461,14 @@ class MyException < StandardError; end;
http_request(:get, "http://www.example.com/")
}.should raise_error(MyException, "Exception from WebMock")
end
-
+
it "should raise exception if declared in a stubbed response as exception instance" do
stub_http_request(:get, "www.example.com").to_raise(MyException.new("hello world"))
lambda {
http_request(:get, "http://www.example.com/")
}.should raise_error(MyException, "hello world")
end
-
+
it "should raise exception if declared in a stubbed response as exception instance" do
stub_http_request(:get, "www.example.com").to_raise("hello world")
lambda {
@@ -488,7 +488,7 @@ class MyException < StandardError; end;
describe "raising timeout errors" do
-
+
it "should raise timeout exception if declared in a stubbed response" do
stub_http_request(:get, "www.example.com").to_timeout
lambda {
@@ -518,7 +518,7 @@ class MyException < StandardError; end;
response = http_request(:get, "http://www.example.com/")
response.headers["Content-Length"].should == "8888"
end
-
+
it "should return declared headers when there are multiple headers with the same key" do
stub_http_request(:get, "www.example.com").to_return(:headers => {"a" => ["b", "c"]})
response = http_request(:get, "http://www.example.com/")
@@ -529,21 +529,21 @@ class MyException < StandardError; end;
stub_http_request(:get, "www.example.com").to_return(:status => 500)
http_request(:get, "http://www.example.com/").status.should == "500"
end
-
+
it "should return declared status message" do
stub_http_request(:get, "www.example.com").to_return(:status => [500, "Internal Server Error"])
http_request(:get, "http://www.example.com/").message.should == "Internal Server Error"
end
-
+
it "should return default status code" do
stub_http_request(:get, "www.example.com")
http_request(:get, "http://www.example.com/").status.should == "200"
end
-
+
it "should return default empty message" do
stub_http_request(:get, "www.example.com")
http_request(:get, "http://www.example.com/").message.should == ""
- end
+ end
it "should return body declared as IO" do
stub_http_request(:get, "www.example.com").to_return(:body => File.new(__FILE__))
@@ -625,20 +625,20 @@ def call(request)
@response.headers.should == {
"Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
"Content-Type"=>"text/html; charset=UTF-8",
- "Content-Length"=>"438",
+ "Content-Length"=>"419",
"Connection"=>"Keep-Alive",
"Accept"=>"image/jpeg, image/png"
}
end
it "should return recorded body" do
- @response.body.size.should == 438
+ @response.body.size.should == 419
end
it "