[rspec-users] cookies

Jerry West jerry.west at ntlworld.com
Mon Mar 19 07:38:12 EDT 2007

How do I set cookies in a spec so I can see them in my controller, please?

Conversely, why doesn't this work...

require File.dirname(__FILE__) + '/../spec_helper'

class TestApplicationController < ApplicationController
   def index
     @seen = cookies['auth_token'] || 'NOT seen!'
     puts cookies.inspect	# {"auth_token"=>42}, see below
     render :text => 'testing'   # don't look for view

context 'All controllers (via ApplicationController)...' do
   controller_name :test_application

   specify 'should see cookie' do
     request.cookies['auth_token'] = 42
     get :index
     assigns['seen'].should eql(42)

clean$ spec -cfs spec/controllers/

All controllers (via ApplicationController)...
- should allow access to url with proper cookie (FAILED - 1)

1) 'All controllers (via ApplicationController)... should see cookie' FAILED
expected 42, got "NOT seen!" (using .eql?)

Finished in 0.143717 seconds

1 specification, 1 failure

Is it something to do with 
and if so, is there a workaround?

Many thanks,

More information about the rspec-users mailing list