bevanb
bevanb

Reputation: 8511

Rails/rspec: how to set cookies in a request spec?

How do I set cookies in my request specs?

The solutions on the following page did not work:

Rspec: setting cookies in a helper test

Namely, request.cookies[:whatever] = 'something' says that request is a nil object. I also tried helper.cookies[:whatever] = 'something', and that also did not work (helper in that case was nil).

Upvotes: 10

Views: 3914

Answers (2)

Connor
Connor

Reputation: 806

Try just the following:

cookies[:whatever] = 'something'

Upvotes: 5

ifightcrime
ifightcrime

Reputation: 1302

Make sure you are using the rspec-rails gem and are requiring 'rspec/rails' in your spec_helper, not just 'rspec'.

Upvotes: -2

Related Questions