Dorian
Dorian

Reputation: 2580

Application Controller helper methods not available for Views Specs

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

Answers (4)

bobzsj87
bobzsj87

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

twe4ked
twe4ked

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

David Chelimsky
David Chelimsky

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

Related Questions