Testing views with rspec – undefined current_user in helper file when rendering view-Record and share programming errors

I’m using rspec, with devise and trying to test my views. In a helper function which my view calls, I use the variable current_user This works fine in practice, but using rspec, I get a sad ‘undefinied variable or method current_user’ error.

I’ve tried a lot of things that don’t work.

@user = FactoryGirl.build_stubbed(:user)
assign(current_user, @user)
sign_in :user, @user
def current_user
current_user = @user
view.stub!(:current_user).and_return @user
assign[:currrnet_user] = @user

Anyone know how to do this? Thanks in advance.

  1. So, the solution to helper methods is to stub them. I don’t really like this solution, because I see it as a bug, but it is the way to do what needs to be done.

Originally posted 2013-08-31 05:30:27.