Невозможно заглушить вспомогательный метод с помощью rspec

Я пытаюсь заглушить метод на помощник, который определен в моем контроллере. Например:

<code>class ApplicationController < ActionController::Base
  def current_user
    @current_user ||= authenticated_user_method
  end
  helper_method :current_user
end

module SomeHelper
  def do_something
    current_user.call_a_method
  end
end
</code>

В моем Rspec:

<code>describe SomeHelper
  it "why cant i stub a helper method?!" do
    helper.stub!(:current_user).and_return(@user)
    helper.respond_to?(:current_user).should be_true # Fails
    helper.do_something # Fails 'no method current_user'
  end
end
</code>

Вspec/support/authentication.rb

<code>module RspecAuthentication
  def sign_in(user)
    controller.stub!(:current_user).and_return(user)
    controller.stub!(:authenticate!).and_return(true)

    helper.stub(:current_user).and_return(user) if respond_to?(:helper)
  end
end

RSpec.configure do |config|
  config.include RspecAuthentication, :type => :controller
  config.include RspecAuthentication, :type => :view
  config.include RspecAuthentication, :type => :helper
end
</code>

Я задал похожий вопросВот, но остановился на работе вокруг. Это странное поведение снова закралось, и я хотел бы понять,why это не работает.

UPDATE: Я нашел это призваниеcontroller.stub!(:current_user).and_return(@user) доhelper.stub!(...) это то, что вызывает такое поведение. Это достаточно легко исправить вspec/support/authentication.rb, но это ошибка в Rspec? Я не понимаю, почему можно было бы ожидать, что он не сможет заглушить метод на помощнике, если он уже заглушен на контроллере.

Ответы на вопрос(4)

Ваш ответ на вопрос