所以我有一个未定义的方法错误,这是Rspec方法'to'。我有一个包含以下代码的规范
it "sends an email to users who have favorited the post" do
@user.favorites.where(post: @post).create
allow ( FavoriteMailer )
.to receive(:new_comment)
.with(@user, @post, @comment)
.and_return( double(deliver: true))
当我运行规范时,我收到以下错误:
1) Comment after_create with users permission sends an email to users who have favorited the post
Failure/Error: allow ( FavoriteMailer )
NoMethodError:
undefined method `to' for FavoriteMailer:Class
# ./spec/models/comment_spec.rb:18:in `block (4 levels) in <top (required)>'
为什么会发生这种情况?
答案 0 :(得分:2)
在第一个括号之前删除空格,这样你就可以写:
allow( FavoriteMailer )
但看起来更好:
allow(FavoriteMailer)
在您的情况下:allow (FavoriteMailer).to ..
被解释为:allow((FavoriteMailer).to ..)