【发布时间】:2013-01-18 18:49:16
【问题描述】:
发现了类似的问题,但令人惊讶的是没有,我已经找到了,给出一个简单的答案......
尝试在我的控制器规范中存根辅助方法;不太确定需要加倍的对象是什么?
控制器调用这个方法:
#app/helpers/sessions_helper.rb
def signed_in?
current_user.present?
end
我想在规范中将其存根以返回真/假。
【问题讨论】:
-
尝试“current_user.stub(:present?).and_return(true)”。我知道 helper 是在其他地方定义的,但它会更具可读性。
-
Alex,不是 current_user.stub...,而是 controller.current_user.stub...
-
是的。
current_user.stub...产生错误:undefined local variable or method 'current_user'
标签: ruby-on-rails rspec rspec-rails