Skip to content

Instantly share code, notes, and snippets.

@pat
Created February 29, 2012 07:17
Show Gist options
  • Save pat/1938821 to your computer and use it in GitHub Desktop.
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
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
# 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