Skip to content


Unable to stub controller helper method when it is already stubbed on the controller #135

bradseefeld opened this Issue · 5 comments

5 participants


See the stack overflow post:


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 justinko closed this
RSpec member

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

RSpec member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.