Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'wemrysi/master' into mechanize_redirects

Conflicts:
	lib/webrat/adapters/mechanize.rb
  • Loading branch information...
commit 38e699820f841ee69d893071720ee9dc288acece 2 parents 4c62279 + 67febe9
@djanowski djanowski authored
View
10 lib/webrat/adapters/mechanize.rb
@@ -41,8 +41,16 @@ def response_code
@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
4 lib/webrat/adapters/rack.rb
@@ -18,6 +18,10 @@ def response_code
response.status
end
+ def response_headers
+ response.headers
+ end
+
def response
@session.last_response
end
View
4 lib/webrat/adapters/rails.rb
@@ -35,6 +35,10 @@ def response_code
response.code.to_i
end
+ def response_headers
+ response.headers
+ end
+
def xml_content_type?
response.headers["Content-Type"].to_s =~ /xml/
end
View
2  lib/webrat/core/session.rb
@@ -282,7 +282,7 @@ def process_request(http_method, url, data, headers)
end
def response_location
- response.headers["Location"]
+ response_headers['Location']
end
def current_host
View
25 spec/private/mechanize/mechanize_adapter_spec.rb
@@ -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 @@
@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 @@ def flattened_data
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 @@ def relative_url
@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
Please sign in to comment.
Something went wrong with that request. Please try again.