开发者

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.

Any开发者_如何学Pythonone had the same problem? Please advice. Thanks


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


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.


check right documentation for specs view

https://www.relishapp.com/rspec/rspec-rails/v/2-14/docs/view-specs/view-spec#passing-view-spec-that-stubs-a-helper-method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜