0

I need to test a page in my Rails 5.2 app that displays the current cart if the user is not logged with Capybara system test. The app retrieves the cart by the card_id saved in the rails session (session[:cart_id] = @cart.id)

My test looks like this:

require 'application_system_test_case'

class CartUiTest < ApplicationSystemTestCase
  def setup
    @cart = create(:cart)
  end

  test 'show cart also if user is not logged' do
    visit edit_cart_path

    assert_text "Some text"
  end
end

How can I set the session in this test? I've tried the gem rack_session_access but I'm looking for another solution that not use this gem because it conflicts with other tests.

Pioz
  • 6,051
  • 4
  • 48
  • 67

1 Answers1

0

You shouldn't be directly accessing the session in system tests. If you want a user that has a session that has logged out, start by logging in the user and then log them out. That way the browser will have the cookie that corresponds to a logged out session just like a real user would.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78