title: When I set a cookie in the controller, why can't Poltergeist read it?
body: <p>I want to test that a controller sets a cookie. I have a controller</p>
  
  <pre><code># app/controllers/home_controller.rb
  class HomeController &lt; ApplicationController
    def index
      cookies[:foo] = "bar"
      head :ok
    end
  end
  
  # config/routes.rb
  Rails.application.routes.draw do
    root to: "home#index"
  end
  </code></pre>
  
  <p>When I write a test</p>
  
  <pre><code>require "capybara/poltergeist"
  
  class CookieTest &lt; ActionDispatch::IntegrationTest
    include Capybara::DSL
  
    setup do
      Capybara.current_driver = :poltergeist
    end
  
    test "cookies" do
      visit "/"
      page.driver.cookies #=&gt; {}
    end
  end
  </code></pre>
  
  <p>The cookies are blank, even though <code>HomeController</code> set a cookie. Why is that? When I visit the same page with my browser, then the cookie is indeed set (I ran <code>document.cookie</code> in the JavaScript console).</p>