Skip to content

Instantly share code, notes, and snippets.

@brianjlandau
Created November 7, 2012 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianjlandau/4033602 to your computer and use it in GitHub Desktop.
Save brianjlandau/4033602 to your computer and use it in GitHub Desktop.
Visit a location in a Capybara rspec spec without following a redirect.
# ...
RSpec.configure do |config|
# ...
config.include VisitWithoutRedirectsHelper, :type => :request
# ...
end
module VisitWithoutRedirectsHelper
def redirected_url
page.response_headers["Location"]
end
# This replicates the normal #visit method in capybara but does not follow any redirects.
# This is useful when needing to check redirects to external sites.
def visit_without_redirects(url)
page.driver.browser.reset_host!
page.driver.browser.process(:get, url, {})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment