While the accepted answer is right, I came here because I wanted to make sure that my application sets a permanent cookie (with a expiration date in the far future) and not a normal one.
If you want to verify that this is the case (and you do not care about the exact expiration date), you can set an expectation like this (the example uses the Mocha gem):
ActionDispatch::Cookies::PermanentCookieJar.any_instance.expects(:[]=).with(:key, "value").once
This expectation will pass with exactly one call of cookies.permanent[:key] = "value"
but will fail for cookies[:key] = "value"
.
It also works for signed cookies (cookies.permanent.signed[:key] = "value"
). However, note that a signed cookie will have its value encrypted based on your application's secret_key_base
, so you will have to adjust the expectation to something like
ActionDispatch::Cookies::PermanentCookieJar.any_instance.expects(:[]=).with(:key, anything).once
instead.