这是我想测试期望的电话:
UserMailer.invoice_paid(user, invoice).deliver_later
Rails 5 ActionMailer:test
模式下的行为似乎在 ApplicationMailer 类的每个方法上都返回 nil。这应该没问题,因为我可以像这样存根它:
invoice_paid_dbl = double(ActionMailer::MessageDelivery)
allow(UserMailer).to receive(:invoice_paid).and_return(invoice_paid_dbl)
这个期望失败了:
expect(UserMailer).to receive(:invoice_paid).once
虽然这个通过:
expect(invoice_paid_dbl).to receive(:deliver_later).once
这不应该是不可能的吗?我想也许方法链混淆了 RSpec,但是将行拆分成这个没有效果:
mail = UserMailer.invoice_paid(user, invoice)
mail.deliver_later
添加.with(any_args)
到存根和期望也没有效果(因为这是默认设置)。预期失败:1 次,带有任何参数,收到:0 次,带有任何参数。