rspec测试失败了这个项目:
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
undefined method `picking?' for nil:NilClass
代码触发此错误的是:
<% if current_user.picking?(post) %>
在用户模型中,拣货方法定义为: def pick?(帖子) trips.find_by_pickedpost_id(post.id) 端
current_user定义为:
def current_user=(user)
@current_user = user
end
def current_user
@current_user ||= user_from_remember_token
end
为什么测试失败?为什么current_user是nil class?
答案 0 :(得分:0)
您确定user_from_remember_token
会返回一些内容吗?我建议使用debugger
或pry
来调试您的代码。我发现后者更容易使用,但它似乎缺乏第一个功能。