You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplify the way we explain how to test cookies in controller
The previous documentation was old and was not clear enough to help
developers to understand properly how to test cookies inside a
controller test. Since then it is much easier to test cookies if you
stick to `cookies` and don't use `response.cookies`.
You can use response.cookies when you don't change cookies inside your
test.
```
def show
cookies["user_name"] = nil
head 200
end
RSpec.describe SignOutsController, type: :request do
describe 'GET /signout' do
it "clear cookie value" do
get "/sign_out"
expect(response.cookies["user_name"]).to eq(nil)
end
end
end
```
Use `cookies` to set and expect when you set cookies inside your test
```
def show
cookies.delete("user_name")
head 200
end
RSpec.describe SignOutsController, type: :request do
describe 'GET /signout' do
it "clear cookie value" do
cookies["user_name"] = "Sam"
get "/sign_out"
expect(cookies["user_name"]).to eq("")
end
end
end
```
This is the prefered way and this is way it is documented like that.
Related:
- #1993
0 commit comments