[rspec-users] Stub a controllers helper_method in a view template helper spec
dchelimsky at gmail.com
Mon Mar 21 07:36:22 EDT 2011
On Mar 21, 2011, at 5:41 AM, Kai Schlamp wrote:
> My ApplicationController exposes a method (e.g. sort_direction) to the
> view templates by using
> helper_method :sort_direction.
> I then use this method in another method (e.g. sort_link) in a view
> helper (application_helper.rb).
> When testing the sort_link method with RSpec (in
> application_helper_spec.rb) I have to stub sort_direction as the test
> seems to run completely independent from the controllers (and thereby
> by to the view templates exposed methods).
> Unfortunately I could not find out how to stub that sort_direction
> method of the controller. I always get "undefined method".
> Here is what I tried so far (inside application_helper_spec.rb):
This ^^ should work.
> Here the error I get:
> undefined method `sort_direction' for
This error ^^ suggests that sort_direction is being called on the example itself rather than the helper object. Please post the spec so we can see what's going on.
More information about the rspec-users