Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing cookies in request spec

I'm trying to pass a cookie when doing a GET request, using rspec 2 and rails 3.

I've tried the following so far.

get "/", {}, {"Cookie" => "uuid=10"} # cookies[:uuid] is nil
request.cookies[:uuid] = 10 # request is nil
@request.env["Cookie"] = "uuid=10" # @request is nil
helper.request.cookies[:uuid] # helper is not defined
cookies[:uuid] = 10 # cookies[:uuid] is nil
controller.cookies[:uuid] = 10 # cookies is nil

Is it possible?

like image 881
Linus Oleander Avatar asked Jul 03 '12 00:07

Linus Oleander


1 Answers

Per this answer, you can use the cookies method within request specs:

before { cookies['foo'] = 'bar' }

I tried @phoet's solution involving ActionDispatch::Request.any_instance.stubs, but it throws an error along with a seemingly unrelated deprecation message in RSpec 3.4.

like image 71
Chris Peters Avatar answered Oct 16 '22 10:10

Chris Peters