rspec 中的 double 是什么?我正在编写测试,但无法在下面的 'double'- 第 15 行中找到信息:

what is a double in rspec ? I am writing a test and can't find information on 'double'- line 15 below:

this is the Comment-rspec, it works, but I don't understand what the double does. my research has returned nothing.

需要'rails_helper'

 describe Comment do

   include TestFactories

   describe "after_create" do

 before do
   @post = associated_post
   @user = authenticated_user
   @comment = Comment.new(body: 'My comment', post: @post, user_id: 10000)
 end

 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_now: true) )

   @comment.save
 end

 it "does not send emails to users who haven't" do
   expect( FavoriteMailer )
     .not_to receive(:new_comment)

   @comment.save
 end
  end
 end

double 是 RSpec 中的基本模拟对象,如 https://relishapp.com/rspec/rspec-mocks/docs 中所述。在您的情况下,它提供了 deliver_now 方法的实现。但是,您的第一个 it 块并没有真正测试任何内容,因为其中没有断言。