Skip to content

Instantly share code, notes, and snippets.

@triskweline
Forked from JonRowe/gist:464323
Created July 7, 2010 07:18
Show Gist options
  • Save triskweline/466411 to your computer and use it in GitHub Desktop.
Save triskweline/466411 to your computer and use it in GitHub Desktop.
# 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