Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 893
bevanb Avatar asked Aug 15 '12 00:08

bevanb


People also ask

What is a request spec?

Request specs provide a thin wrapper around Rails' integration tests, and are. designed to drive behavior through the full stack, including routing. (provided by Rails) and without stubbing (that's up to you). Request specs are marked by :type => :request or if you have set. config.

What is RSpec Rails gem?

RSpec is a testing framework written in Ruby to test Ruby code. To get started using RSpec with Rails, add it to the Gemfile. group :development, :test do gem 'rspec-rails' end. Next finish setting it up by running bundle install in your project directory and then. rails generate rspec:install.


1 Answers

Try just the following:

cookies[:whatever] = 'something'
like image 172
Connor Avatar answered Sep 19 '22 03:09

Connor