我正在使用 authlogic 进行用户身份验证,在我的 ApplicationController 中,我定义了“current_user”、“current_user_session”等并将其设置为 helper_methods。
我的主索引有一个非常简单的视图规范:
RSpec.describe "main/index.html.erb", :type => :view do
context "when not logged in" do
before do
allow(view).to receive(:current_user).and_return(nil)
end
it "has an h1" do
render
expect(rendered).to include('h1')
end
end
end
问题是,如果我的配置中有“mocks.verify_partial_doubles = true”,那么这会导致一个令人印象深刻的巨大错误,因为它会转储整个对象,然后在底部说:
1) main/index.html.erb when not logged in has an h1
Failure/Error: allow(view).to receive(:current_user).and_return(nil)
#<#<Class:0x00000104c249d0>:.........
@rendered_views={}>> does not implement: current_user
当然,建议将 verify_partial_doubles 设置为 true,但这样做会中断。我直接从文档中提取了这个:
如果该方法出现在 ApplicationHelper 中,它将起作用。但如果它在 ApplicationController 中并定义为 helper_method 就没有这样的运气了:
helper_method :current_user, ...
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
我想要 verify_partial_doubles 提供的保护,我该如何解决这个问题?