Permalink
Browse files

Removed validation of the whole error message in webmock adapter spec…

… with client specific headers validation as it didn't help in any way.
  • Loading branch information...
1 parent b175c1a commit 0c904c90c4dedbe71c813f9910617680b5419261 @bblimke committed Nov 10, 2010
@@ -30,10 +30,6 @@ def setup_request(uri, curl, options={})
curl
end
- def default_client_request_headers(request_method = nil, has_body = false)
- nil
- end
-
def client_timeout_exception_class
Curl::Err::TimeoutError
end
@@ -47,10 +47,6 @@ def connection_refused_exception_class
""
end
- def default_client_request_headers(request_method = nil, has_body = false)
- nil
- end
-
def setup_expectations_for_real_request(options = {})
end
@@ -41,10 +41,6 @@ def connection_refused_exception_class
Errno::ECONNREFUSED
end
- def default_client_request_headers(request_method = nil, has_body = false)
- {'Content-Type'=>'application/x-www-form-urlencoded'} if request_method == 'POST' && has_body
- end
-
def setup_expectations_for_real_request(options = {})
socket = mock("TCPSocket")
TCPSocket.should_receive(:new).
@@ -39,13 +39,6 @@ def http_request(method, uri, options = {}, &block)
})
end
- def default_client_request_headers(request_method = nil, has_body = false)
- default_request = Net::HTTPGenericRequest.new('','','','/')
- default_net_http_headers = Hash[*default_request.to_hash.map {|k,v|
- [k, v.flatten]
- }.flatten]
- end
-
def client_timeout_exception_class
Timeout::Error
end
@@ -30,14 +30,6 @@ def http_request(method, uri, options = {}, &block)
})
end
- def default_client_request_headers(request_method = nil, has_body = false)
- if Gem::Version.new(Patron.version) >= Gem::Version.new("0.4.6")
- {'Expect'=>''}
- else
- nil
- end
- end
-
def client_timeout_exception_class
Patron::TimeoutError
end
View
@@ -47,19 +47,3 @@ def setup_expectations_for_real_example_com_request(options = {})
setup_expectations_for_real_request(defaults.merge(options))
end
-def client_specific_request_string(string)
- method = string.gsub(/.*Unregistered request: ([^ ]+).+/, '\1')
- has_body = string.include?(" with body")
- default_headers = default_client_request_headers(method, has_body)
- if default_headers
- if string.include?(" with headers")
- current_headers = Crack::JSON.parse(string.gsub(/.*with headers (\{[^}]+\}).*/, '\1').gsub("=>",":").gsub("'","\""))
- default_headers = WebMock::Util::Headers.normalize_headers(default_headers)
- default_headers.merge!(current_headers)
- string.gsub!(/(.*) with headers.*/,'\1')
- end
- string << " with headers #{WebMock::Util::Headers.sorted_headers_string(default_headers)}"
- end
- string
-end
-
@@ -67,7 +67,7 @@ class MyException < StandardError; end;
it "should raise exception if request was not stubbed" do
lambda {
http_request(:get, "http://www.example.com/")
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string("Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
end
end
@@ -84,7 +84,7 @@ class MyException < StandardError; end;
it "should raise exception if request was not stubbed" do
lambda {
http_request(:get, "http://www.example.com/")
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string("Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
end
it "should allow a real request to localhost" do
@@ -119,7 +119,7 @@ class MyException < StandardError; end;
it "should raise exception if request was not stubbed" do
lambda {
http_request(:get, "http://www.example.com/")
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string("Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
end
it "should allow a real request to allowed host", :net_connect => true do
@@ -180,8 +180,7 @@ class MyException < StandardError; end;
http_request(:get, "http://www.example.com/").status.should == "200"
lambda {
http_request(:delete, "http://www.example.com/")
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- "Real HTTP connections are disabled. Unregistered request: DELETE http://www.example.com/")
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: DELETE http://www.example.com/)
)
end
@@ -207,8 +206,7 @@ class MyException < StandardError; end;
stub_http_request(:post, "www.example.com").with(:body => "abc")
lambda {
http_request(:post, "http://www.example.com/", :body => "def")
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- "Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'def'"))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'def'))
end
describe "with regular expressions" do
@@ -224,8 +222,7 @@ class MyException < StandardError; end;
stub_http_request(:post, "www.example.com").with(:body => /^abc/)
lambda {
http_request(:post, "http://www.example.com/", :body => "xabc")
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- "Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'xabc'"))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'xabc'))
end
end
@@ -255,9 +252,7 @@ class MyException < StandardError; end;
http_request(
:post, "http://www.example.com/",
:body => 'c[d][]=f&a=1&c[d][]=e').status.should == "200"
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- "Real HTTP connections are disabled. Unregistered request: "+
- "POST http://www.example.com/ with body 'c[d][]=f&a=1&c[d][]=e'"))
+ }.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
@@ -343,8 +338,7 @@ class MyException < StandardError; end;
http_request(
:get, "http://www.example.com/",
:headers => {"a" => ["b", "d"]})
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- %q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with 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
@@ -363,8 +357,7 @@ class MyException < StandardError; end;
http_request(
:get, "http://www.example.com/",
:headers => { 'Content-Length' => '9999'})
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- %q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'Content-Length'=>'9999'})))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
end
it "should not match if accept header is different" do
@@ -374,8 +367,7 @@ class MyException < StandardError; end;
http_request(
:get, "http://www.example.com/",
:headers => { 'Accept' => 'application/xml'})
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- %q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'Accept'=>'application/xml'})))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
end
describe "with regular expressions" do
@@ -394,8 +386,7 @@ class MyException < StandardError; end;
http_request(
:get, "http://www.example.com/",
:headers => { 'user-agent' => 'xMyAppName' })
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- %q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'User-Agent'=>'xMyAppName'})))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
end
end
@@ -412,24 +403,21 @@ class MyException < StandardError; end;
stub_http_request(:get, "user:pass@www.example.com")
lambda {
http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- %q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/)))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
end
it "should not match if credentials are stubbed but not provided in the request" do
stub_http_request(:get, "user:pass@www.example.com")
lambda {
http_request(:get, "http://www.example.com/").status.should == "200"
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- %q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/)))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
end
it "should not match if credentials are not stubbed but exist in the request" do
stub_http_request(:get, "www.example.com")
lambda {
http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- %q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/)))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
end
end
@@ -445,8 +433,7 @@ class MyException < StandardError; end;
stub_http_request(:get, "www.example.com").with { |request| false }
lambda {
http_request(:get, "http://www.example.com/")
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- "Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
end
it "should pass the request to the block" do
@@ -456,8 +443,7 @@ class MyException < StandardError; end;
:body => "wadus").status.should == "200"
lambda {
http_request(:post, "http://www.example.com/", :body => "jander")
- }.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string(
- "Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'jander'"))
+ }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'jander'))
end
end

0 comments on commit 0c904c9

Please sign in to comment.