Lock the controller helper method in the template helper specification

My ApplicationController provides a method (e.g. sort_direction ) for presentation templates using helper_method :sort_direction . Then I use this method in another method (e.g. sort_link ) of a view helper ( application_helper.rb ).

When testing the sort_link method with RSpec (in application_helper_spec.rb ), I need to drown out the sort_direction , since the test seems to run completely independent of the controllers (and thus its open view templates).

Unfortunately, I could not find out how to drown out this controller's sort_direction method. I always get the "undefined method".

Here is what I have tried so far (inside application_helper_spec.rb ):

 helper.stub(:sort_direction) controller.stub(:sort_direction) view.stub(:sort_direction) self.stub(:sort_direction) 

Any suggestions how I can drown out this method?

Here is the error I get:

 NoMethodError: undefined method `sort_direction' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xb641434c> 
+6
ruby-on-rails stub rspec
source share
1 answer

David Chelimsky solved this problem here: http://groups.google.com/group/rspec/browse_thread/thread/cc44ca12c6816053

Just call all methods of the auxiliary object in spec:

 it "should work" do helper.stub(:sort_direction) helper.sort_link(...).should == ... end 
+6
source share

All Articles