Reputation: 2580
I have a helper method called current_user
in my Application Controller (used with Authlogic).
Spec for views using that helper fail (but the view is working when i use the browser)
ActionView::Template::Error: undefined local variable or method 'current_user' for #<#<Class:0x0000000229b060>:0x00000002004248>
I use rspec 2.6.0.
Anyone had the same problem? Please advice. Thanks
Upvotes: 12
Views: 5659
Reputation: 818
Check out this one: http://apidock.com/rails/ActionController/Helpers/ClassMethods/helper_method.
You can define helper inside the ApplicationController, and use it across the controllers AND views.
Upvotes: 0
Reputation: 2892
You can stub out the method on view
.
view.stub(:current_user).and_return(user)
This will also work in helper specs.
Upvotes: 11
Reputation: 9000
Controller-defined helper methods are not included in the helper object.
http://relishapp.com/rspec/rspec-rails/dir/helper-specs/helper-spec
Upvotes: 4