[FIXED]: RSPEC: controller.current_user gives you: ArgumentError: wrong number of arguments (given 1, expected 2)
We upgraded ruby to 3.4.x and rails to 8.x.x and found this new error in our specs:

Upon further looking at it, what was causing it was some internal calls to warden and devise. This command would fail in byebug, or in rspec:
controller.current_userBut re-logging in would fix it, so one of the proposed solutions was this in a `before` action:
before do
setup_users :sign_in_role => Role::ROLE_ADMIN
controller.current_user rescue setup_users({ :sign_in_role => Role::ROLE_ADMIN }) ## adding this line fixed it
endLooking at this github comment thread, we see a different proposed solution/workaround:
RSpec.configure do |config|
config.before(:suite) do
Rails.application.try(:reload_routes_unless_loaded)
end
endAnd that's the solution we went with, since it's the cleaner of the two.
.^.

Related Articles
Please log in to post comments:
Login with Google