Fetching contributors…
Cannot retrieve contributors at this time
167 lines (103 sloc) 5.99 KB

Show me the cookies

Build Status Gem Version Inline docs endorse

Some helpers for poking around at your Capybara driven browser's cookies in integration tests. Should have been called capybara-cookies if you go by the rubygems naming guide.

Provides drivers for rack-test, selenium-webdriver, Poltergeist (PhantomJS) and capybara-webkit. You may add new drivers for your application by implementing an adapter class and calling ShowMeTheCookies.register_adapter in your test code (e.g. a spec/support file).


  # puts a string summary of the cookie

  # returns a hash of the cookie
  # form: {:name, :domain, :value, :expires, :path}

  # puts a string summary of all cookies

  # returns an array of cookie hashes
  # form: [{:name, :domain, :value, :expires, :path, :secure}]

  # deletes the named cookie

  # removes session cookies and expired persistent cookies
  # creates a cookie
  create_cookie(cookie_name, cookie_value)
  # creates a cookie for the path or domain
  create_cookie(cookie_name, cookie_value, :path => "...", :domain => "...")


Add to your gemfile's test group:

gem "show_me_the_cookies"


in spec_helper/rails_helper or your required support directory:

RSpec.configure do |config|
  config.include ShowMeTheCookies, :type => :feature

Example usage

In a request spec, using Capybara

specify "user login is remembered across browser restarts" do
  #browser restart = session cookie is lost


Install by loading the gem and adding the following to your stepdefs or support files



Scenario: remembering users so they don't have to log in again for a while
  Given I am a site member
  When I go to the dashboard
  And I log in with the Remember Me option checked
  Then I should see "Welcome back"

  When I close my browser (clearing the session)
  And I return to the dashboard url
  Then I should see "Welcome back"

Scenario: don't remember users across browser restarts if they don't want it
  Given I am a site member
  When I go to the dashboard
  And I log in without the Remember Me option checked
  Then I should see "Welcome back"

  When I close my browser (clearing the session)
  And I return to the dashboard url
  Then I should see the log-in screen


Then /^show me the cookies!$/ do

Then /^show me the "([^"]*)" cookie$/ do |cookie_name|

Given /^I close my browser \(clearing the session\)$/ do

Installing your own drivers

Register your adapter class in your test setup after loading the library.

ShowMeTheCookies.register_adapter(driver, adapter)

for example

ShowMeTheCookies.register_adapter(:custom_selenium_a, ShowMeTheCookies::Selenium)

which indicates how to use the selenium adapter with a custom selenium testing profile.

Usage / License / Support

This software is provided free of charge for use at your own risk, see MIT License. If you have trouble making the software work try posting on stackoverflow. If you find a bug or don't understand the documentation open a github issue.


Bugs should be raised in the issue tracker.

Code contributions should be sent as Github pull requests, or by messaging me with a link to your repository branch. Please run the tests, and add new ones.

New drivers will be selectively accepted. Be sure that the api spec passes. If you prefer to keep the driver in your own repository send me the address and I'll add a link in the docs.

Development and running the tests

bundle install
bundle exec rspec

If you get DNS lookup failures try this in the terminal


You should get a quick response of has address

If you don't see this your router or similar is interfering with the DNS for security reasons, blocking a loopback lookup result. You can get around this by changing your DNS server to Google's public DNS service to run the tests. You can turn this off again afterwards. Alternatively you can add an /etc/hosts entry looping back to

History, Credits, and Acknowledgements


Original development took place when testing Devise 0.1's "Remember me" functionality under rails 2.3.x with capybara rack-test and/or selenium. Initial release as a gist here. Development sponsored by Medify.

Contributions outside of github have been made by: