Created
November 7, 2012 18:53
-
-
Save brianjlandau/4033602 to your computer and use it in GitHub Desktop.
Visit a location in a Capybara rspec spec without following a redirect.
This file contains 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
# ... | |
RSpec.configure do |config| | |
# ... | |
config.include VisitWithoutRedirectsHelper, :type => :request | |
# ... | |
end |
This file contains 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
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