title: Rails + Cucumber/Capybara: How to set/retrieve cookies in tests?
body: <p>I'm implementing a lazy login feature. My cucumber feature should describe it:</p>
  
  <pre><code>    Feature: User log in
  
          Scenario: Lazy login
              Given I didn't log out the last time I was on the site
              When I go to the homepage
              Then I should automatically be logged in 
  </code></pre>
  
  <p>And these are my step definitions:</p>
  
  <pre><code>Given(/^I didn't log out the last time I was on the site$/) do
    user = FactoryGirl.create(:user)
    visit new_user_session_path
    fill_in('user[email]', with: user.email)
    fill_in('user[password]', with: 'test123')
    click_button('Sign in')
  
    Capybara.reset_sessions!
  end
  
  When(/^I go to the homepage$/) do
    visit root_path
  end
  
  Then(/^I should automatically be logged in$/) do #&lt;-- Fails here
    page.should have_content("Logout")
  end
  </code></pre>
  
  <p>This is what happens when a user logs in: the <code>cookies.signed[:auth_token]</code> gets set. This will be used by a before filter in my ApplicationController so that users who open a fresh browser will be logged in automatically:</p>
  
  <pre><code>class SessionsController &lt; Devise::SessionsController
  
  def create
    super
    if user_signed_in?
      puts 'yesssssss'
      session[:user_id] = current_user.id  
      current_user.remember_me! if current_user.remember_token.blank?
      cookies.signed[:auth_token] = {
        :value =&gt; current_user.remember_token,
        :domain =&gt; "mysite.com",
        :secure =&gt; !(Rails.env.test? || Rails.env.development?)
        }
      puts "current_user.remember_token = #{current_user.remember_token}"
      puts 'cookies:'
      puts cookies.signed[:auth_token]
    end
  end
  </code></pre>
  
  <p>end</p>
  
  <p>This is the before filter in my ApplicationController:</p>
  
  <pre><code>def sign_in_through_cookie
    logger.info "logging in by cookie"
    puts "logging in by cookie"
    puts cookies.signed[:auth_token] #&lt;-- PROBLEM: this returns nil.
    return true if !current_user.nil?
    if !cookies[:auth_token].nil? &amp;&amp; cookies[:auth_token] != ''
      user = User.find_by_remember_token(cookies.signed[:auth_token])
      return false if user.blank?
      sign_in(user)
      puts 'success'
      return true
    else
      return false
    end
  end
  </code></pre>
  
  <p>So the issue is that in the last step of my cucumber feature, <code>cookies.signed[:auth_token]</code> returns nil. I'm guessing this is just a capybara thing. So do I actually have to set a cookie in the test as opposed to using the one in my controller?</p>