Skip to content

Instantly share code, notes, and snippets.

@raul
Created November 27, 2010 11:33
Show Gist options
  • Save raul/717819 to your computer and use it in GitHub Desktop.
Save raul/717819 to your computer and use it in GitHub Desktop.
Set request headers in Capybara+RackTest
# 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
@sardaukar
Copy link

it should be Capybara::RackTest::Driver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment