From a251cb3657cd2032c8c03f02108a1bce9113e72b Mon Sep 17 00:00:00 2001 From: James Conroy-Finn Date: Sat, 28 May 2011 19:33:37 +0100 Subject: [PATCH] Indent files correctly and remove trailing whitespace This makes it much easier moving using motions and editing files in a number of editors. --- CHANGELOG.md | 236 +++++++++--------- Gemfile | 2 +- LICENSE | 2 +- lib/webmock/api.rb | 6 +- lib/webmock/assertion_failure.rb | 2 +- lib/webmock/callback_registry.rb | 2 +- lib/webmock/config.rb | 4 +- lib/webmock/cucumber.rb | 2 +- lib/webmock/errors.rb | 4 +- lib/webmock/http_lib_adapters/curb.rb | 18 +- lib/webmock/http_lib_adapters/httpclient.rb | 12 +- lib/webmock/http_lib_adapters/net_http.rb | 8 +- .../http_lib_adapters/net_http_response.rb | 4 +- lib/webmock/http_lib_adapters/patron.rb | 6 +- lib/webmock/request_pattern.rb | 2 +- lib/webmock/request_stub.rb | 4 +- lib/webmock/responses_sequence.rb | 4 +- lib/webmock/rspec.rb | 4 +- lib/webmock/rspec/matchers.rb | 8 +- lib/webmock/rspec/matchers/webmock_matcher.rb | 2 +- lib/webmock/stub_registry.rb | 2 +- lib/webmock/util/hash_keys_stringifier.rb | 8 +- lib/webmock/util/headers.rb | 6 +- lib/webmock/util/uri.rb | 2 +- lib/webmock/webmock.rb | 4 +- spec/curb_spec.rb | 14 +- spec/curb_spec_helper.rb | 4 +- spec/em_http_request_spec_helper.rb | 18 +- spec/errors_spec.rb | 6 +- spec/example_curl_output.txt | 44 ++-- spec/httpclient_spec.rb | 2 +- spec/httpclient_spec_helper.rb | 6 +- spec/net_http_spec_helper.rb | 12 +- spec/network_connection.rb | 2 +- spec/patron_spec_helper.rb | 4 +- spec/request_execution_verifier_spec.rb | 16 +- spec/request_pattern_spec.rb | 6 +- spec/request_stub_spec.rb | 38 +-- spec/response_spec.rb | 16 +- spec/spec_helper.rb | 4 +- spec/stub_request_snippet_spec.rb | 14 +- spec/util/headers_spec.rb | 10 +- spec/util/uri_spec.rb | 2 +- spec/vendor/addressable/lib/uri.rb | 1 + spec/vendor/crack/lib/crack.rb | 1 + .../right_http_connection-1.2.4/History.txt | 8 +- .../right_http_connection-1.2.4/README.txt | 8 +- .../right_http_connection-1.2.4/Rakefile | 6 +- .../lib/net_fix.rb | 8 +- .../right_http_connection-1.2.4/setup.rb | 8 +- spec/webmock_shared.rb | 184 +++++++------- 51 files changed, 399 insertions(+), 397 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38885f7f6..2fbce060c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`
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', '', - :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', '', + :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 diff --git a/Gemfile b/Gemfile index f792d2e28..7dff8ab94 100644 --- a/Gemfile +++ b/Gemfile @@ -9,4 +9,4 @@ end platforms :jruby do gem 'jruby-openssl', '~> 0.7' -end \ No newline at end of file +end diff --git a/LICENSE b/LICENSE index cfe6488aa..9a6302d0b 100644 --- a/LICENSE +++ b/LICENSE @@ -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. \ No newline at end of file +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/webmock/api.rb b/lib/webmock/api.rb index b94bcd331..aec580567 100644 --- a/lib/webmock/api.rb +++ b/lib/webmock/api.rb @@ -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 \ No newline at end of file +end diff --git a/lib/webmock/assertion_failure.rb b/lib/webmock/assertion_failure.rb index a85e5a8a5..86397c5e9 100644 --- a/lib/webmock/assertion_failure.rb +++ b/lib/webmock/assertion_failure.rb @@ -8,4 +8,4 @@ def failure(message) end end end -end \ No newline at end of file +end diff --git a/lib/webmock/callback_registry.rb b/lib/webmock/callback_registry.rb index a851af91c..cc9ab3415 100644 --- a/lib/webmock/callback_registry.rb +++ b/lib/webmock/callback_registry.rb @@ -26,7 +26,7 @@ def self.invoke_callbacks(options, request_signature, response) def self.reset @@callbacks = [] end - + def self.any_callbacks? !@@callbacks.empty? end diff --git a/lib/webmock/config.rb b/lib/webmock/config.rb index 9c8ecd241..392225007 100644 --- a/lib/webmock/config.rb +++ b/lib/webmock/config.rb @@ -1,7 +1,7 @@ module WebMock - class Config + class Config include Singleton - + attr_accessor :allow_net_connect attr_accessor :allow_localhost attr_accessor :allow diff --git a/lib/webmock/cucumber.rb b/lib/webmock/cucumber.rb index f7eb1da1d..5f2667d8a 100644 --- a/lib/webmock/cucumber.rb +++ b/lib/webmock/cucumber.rb @@ -5,4 +5,4 @@ After do WebMock.reset! -end \ No newline at end of file +end diff --git a/lib/webmock/errors.rb b/lib/webmock/errors.rb index 04a68cc5b..d86032b70 100644 --- a/lib/webmock/errors.rb +++ b/lib/webmock/errors.rb @@ -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 \ No newline at end of file +end diff --git a/lib/webmock/http_lib_adapters/curb.rb b/lib/webmock/http_lib_adapters/curb.rb index 05720800d..bb7042720 100644 --- a/lib/webmock/http_lib_adapters/curb.rb +++ b/lib/webmock/http_lib_adapters/curb.rb @@ -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 diff --git a/lib/webmock/http_lib_adapters/httpclient.rb b/lib/webmock/http_lib_adapters/httpclient.rb index 674a4946f..1a19aec3d 100644 --- a/lib/webmock/http_lib_adapters/httpclient.rb +++ b/lib/webmock/http_lib_adapters/httpclient.rb @@ -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 diff --git a/lib/webmock/http_lib_adapters/net_http.rb b/lib/webmock/http_lib_adapters/net_http.rb index 3facb9171..92f2fe85e 100644 --- a/lib/webmock/http_lib_adapters/net_http.rb +++ b/lib/webmock/http_lib_adapters/net_http.rb @@ -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 diff --git a/lib/webmock/http_lib_adapters/net_http_response.rb b/lib/webmock/http_lib_adapters/net_http_response.rb index 1c96b42e3..b25199373 100644 --- a/lib/webmock/http_lib_adapters/net_http_response.rb +++ b/lib/webmock/http_lib_adapters/net_http_response.rb @@ -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 \ No newline at end of file +end diff --git a/lib/webmock/http_lib_adapters/patron.rb b/lib/webmock/http_lib_adapters/patron.rb index 093ac732a..fb71fb607 100644 --- a/lib/webmock/http_lib_adapters/patron.rb +++ b/lib/webmock/http_lib_adapters/patron.rb @@ -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] diff --git a/lib/webmock/request_pattern.rb b/lib/webmock/request_pattern.rb index a9494e20b..fc826af24 100644 --- a/lib/webmock/request_pattern.rb +++ b/lib/webmock/request_pattern.rb @@ -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) diff --git a/lib/webmock/request_stub.rb b/lib/webmock/request_stub.rb index b42dbafd3..2dc9697eb 100644 --- a/lib/webmock/request_stub.rb +++ b/lib/webmock/request_stub.rb @@ -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 diff --git a/lib/webmock/responses_sequence.rb b/lib/webmock/responses_sequence.rb index e712f52e5..7c5f13394 100644 --- a/lib/webmock/responses_sequence.rb +++ b/lib/webmock/responses_sequence.rb @@ -1,5 +1,5 @@ module WebMock - + class ResponsesSequence attr_accessor :times_to_repeat @@ -36,5 +36,5 @@ def increase_position end end - + end diff --git a/lib/webmock/rspec.rb b/lib/webmock/rspec.rb index 9a640e2b1..49a3040ce 100644 --- a/lib/webmock/rspec.rb +++ b/lib/webmock/rspec.rb @@ -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 diff --git a/lib/webmock/rspec/matchers.rb b/lib/webmock/rspec/matchers.rb index b396d3ad6..79d182abf 100644 --- a/lib/webmock/rspec/matchers.rb +++ b/lib/webmock/rspec/matchers.rb @@ -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 \ No newline at end of file +end diff --git a/lib/webmock/rspec/matchers/webmock_matcher.rb b/lib/webmock/rspec/matchers/webmock_matcher.rb index ea6862473..7f4b17556 100644 --- a/lib/webmock/rspec/matchers/webmock_matcher.rb +++ b/lib/webmock/rspec/matchers/webmock_matcher.rb @@ -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 diff --git a/lib/webmock/stub_registry.rb b/lib/webmock/stub_registry.rb index fca8761a7..20994f003 100644 --- a/lib/webmock/stub_registry.rb +++ b/lib/webmock/stub_registry.rb @@ -40,4 +40,4 @@ def evaluate_response_for_request(response, request_signature) end end -end \ No newline at end of file +end diff --git a/lib/webmock/util/hash_keys_stringifier.rb b/lib/webmock/util/hash_keys_stringifier.rb index c66260ebb..85fae63ce 100644 --- a/lib/webmock/util/hash_keys_stringifier.rb +++ b/lib/webmock/util/hash_keys_stringifier.rb @@ -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 \ No newline at end of file +end diff --git a/lib/webmock/util/headers.rb b/lib/webmock/util/headers.rb index 1c6322ac0..bd88ff7cf 100644 --- a/lib/webmock/util/headers.rb +++ b/lib/webmock/util/headers.rb @@ -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 diff --git a/lib/webmock/util/uri.rb b/lib/webmock/util/uri.rb index 879a46aa5..91241942f 100644 --- a/lib/webmock/util/uri.rb +++ b/lib/webmock/util/uri.rb @@ -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 diff --git a/lib/webmock/webmock.rb b/lib/webmock/webmock.rb index af7a8a385..9c21016e2 100644 --- a/lib/webmock/webmock.rb +++ b/lib/webmock/webmock.rb @@ -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 diff --git a/spec/curb_spec.rb b/spec/curb_spec.rb index ced5ba0b7..ab634c654 100644 --- a/spec/curb_spec.rb +++ b/spec/curb_spec.rb @@ -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 diff --git a/spec/curb_spec_helper.rb b/spec/curb_spec_helper.rb index 6af0142f6..1a27cec0b 100644 --- a/spec/curb_spec_helper.rb +++ b/spec/curb_spec_helper.rb @@ -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 diff --git a/spec/em_http_request_spec_helper.rb b/spec/em_http_request_spec_helper.rb index fb4c84d79..e809d9b36 100644 --- a/spec/em_http_request_spec_helper.rb +++ b/spec/em_http_request_spec_helper.rb @@ -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 diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index 924887eda..f8153a987 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -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 \ No newline at end of file +end diff --git a/spec/example_curl_output.txt b/spec/example_curl_output.txt index 571c41ee0..68598525a 100644 --- a/spec/example_curl_output.txt +++ b/spec/example_curl_output.txt @@ -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 - - - - Example Web Page - - -

You have reached this web page by typing "example.com", -"example.net", - or "example.org" into your web browser.

-

These domain names are reserved for use in documentation and are not available - for registration. See RFC - 2606, Section 3.

- - - +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 + + + + Example Web Page + + +

You have reached this web page by typing "example.com", +"example.net", + or "example.org" into your web browser.

+

These domain names are reserved for use in documentation and are not available + for registration. See RFC + 2606, Section 3.

+ + + diff --git a/spec/httpclient_spec.rb b/spec/httpclient_spec.rb index 6a24564b8..9ae292836 100644 --- a/spec/httpclient_spec.rb +++ b/spec/httpclient_spec.rb @@ -28,7 +28,7 @@ :get, "http://www.example.com/", :headers => {"a" => ["c", "b"]}).status.should == "200" end - + describe "async requests" do diff --git a/spec/httpclient_spec_helper.rb b/spec/httpclient_spec_helper.rb index a1d505805..d3003d564 100644 --- a/spec/httpclient_spec_helper.rb +++ b/spec/httpclient_spec_helper.rb @@ -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 diff --git a/spec/net_http_spec_helper.rb b/spec/net_http_spec_helper.rb index d28a85dce..558685b60 100644 --- a/spec/net_http_spec_helper.rb +++ b/spec/net_http_spec_helper.rb @@ -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 diff --git a/spec/network_connection.rb b/spec/network_connection.rb index 2a3763499..66a0f2df4 100644 --- a/spec/network_connection.rb +++ b/spec/network_connection.rb @@ -22,4 +22,4 @@ def self.is_network_available? false end end -end \ No newline at end of file +end diff --git a/spec/patron_spec_helper.rb b/spec/patron_spec_helper.rb index 1d3e0124a..b37a34d9f 100644 --- a/spec/patron_spec_helper.rb +++ b/spec/patron_spec_helper.rb @@ -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({ diff --git a/spec/request_execution_verifier_spec.rb b/spec/request_execution_verifier_spec.rb index 4ad53f61d..1ad8a8ba8 100644 --- a/spec/request_execution_verifier_spec.rb +++ b/spec/request_execution_verifier_spec.rb @@ -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 diff --git a/spec/request_pattern_spec.rb b/spec/request_pattern_spec.rb index 9ecce7c73..474fd0e68 100644 --- a/spec/request_pattern_spec.rb +++ b/spec/request_pattern_spec.rb @@ -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")) diff --git a/spec/request_stub_spec.rb b/spec/request_stub_spec.rb index a5fea0eb1..4eb53494f 100644 --- a/spec/request_stub_spec.rb +++ b/spec/request_stub_spec.rb @@ -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 diff --git a/spec/response_spec.rb b/spec/response_spec.rb index 6bcfbcd03..56c63993d 100644 --- a/spec/response_spec.rb +++ b/spec/response_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 428f4d7dc..329ab24fe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/stub_request_snippet_spec.rb b/spec/stub_request_snippet_spec.rb index e8273923a..4864d162f 100644 --- a/spec/stub_request_snippet_spec.rb +++ b/spec/stub_request_snippet_spec.rb @@ -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 diff --git a/spec/util/headers_spec.rb b/spec/util/headers_spec.rb index 57a6b93e7..723b7700c 100644 --- a/spec/util/headers_spec.rb +++ b/spec/util/headers_spec.rb @@ -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 diff --git a/spec/util/uri_spec.rb b/spec/util/uri_spec.rb index 0f070c620..6f7bae177 100644 --- a/spec/util/uri_spec.rb +++ b/spec/util/uri_spec.rb @@ -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 diff --git a/spec/vendor/addressable/lib/uri.rb b/spec/vendor/addressable/lib/uri.rb index e69de29bb..8b1378917 100644 --- a/spec/vendor/addressable/lib/uri.rb +++ b/spec/vendor/addressable/lib/uri.rb @@ -0,0 +1 @@ + diff --git a/spec/vendor/crack/lib/crack.rb b/spec/vendor/crack/lib/crack.rb index e69de29bb..8b1378917 100644 --- a/spec/vendor/crack/lib/crack.rb +++ b/spec/vendor/crack/lib/crack.rb @@ -0,0 +1 @@ + diff --git a/spec/vendor/right_http_connection-1.2.4/History.txt b/spec/vendor/right_http_connection-1.2.4/History.txt index e06bcd0a2..5943374fc 100644 --- a/spec/vendor/right_http_connection-1.2.4/History.txt +++ b/spec/vendor/right_http_connection-1.2.4/History.txt @@ -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: = 1.3.1'] ] diff --git a/spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb b/spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb index ad54f8a2a..feb78c89b 100644 --- a/spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb +++ b/spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb @@ -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? diff --git a/spec/vendor/right_http_connection-1.2.4/setup.rb b/spec/vendor/right_http_connection-1.2.4/setup.rb index 424a5f37c..9f0c8267a 100644 --- a/spec/vendor/right_http_connection-1.2.4/setup.rb +++ b/spec/vendor/right_http_connection-1.2.4/setup.rb @@ -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 _$* *$ diff --git a/spec/webmock_shared.rb b/spec/webmock_shared.rb index ba855c5e6..89aa94371 100644 --- a/spec/webmock_shared.rb +++ b/spec/webmock_shared.rb @@ -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 => "\n \n e\n f\n \n\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 => "\n \n e\n f\n \n\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 "should return recorded status" do @response.status.should == "202" end - + it "should return recorded status message" do @response.message.should == "OK" end @@ -661,20 +661,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 "should return recorded status" do @response.status.should == "202" end - + it "should return recorded status message" do @response.message.should == "OK" end @@ -689,12 +689,12 @@ def call(request) it "should return response from evaluated file" do stub_http_request(:get, "www.example.com").to_return(lambda {|request| @files[request.uri.host.to_s] }) - http_request(:get, "http://www.example.com/").body.size.should == 438 + http_request(:get, "http://www.example.com/").body.size.should == 419 end it "should return response from evaluated string" do stub_http_request(:get, "www.example.com").to_return(lambda {|request| @files[request.uri.host.to_s].read }) - http_request(:get, "http://www.example.com/").body.size.should == 438 + http_request(:get, "http://www.example.com/").body.size.should == 419 end end @@ -870,7 +870,7 @@ def call(request) a_request(:get, "http://www.example.com").should_not have_been_made }.should fail_with(%r(The request GET http://www.example.com/ was expected to execute 0 times but it executed 1 time)) end - + it "should fail with message with executed requests listed" do lambda { http_request(:get, "http://www.example.com/") @@ -960,14 +960,14 @@ def call(request) a_request(:get, /.*example.*/).should have_been_made }.should_not raise_error end - + end describe "when matching requests with query params" do before(:each) do stub_http_request(:any, /.*example.*/) end - + it "should pass if the request was executed with query params declared in a hash in query option" do lambda { http_request(:get, "http://www.example.com/?a[]=b&a[]=c") @@ -988,7 +988,7 @@ def call(request) a_request(:get, "www.example.com/?x=3").with(:query => {"a" => ["b", "c"]}).should have_been_made }.should_not raise_error end - + end it "should fail if requested more times than expected" do @@ -1044,22 +1044,22 @@ def call(request) with(:body => "xabc").should have_been_made }.should fail_with(%r(The request GET http://www.example.com/ with body "xabc" was expected to execute 1 time but it executed 0 times)) end - + end - + describe "when expected body is declared as a hash" do let(:body_hash) { {:a => '1', :b => 'five', 'c' => {'d' => ['e', 'f']}} } let(:fail_message) {%r(The request POST http://www.example.com/ with body \{"a"=>"1", "b"=>"five", "c"=>\{"d"=>\["e", "f"\]\}\} was expected to execute 1 time but it executed 0 times)} describe "when request is executed with url encoded body matching hash" do - + it "should succeed" do lambda { http_request(:post, "http://www.example.com/", :body => 'a=1&c[d][]=e&c[d][]=f&b=five') a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made }.should_not raise_error end - + it "should succeed if url encoded params have different order" do lambda { http_request(:post, "http://www.example.com/", :body => 'a=1&c[d][]=e&b=five&c[d][]=f') @@ -1073,7 +1073,7 @@ def call(request) a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made }.should fail_with(fail_message) end - + end describe "when request is executed with json body matching hash and content type is set to json" do @@ -1085,7 +1085,7 @@ def call(request) a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made }.should_not raise_error end - + it "should succeed if json body is in different form" do lambda { http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/json'}, @@ -1093,13 +1093,13 @@ def call(request) a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made }.should_not raise_error end - + end describe "when request is executed with xml body matching hash and content type is set to xml" do let(:body_hash) { { "opt" => {:a => "1", :b => 'five', 'c' => {'d' => ['e', 'f']}} }} - + it "should succeed" do lambda { http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'}, @@ -1107,7 +1107,7 @@ def call(request) a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made }.should_not raise_error end - + it "should succeed if xml body is in different form" do lambda { http_request(:post, "http://www.example.com/", :headers => {'Content-Type' => 'application/xml'}, @@ -1115,9 +1115,9 @@ def call(request) a_request(:post, "www.example.com").with(:body => body_hash).should have_been_made }.should_not raise_error end - + end - + end it "should succeed if request was executed with the same headers" do @@ -1127,7 +1127,7 @@ def call(request) with(:headers => SAMPLE_HEADERS).should have_been_made }.should_not raise_error end - + it "should succeed if request was executed with the same headers with value declared as array" do lambda { http_request(:get, "http://www.example.com/", :headers => {"a" => "b"}) @@ -1135,9 +1135,9 @@ def call(request) with(:headers => {"a" => ["b"]}).should have_been_made }.should_not raise_error end - + describe "when multiple headers with the same key are passed" do - + it "should succeed if request was executed with the same headers" do lambda { http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]}) @@ -1145,7 +1145,7 @@ def call(request) with(:headers => {"a" => ["b", "c"]}).should have_been_made }.should_not raise_error end - + it "should succeed if request was executed with the same headers but different order" do lambda { http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]}) @@ -1153,7 +1153,7 @@ def call(request) with(:headers => {"a" => ["c", "b"]}).should have_been_made }.should_not raise_error end - + it "should fail if request was executed with different headers" do lambda { http_request(:get, "http://www.example.com/", :headers => {"a" => ["b", "c"]}) @@ -1161,7 +1161,7 @@ def call(request) with(:headers => {"a" => ["b", "d"]}).should have_been_made }.should fail_with(%r(The request GET http://www.example.com/ with headers \{'A'=>\['b', 'd'\]\} was expected to execute 1 time but it executed 0 times)) end - + end it "should fail if request was executed with different headers" do @@ -1401,20 +1401,20 @@ def call(request) describe "callbacks" do - + describe "after_request" do before(:each) do WebMock.reset_callbacks stub_request(:get, "http://www.example.com") end - + it "should not invoke callback unless request is made" do WebMock.after_request { @called = true } @called.should == nil end - + it "should invoke a callback after request is made" do WebMock.after_request { @called = true @@ -1422,7 +1422,7 @@ def call(request) http_request(:get, "http://www.example.com/") @called.should == true end - + it "should not invoke a callback if specific http library should be ignored" do WebMock.after_request(:except => [http_library()]) { @called = true @@ -1430,7 +1430,7 @@ def call(request) http_request(:get, "http://www.example.com/") @called.should == nil end - + it "should invoke a callback even if other http libraries should be ignored" do WebMock.after_request(:except => [:other_lib]) { @called = true @@ -1438,7 +1438,7 @@ def call(request) http_request(:get, "http://www.example.com/") @called.should == true end - + it "should pass request signature to the callback" do WebMock.after_request(:except => [:other_lib]) do |request_signature, _| @request_signature = request_signature @@ -1446,7 +1446,7 @@ def call(request) http_request(:get, "http://www.example.com/") @request_signature.uri.to_s.should == "http://www.example.com:80/" end - + describe "passing response to callback" do describe "for stubbed requests" do @@ -1463,23 +1463,23 @@ def call(request) http_request(:get, "http://www.example.com/") end - it "should pass response with status and message" do + it "should pass response with status and message" do @response.status.should == ["200", "hello"] end - + it "should pass response with headers" do @response.headers.should == { - 'Content-Length' => '666', + 'Content-Length' => '666', 'Hello' => 'World' } end - + it "should pass response with body" do @response.body.should == "foo bar" end - + end - + describe "for real requests", :net_connect => true do before(:each) do WebMock.reset! @@ -1494,26 +1494,26 @@ def call(request) @response.status[0].should == 302 @response.status[1].should == "Found" end - + it "should pass response with headers" do @response.headers["Content-Length"].should == "#{WWW_EXAMPLE_COM_CONTENT_LENGTH}" end - + it "should pass response with body" do @response.body.size.should == WWW_EXAMPLE_COM_CONTENT_LENGTH end - + end - + end - + it "should invoke multiple callbacks in order of their declarations" do WebMock.after_request { @called = 1 } WebMock.after_request { @called += 1 } http_request(:get, "http://www.example.com/") @called.should == 2 end - + it "should invoke callbacks only for real requests if requested", :net_connect => true do WebMock.after_request(:real_requests_only => true) { @called = true } http_request(:get, "http://www.example.com/") @@ -1522,17 +1522,17 @@ def call(request) http_request(:get, "http://www.example.net/") @called.should == true end - + it "should clear all declared callbacks on reset callbacks" do WebMock.after_request { @called = 1 } WebMock.reset_callbacks - stub_request(:get, "http://www.example.com") + stub_request(:get, "http://www.example.com") http_request(:get, "http://www.example.com/") @called.should == nil end - + end - + end end