【发布时间】:2021-11-14 04:35:05
【问题描述】:
我有以下代码:
def do_something(param1, param2)
"hello" if current_page? param2
end
但是,当我在帮助规范中执行此操作时,上面的应用程序代码可以工作:
allow(helper).to receive(:current_page?).and_return(true)
它不工作它说You cannot use helpers that need to determine the current page unless your view context provides a Request object in a #request method
但是当我这样做时
allow(self).to receive(:current_page?).and_return(true)
它有效。这是怎么回事?在这种情况下,self 不是辅助规范类吗?为什么我不能显式引用助手?
【问题讨论】:
-
你能发布更多上下文吗?现在我们甚至不知道这行代码的范围
标签: ruby-on-rails rspec mocking stub