Normalize access to response headers in adapters

This commit is contained in:
Emrys Ingersoll 2010-02-20 17:06:30 -05:00
parent 56b2f342da
commit 67febe9072
5 changed files with 25 additions and 1 deletions

View File

@ -39,6 +39,10 @@ module Webrat #:nodoc:
@response.code.to_i @response.code.to_i
end end
def response_headers
@response.header
end
def mechanize def mechanize
unless @mechanize unless @mechanize
@mechanize = Mechanize.new @mechanize = Mechanize.new

View File

@ -18,6 +18,10 @@ module Webrat
response.status response.status
end end
def response_headers
response.headers
end
def response def response
@session.last_response @session.last_response
end end

View File

@ -35,6 +35,10 @@ module Webrat
response.code.to_i response.code.to_i
end end
def response_headers
response.headers
end
def xml_content_type? def xml_content_type?
response.headers["Content-Type"].to_s =~ /xml/ response.headers["Content-Type"].to_s =~ /xml/
end end

View File

@ -281,7 +281,7 @@ For example:
end end
def response_location def response_location
response.headers["Location"] response_headers['Location']
end end
def current_host def current_host

View File

@ -78,4 +78,16 @@ describe Webrat::MechanizeAdapter do
@session.absolute_url(relative_url).should == 'https://test.host/wilma' @session.absolute_url(relative_url).should == 'https://test.host/wilma'
end end
end end
describe "response_headers" do
it "should return the Headers object from the response" do
mech = @mech.mechanize
resp = mock('Mechanize::File')
hdr = Mechanize::Headers.new
resp.should_receive(:header).and_return(hdr)
mech.stub!(:get).and_return(resp)
@mech.get('/', nil)
@mech.response_headers.should == hdr
end
end
end end