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
).
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.
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.
Try just the following:
cookies[:whatever] = 'something'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With