I’m trying to test for cookies in my request spec:
require 'spec_helper'
describe "Cookies"
it "should set correctly" do
request.cookies['foo'] = 'bar'
end
end
But this gives me undefined method 'cookies' for nil:NilClass. How do I fix this?
The
requestobject will be nil inside your test case until you make an http request using one of the methodsget,post,delete,put, etc.For example, your code would work if you had preceded
request.cookies['foo'] = 'bar'withget root_path.