File: cookies.feature

package info (click to toggle)
ruby-rspec-rails 7.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,796 kB
  • sloc: ruby: 11,068; sh: 198; makefile: 6
file content (36 lines) | stat: -rw-r--r-- 1,029 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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