因此,我有一个未定义的方法错误,即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)>'
知道为什么会这样吗?
发布于 2014-09-09 04:10:15
只需在第一个括号之前删除空格,这样您就可以编写:
allow( FavoriteMailer )
但看起来更好的是:
allow(FavoriteMailer)
在您的例子中:allow (FavoriteMailer).to ..
被解释为:allow((FavoriteMailer).to ..)
https://stackoverflow.com/questions/25744170
复制