Cookies in RSpec

So how do you work with cookies properly in rspec now? I noticed in
the docs that it mentions session, assigns, and flash, but nothing of
cookie. I’m using edge rails so I’m concerned about changes to the
cookie mechanisms. I need to assign values into the cookie (a
remember token for restful authentication) so that I can have it log
in by cookie. here is my spec for it:

http://pastie.caboo.se/103647

I’m using AR-stored-sessions, if that matters.

Nate

On 10/4/07, Nathan S. [email protected] wrote:

Nate


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Hi Nate,

I’m mocking cookies like this:

it “should clean cookie with remember_token” do
cookies = mock(‘cookies’)
cookies.stub!(:[])
controller.stub!(:cookies).and_return(cookies)

cookies.should_receive(:delete).with(:remember_token)
delete :destroy

end

def destroy
current_user.forget_me
cookies.delete :remember_token
reset_session
redirect_to home_path
end

You can stub writing part like this:
cookies.stub!(:[]=)

I have got some nice ideas from caboo’s empty rspec app:
http://plugins.svn.caboo.se/browser/court3nay/empty_apps/restful_auth_rspec

Priit