Reputation: 1472
As the title states, I'm upgrading a project to Rails 5 and Rspec 3 from 4.2 and 2, respectively. All tests passed before the upgrade, but now the view helper spec for the application controller is giving me an error.
In the spec lives this code:
allow(helper).to receive(:current_user).and_return(login_session)
But attempting to run this line gives an error:
*helper object* does not implement: current_user
There is an authentication module that sets up current_user, and it is included in the application controller.
def current_user
@current_user ||= session[:login_session]
@current_user ||= LoginSession.new
return @current_user
end
This code works unmodified in the older versions, and searches suggest that this is the correct implementation. What could be causing this?
Upvotes: 0
Views: 1073
Reputation: 1418
In Rails 5 projects, I use the following syntax (might make a difference to stub the controller instead of the helper):
allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(login_session)
Upvotes: 1