RSpec request object is zero

I am trying to check cookies in my request specification:

require 'spec_helper' describe "Cookies" it "should set correctly" do request.cookies['foo'] = 'bar' end end 

But it gives me an undefined method 'cookies' for nil:NilClass . How to fix it?

+4
source share
1 answer

The request object will not be present inside your test case until you make an HTTP request using one of the get , post , delete , put , etc. methods.

For example, your code will work if you were preceded by request.cookies['foo'] = 'bar' using get root_path .

+7
source

Source: https://habr.com/ru/post/1443517/


All Articles