Skip to content

Simplify the way we explain how to test cookies in controller #2127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions features/controller_specs/Cookies.md

This file was deleted.

36 changes: 36 additions & 0 deletions features/controller_specs/cookies.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Feature: Cookies

There are different ways to make assertions on cookies from controller specs,
but we recommend using the `cookies` method as set out below.

You can use strings or symbols to fetch or set your cookies because the `cookies`
method supports indifferent access.

Scenario: Testing cookie's value cleared in controller
Given a file named "spec/controllers/application_controller_spec.rb" with:
"""ruby
require "rails_helper"

RSpec.describe ApplicationController, :type => :controller do
controller do
def clear_cookie
cookies.delete(:user_name)
head :ok
end
end

before do
routes.draw { get "clear_cookie" => "anonymous#clear_cookie" }
end

it "clear cookie's value 'user_name'" do
cookies[:user_name] = "Sam"

get :clear_cookie

expect(cookies[:user_name]).to eq nil
end
end
"""
When I run `rspec spec`
Then the example should pass