Skip to content

Commit

Permalink
Removed validation of the whole error message in webmock adapter spec…
Browse files Browse the repository at this point in the history
… with client specific headers validation as it didn't help in any way.
  • Loading branch information
bblimke committed Nov 10, 2010
1 parent b175c1a commit 0c904c9
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 73 deletions.
4 changes: 0 additions & 4 deletions spec/curb_spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ def setup_request(uri, curl, options={})
curl curl
end end


def default_client_request_headers(request_method = nil, has_body = false)
nil
end

def client_timeout_exception_class def client_timeout_exception_class
Curl::Err::TimeoutError Curl::Err::TimeoutError
end end
Expand Down
4 changes: 0 additions & 4 deletions spec/em_http_request_spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ def connection_refused_exception_class
"" ""
end end


def default_client_request_headers(request_method = nil, has_body = false)
nil
end

def setup_expectations_for_real_request(options = {}) def setup_expectations_for_real_request(options = {})
end end


Expand Down
4 changes: 0 additions & 4 deletions spec/httpclient_spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ def connection_refused_exception_class
Errno::ECONNREFUSED Errno::ECONNREFUSED
end 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 = {}) def setup_expectations_for_real_request(options = {})
socket = mock("TCPSocket") socket = mock("TCPSocket")
TCPSocket.should_receive(:new). TCPSocket.should_receive(:new).
Expand Down
7 changes: 0 additions & 7 deletions spec/net_http_spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ def http_request(method, uri, options = {}, &block)
}) })
end 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 def client_timeout_exception_class
Timeout::Error Timeout::Error
end end
Expand Down
8 changes: 0 additions & 8 deletions spec/patron_spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ def http_request(method, uri, options = {}, &block)
}) })
end 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 def client_timeout_exception_class
Patron::TimeoutError Patron::TimeoutError
end end
Expand Down
16 changes: 0 additions & 16 deletions spec/spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,19 +47,3 @@ def setup_expectations_for_real_example_com_request(options = {})
setup_expectations_for_real_request(defaults.merge(options)) setup_expectations_for_real_request(defaults.merge(options))
end 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

46 changes: 16 additions & 30 deletions spec/webmock_shared.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MyException < StandardError; end;
it "should raise exception if request was not stubbed" do it "should raise exception if request was not stubbed" do
lambda { lambda {
http_request(:get, "http://www.example.com/") 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
end end


Expand All @@ -84,7 +84,7 @@ class MyException < StandardError; end;
it "should raise exception if request was not stubbed" do it "should raise exception if request was not stubbed" do
lambda { lambda {
http_request(:get, "http://www.example.com/") 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


it "should allow a real request to localhost" do it "should allow a real request to localhost" do
Expand Down Expand Up @@ -119,7 +119,7 @@ class MyException < StandardError; end;
it "should raise exception if request was not stubbed" do it "should raise exception if request was not stubbed" do
lambda { lambda {
http_request(:get, "http://www.example.com/") 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


it "should allow a real request to allowed host", :net_connect => true do it "should allow a real request to allowed host", :net_connect => true do
Expand Down Expand Up @@ -180,8 +180,7 @@ class MyException < StandardError; end;
http_request(:get, "http://www.example.com/").status.should == "200" http_request(:get, "http://www.example.com/").status.should == "200"
lambda { lambda {
http_request(:delete, "http://www.example.com/") http_request(:delete, "http://www.example.com/")
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: DELETE http://www.example.com/)
"Real HTTP connections are disabled. Unregistered request: DELETE http://www.example.com/")
) )
end end


Expand All @@ -207,8 +206,7 @@ class MyException < StandardError; end;
stub_http_request(:post, "www.example.com").with(:body => "abc") stub_http_request(:post, "www.example.com").with(:body => "abc")
lambda { lambda {
http_request(:post, "http://www.example.com/", :body => "def") http_request(:post, "http://www.example.com/", :body => "def")
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'def'))
"Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'def'"))
end end


describe "with regular expressions" do describe "with regular expressions" do
Expand All @@ -224,8 +222,7 @@ class MyException < StandardError; end;
stub_http_request(:post, "www.example.com").with(:body => /^abc/) stub_http_request(:post, "www.example.com").with(:body => /^abc/)
lambda { lambda {
http_request(:post, "http://www.example.com/", :body => "xabc") http_request(:post, "http://www.example.com/", :body => "xabc")
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'xabc'))
"Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'xabc'"))
end end


end end
Expand Down Expand Up @@ -255,9 +252,7 @@ class MyException < StandardError; end;
http_request( http_request(
:post, "http://www.example.com/", :post, "http://www.example.com/",
:body => 'c[d][]=f&a=1&c[d][]=e').status.should == "200" :body => 'c[d][]=f&a=1&c[d][]=e').status.should == "200"
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.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'))
"Real HTTP connections are disabled. Unregistered request: "+
"POST http://www.example.com/ with body 'c[d][]=f&a=1&c[d][]=e'"))
end end


end end
Expand Down Expand Up @@ -343,8 +338,7 @@ class MyException < StandardError; end;
http_request( http_request(
:get, "http://www.example.com/", :get, "http://www.example.com/",
:headers => {"a" => ["b", "d"]}) :headers => {"a" => ["b", "d"]})
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'A'=>['b', 'd']})))
end end


end end
Expand All @@ -363,8 +357,7 @@ class MyException < StandardError; end;
http_request( http_request(
:get, "http://www.example.com/", :get, "http://www.example.com/",
:headers => { 'Content-Length' => '9999'}) :headers => { 'Content-Length' => '9999'})
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'Content-Length'=>'9999'})))
end end


it "should not match if accept header is different" do it "should not match if accept header is different" do
Expand All @@ -374,8 +367,7 @@ class MyException < StandardError; end;
http_request( http_request(
:get, "http://www.example.com/", :get, "http://www.example.com/",
:headers => { 'Accept' => 'application/xml'}) :headers => { 'Accept' => 'application/xml'})
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'Accept'=>'application/xml'})))
end end


describe "with regular expressions" do describe "with regular expressions" do
Expand All @@ -394,8 +386,7 @@ class MyException < StandardError; end;
http_request( http_request(
:get, "http://www.example.com/", :get, "http://www.example.com/",
:headers => { 'user-agent' => 'xMyAppName' }) :headers => { 'user-agent' => 'xMyAppName' })
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers {'User-Agent'=>'xMyAppName'})))
end end


end end
Expand All @@ -412,24 +403,21 @@ class MyException < StandardError; end;
stub_http_request(:get, "user:pass@www.example.com") stub_http_request(:get, "user:pass@www.example.com")
lambda { lambda {
http_request(:get, "http://user:pazz@www.example.com/").status.should == "200" http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
%q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/)))
end end


it "should not match if credentials are stubbed but not provided in the request" do it "should not match if credentials are stubbed but not provided in the request" do
stub_http_request(:get, "user:pass@www.example.com") stub_http_request(:get, "user:pass@www.example.com")
lambda { lambda {
http_request(:get, "http://www.example.com/").status.should == "200" http_request(:get, "http://www.example.com/").status.should == "200"
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
%q(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/)))
end end


it "should not match if credentials are not stubbed but exist in the request" do it "should not match if credentials are not stubbed but exist in the request" do
stub_http_request(:get, "www.example.com") stub_http_request(:get, "www.example.com")
lambda { lambda {
http_request(:get, "http://user:pazz@www.example.com/").status.should == "200" http_request(:get, "http://user:pazz@www.example.com/").status.should == "200"
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/))
%q(Real HTTP connections are disabled. Unregistered request: GET http://user:pazz@www.example.com/)))
end end


end end
Expand All @@ -445,8 +433,7 @@ class MyException < StandardError; end;
stub_http_request(:get, "www.example.com").with { |request| false } stub_http_request(:get, "www.example.com").with { |request| false }
lambda { lambda {
http_request(:get, "http://www.example.com/") http_request(:get, "http://www.example.com/")
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
"Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
end end


it "should pass the request to the block" do it "should pass the request to the block" do
Expand All @@ -456,8 +443,7 @@ class MyException < StandardError; end;
:body => "wadus").status.should == "200" :body => "wadus").status.should == "200"
lambda { lambda {
http_request(:post, "http://www.example.com/", :body => "jander") http_request(:post, "http://www.example.com/", :body => "jander")
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string( }.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'jander'))
"Real HTTP connections are disabled. Unregistered request: POST http://www.example.com/ with body 'jander'"))
end end


end end
Expand Down

0 comments on commit 0c904c9

Please sign in to comment.