Add method to stub current_user in component tests

We're choosing `sign_in` instead of `login_as` because IMHO component
tests are more similar to controller tests than they are to system
tests.
This commit is contained in:
Javi Martín
2021-09-04 15:30:04 +02:00
parent 4cbf945228
commit e97c375063
11 changed files with 30 additions and 31 deletions

View File

@@ -13,6 +13,14 @@ require "capybara/rspec"
require "selenium/webdriver"
require "view_component/test_helpers"
module ViewComponent
module TestHelpers
def sign_in(user)
allow(controller).to receive(:current_user).and_return(user)
end
end
end
RSpec.configure do |config|
config.include ViewComponent::TestHelpers, type: :component
end