[rspec-users] Stub a controllers helper_method in a view template helper spec

Kai Schlamp kai.schlamp at googlemail.com
Mon Mar 21 09:40:51 EDT 2011


> 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.

Sure ...

describe ApplicationHelper do
  describe "order link" do
    it "should create html link" do
      # things I tried
      view.stub(:check_param)
      helper.stub(:check_param)
      controller.stub(:check_param)
      self.stub(:check_param)

      order_link(:name)
    end
  end
end

Here is how check_param is called from within the helper:

module ApplicationHelper
  def order_link(column, title = nil)
    fetch_param(:order)
  end
end

and in application controller:

...
helper_method :fetch_param

def fetch_param(name)
  ...
end
...



More information about the rspec-users mailing list