Created
November 27, 2010 11:33
-
-
Save raul/717819 to your computer and use it in GitHub Desktop.
Set request headers in Capybara+RackTest
This file contains hidden or 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
# Patch to support customized request headers in your Capybara tests | |
# when you're using the RackTest driver, based on an Aslak Hellesøy's gist: | |
# https://gist.github.com/358664 | |
# | |
# Please note that some drivers don't allow access to headers, see: | |
# https://github.com/jnicklas/capybara/issuesearch?state=closed&q=header#issue/17 | |
class Capybara::Driver::RackTest < Capybara::Driver::Base | |
def env | |
@env | |
end | |
def set_headers(headers) | |
@env = env.nil? ? headers : env.merge(headers) | |
end | |
end | |
class Capybara::Session | |
def set_headers(headers) | |
if driver.respond_to?(:set_headers) | |
driver.set_headers headers | |
else | |
raise Capybara::NotSupportedByDriverError | |
end | |
end | |
end | |
# Steak sample test: | |
scenario "..." do | |
page.set_headers({"HTTP_ACCEPT_LANGUAGE" => "es" }) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it should be Capybara::RackTest::Driver