jeudi 27 février 2020

Change Rails session for tests with Capybara

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.

Aucun commentaire:

Enregistrer un commentaire