Created
February 29, 2012 07:17
-
-
Save pat/1938821 to your computer and use it in GitHub Desktop.
Quick hack: A Capybara that you can tell not to auto-follow redirects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "does not have to auto-follow redirects", :driver => :tito_driver do | |
page.driver.stop_following_redirects | |
# make a web request that redirects | |
# do whatever you need to do | |
# the continue... | |
page.driver.follow_redirects! | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I put this in spec/support/ | |
class Tito::Driver < Capybara::RackTest::Driver | |
def initialize(app, options = {}) | |
super | |
@follow_redirects = true | |
end | |
def browser | |
@browser ||= Tito::Browser.new(self) | |
end | |
def follow_redirects? | |
@follow_redirects | |
end | |
def follow_redirects! | |
@follow_redirects = true | |
browser.follow_redirects! | |
end | |
def stop_following_redirects | |
@follow_redirects = false | |
end | |
end | |
class Tito::Browser < Capybara::RackTest::Browser | |
def follow_redirects! | |
super if driver.follow_redirects? | |
end | |
end | |
Capybara.register_driver :tito_driver do |app| | |
Tito::Driver.new app | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment