0.0
The project is in a healthy, maintained state
TestyCookie provides a helper to access plain, permanent, signed and encrypted cookies in Rails controller / integration / request tests.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 7.0.0
 Project Readme

TestyCookie

TestyCookie gem provides a helper for accessing plain, permanent, signed, and encrypted cookies in Rails controller, integration, and request tests.

Why do I need a custom helper?

In Rails, ActionDispatch::IntegrationTest based tests and RSpec request specs do not provide encrypted, permanent and signed stores when the default cookies helper is used (it returns Rack::Test::CookieJar instance). TestyCookie resolves this limitation by initializing a proper ActionDispatch::Cookies::CookieJar instance which support these stores. The included helper also propagates any changes back to the original Rack::Test::CookieJar instance making them correctly read in application controllers.

In ActionController::TestCase tests and RSpec controller specs, cookie_jar serves as an alias for the default cookies method which returns ActionDispatch::Cookies::CookieJar instance correctly.

Usage

Inside your controller / integration / request test, call cookie_jar helper to access cookies:

cookie_jar.encrypted[:key]
cookie_jar.signed[:key] = value
cookie_jar.signed.encrypted.permanent[:key] = value

Installation

Add this line to your application's Gemfile:

gem "testy_cookie"

And then execute:

$ bundle

License

The gem is available as open source under the terms of the MIT License.