Ruby on rails 使用Desive对当前用户进行存根的问题

Ruby on rails 使用Desive对当前用户进行存根的问题,ruby-on-rails,ruby,ruby-on-rails-4,rspec,devise,Ruby On Rails,Ruby,Ruby On Rails 4,Rspec,Devise,我正在使用Desive制作一个rails 4应用程序来处理我的用户身份验证,这在任何其他控制器或其测试中都没有给我带来任何麻烦。然而,当我在我的评论测试中转到当前用户的存根时,我一直得到一个多态关联: Failure/Error: allow(comment).to receive(:current_user).with(:user) #<Comment id: nil, author_id: nil, content: "This is a Comment", commentable_t

我正在使用Desive制作一个rails 4应用程序来处理我的用户身份验证,这在任何其他控制器或其测试中都没有给我带来任何麻烦。然而,当我在我的评论测试中转到当前用户的存根时,我一直得到一个多态关联:

Failure/Error: allow(comment).to receive(:current_user).with(:user)
#<Comment id: nil, author_id: nil, content: "This is a Comment", commentable_type: "Question", commentable_id: 1, created_at: nil, updated_at: nil> does not implement: current_user
以下是注释模型代码:

class Comment < ActiveRecord::Base
  validates :content, presence: true
  validates :author, presence: true

  belongs_to :author, class_name: "User"
  belongs_to :commentable, polymorphic: true
end

当前_用户是designe look-at代码中的控制器或助手方法,但您试图在模型中模拟它。它没有当前的用户方法,因此rspec引发异常。

可以显示注释模型代码吗?它是控制器测试吗?还是模型试验?还是功能测试?你能给我们看看这个规格吗?对我来说,你想做什么完全不清楚。
class Comment < ActiveRecord::Base
  validates :content, presence: true
  validates :author, presence: true

  belongs_to :author, class_name: "User"
  belongs_to :commentable, polymorphic: true
end