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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user