See the stack overflow post: http://stackoverflow.com/questions/10537932/unable-to-stub-helper-method-with-rspec
describe MyModuleHelper do
it "can stub a helper method" do
helper.respond_to?(:current_user).should be_true # Fails
In this example, current_user is a helper_method defined on the controller.
The controller in your helper spec is not a "RSpec controller" (instance of one of your app's controllers), it is an instance of ActionView::TestCase::TestController. Not sure what Rails is doing to cause the stubbed method to be "removed". Maybe we should warn or raise an exception if controller is called within a helper spec.... @dchelimsky
I would avoid calling controller in any of your helper specs - what controller would it be anyway?
Closing this. If you find the cause, please report back here.
@justinko is correct that there should not be any references to controller in helper specs (or view specs, for that matter).
Understand the bit about "don't reference controller in view specs", but still unclear on how I can mock or stub an ApplicationHelper method in a view spec. I want to verify that the helper is called n times while rendering the view, and I've been flailing for a couple of hours here.
@jdickey -- this sounds like an rspec-rails issue. Can you report it there?
@myronmarston I'd think I'd use rspec-mocks to do it, but I will ask over there. Thanks or the quick reply.