title: Capybara & Cucumber | Getting cookies
body: <p>I'm trying to get cookie values in the Cucumber step:</p>
  
  <p><strong>Step definitions</strong></p>
  
  <pre class="lang-rb prettyprint-override"><code>When /^I log in$/ do
    # code to log in
  end
  
  Then /^cookies should be set$/ do
    cookies[:author].should_not be_nil
  end
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre class="lang-rb prettyprint-override"><code>class SessionsController &lt; ApplicationController
    def create
      cookies[:author] = 'me'
      redirect_to authors_path
    end
  end
  </code></pre>
  
  <p>But it doesn't work:</p>
  
  <p><strong>Result</strong></p>
  
  <pre><code>expected: not nil
       got: nil
  </code></pre>
  
  <p>In the RSpec examples, all works just fine:</p>
  
  <p><strong>Controller Spec</strong></p>
  
  <pre class="lang-rb prettyprint-override"><code>require 'spec_helper'
  
  describe SessionsController do
    describe 'create' do
      it 'sets cookies' do
        post :create
        cookies[:author].should_not be_nil
      end
    end
  end
  </code></pre>
  
  <p>How can I get cookie values in Cucumber steps using Capybara?</p>
  
  <p>Thanks.</p>
  
  <p>Debian GNU/Linux 6.0.4;</p>
  
  <p>Ruby 1.9.3;</p>
  
  <p>Ruby on Rails 3.2.1;</p>
  
  <p>Cucumber 1.1.4;</p>
  
  <p>Cucumber-Rails 1.2.1;</p>
  
  <p>Capybara 1.1.2;</p>
  
  <p>Rack-Test 0.6.1.</p>