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
Instead of including the helper module inside the controller you can use the ActionController::Base. helpers available inside your action to have access to every helper method you use inside your views!
A helper is a method that is (mostly) used in your Rails views to share reusable code. Rails comes with a set of built-in helper methods. One of these built-in helpers is time_ago_in_words . This method is helpful whenever you want to display time in this specific format.
Basically helpers in Rails are used to extract complex logic out of the view so that you can organize your code better.
You can stub out the method on view
.
view.stub(:current_user).and_return(user)
This will also work in helper specs.
Controller-defined helper methods are not included in the helper object.
http://relishapp.com/rspec/rspec-rails/dir/helper-specs/helper-spec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With