Merge remote branch 'wemrysi/master' into mechanize_redirects

Conflicts:
	lib/webrat/adapters/mechanize.rb
This commit is contained in:
Damian Janowski 2010-04-13 12:01:22 -03:00
commit 38e699820f
5 changed files with 42 additions and 3 deletions

View File

@ -41,8 +41,16 @@ module Webrat #:nodoc:
@response.code.to_i
end
def response_headers
@response.header
end
def mechanize
@mechanize ||= Mechanize.new
@mechanize ||= begin
mechanize = Mechanize.new
mechanize.redirect_ok = false
mechanize
end
end
def_delegators :mechanize, :basic_auth

View File

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

View File

@ -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

View File

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

View File

@ -1,6 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe Webrat::MechanizeAdapter do
Mechanize = WWW::Mechanize if defined?(WWW::Mechanize)
before :each do
Webrat.configuration.mode = :mechanize
end
@ -9,6 +12,13 @@ describe Webrat::MechanizeAdapter do
@mech = Webrat::MechanizeAdapter.new
end
describe "mechanize" do
it "should disable the following of redirects on the mechanize instance" do
mech = @mech.mechanize
mech.redirect_ok.should be_false
end
end
describe "post" do
def url
'http://test.host/users'
@ -24,7 +34,8 @@ describe Webrat::MechanizeAdapter do
it "should flatten model post data" do
mechanize = mock(:mechanize)
WWW::Mechanize.stub!(:new => mechanize)
mechanize.stub!(:redirect_ok=)
Mechanize.stub!(:new => mechanize)
mechanize.should_receive(:post).with(url, flattened_data)
Webrat::MechanizeAdapter.new.post(url, data)
end
@ -70,4 +81,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