开发者

Application Controller helper methods not available for Views Specs

开发者 https://www.devze.com 2023-03-06 19:45 出处:网络
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)

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

精彩评论

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