-
-
Save triskweline/466411 to your computer and use it in GitHub Desktop.
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
# Copy this to features/support/ssl_fix.rb to make Capybara work with sites that switch between HTTP and HTTPS | |
module Capybara::Driver::RackTest::SslFix | |
[:get, :post, :put, :delete].each do |method| | |
define_method method do |*args| | |
args[0] = path_to_ssl_aware_url(args[0]) | |
super(*args) | |
end | |
end | |
private | |
def path_to_ssl_aware_url(path) | |
unless path =~ /:\/\// | |
env = request.env | |
path = "#{env["rack.url_scheme"]}://#{env["SERVER_NAME"]}#{path}" | |
end | |
path | |
rescue Rack::Test::Error | |
# no request yet | |
path | |
end | |
end | |
Capybara::Driver::RackTest.send :include, Capybara::Driver::RackTest::SslFix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment