10

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).

Community
  • 1
  • 1
bevanb
  • 8,201
  • 10
  • 53
  • 90

2 Answers2

5

Try just the following:

cookies[:whatever] = 'something'
Connor
  • 796
  • 11
  • 16
-2

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

ifightcrime
  • 1,216
  • 15
  • 18