[rspec-users] Rack::Test + cookies + rspec

Nicholas Wieland nicholas.wieland at gmail.com
Fri Apr 16 09:07:30 EDT 2010

Hi *,
I need to test cookie creation with rspec and using Rack::Test, but for some reason I'm not able to pair the real app that creates a cookie with the rspec tests.
The spec is like this:

  it "should authenticate using cookies" do
    user = Factory.create :user
    remember_token = Charon.make_remember_token
    set_cookie "warden=#{ remember_token }"
    user.update :remember_token => remember_token
    post '/authenticate'
    last_request.env[ 'warden' ].should be_authenticated

Inside the main app I set the cookie like:

  if !request.cookies[ 'warden' ]
    response.set_cookie( 'warden', :value => env[ 'warden' ].user.remember_token )

I can clearly see it works when testing manually. For some reasons, the rspec cookie is different than the one set by the app.

Is someone trying something similar and can share some code ? I think that the problem is in Rack::Test but I'm not sure and I'm not able prove it.


More information about the rspec-users mailing list