Created
August 10, 2011 00:21
-
-
Save odf/1135616 to your computer and use it in GitHub Desktop.
Handling cookies in Capybara with Rack::Test so that controllers see them
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
def set_cookie(key, value) | |
# This is how one needs to set cookies in Rack::Test. | |
jar.merge "#{key.to_s}=#{value};domain=#{domain};path=/" | |
end | |
def get_cookie(key) | |
jar[key.to_s] | |
end | |
def jar | |
# Sorry Selenium! | |
driver = Capybara.current_session.driver | |
driver.class.should == Capybara::RackTest::Driver | |
@jar ||= driver.browser.rack_mock_session.cookie_jar | |
end | |
def domain | |
@domain ||= current_host.sub /\A (?:https?:\/\/)? (.*) (?::\d+)? \z/x, '\\1' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment