From 67febe9072fd8f1f622d547267c778d210138da7 Mon Sep 17 00:00:00 2001 From: Emrys Ingersoll Date: Sat, 20 Feb 2010 17:06:30 -0500 Subject: [PATCH] Normalize access to response headers in adapters --- lib/webrat/adapters/mechanize.rb | 4 ++++ lib/webrat/adapters/rack.rb | 4 ++++ lib/webrat/adapters/rails.rb | 4 ++++ lib/webrat/core/session.rb | 2 +- spec/private/mechanize/mechanize_adapter_spec.rb | 12 ++++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/webrat/adapters/mechanize.rb b/lib/webrat/adapters/mechanize.rb index bc79466..84f9fe1 100644 --- a/lib/webrat/adapters/mechanize.rb +++ b/lib/webrat/adapters/mechanize.rb @@ -39,6 +39,10 @@ module Webrat #:nodoc: @response.code.to_i end + def response_headers + @response.header + end + def mechanize unless @mechanize @mechanize = Mechanize.new diff --git a/lib/webrat/adapters/rack.rb b/lib/webrat/adapters/rack.rb index 89f938d..3611846 100644 --- a/lib/webrat/adapters/rack.rb +++ b/lib/webrat/adapters/rack.rb @@ -18,6 +18,10 @@ module Webrat response.status end + def response_headers + response.headers + end + def response @session.last_response end diff --git a/lib/webrat/adapters/rails.rb b/lib/webrat/adapters/rails.rb index 1d4264c..fadb423 100644 --- a/lib/webrat/adapters/rails.rb +++ b/lib/webrat/adapters/rails.rb @@ -35,6 +35,10 @@ module Webrat response.code.to_i end + def response_headers + response.headers + end + def xml_content_type? response.headers["Content-Type"].to_s =~ /xml/ end diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 939771b..07d86cb 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -281,7 +281,7 @@ For example: end def response_location - response.headers["Location"] + response_headers['Location'] end def current_host diff --git a/spec/private/mechanize/mechanize_adapter_spec.rb b/spec/private/mechanize/mechanize_adapter_spec.rb index 6c3dff2..aa7fc32 100644 --- a/spec/private/mechanize/mechanize_adapter_spec.rb +++ b/spec/private/mechanize/mechanize_adapter_spec.rb @@ -78,4 +78,16 @@ describe Webrat::MechanizeAdapter do @session.absolute_url(relative_url).should == 'https://test.host/wilma' 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