0

オブジェクトの after_create コールバックでメールが送信されることをテストしようとしています

class Payment < ActiveRecord::Base

    #associations
    belongs_to :quotation

  #validations
    validates :method, :amount, :quotation, :presence => true

    #callbacks
    after_create :send_email_confirmations



  def method_enum
     [['Cash'],['Bank Transfer'], ['PayPal']]
  end

  private

  def send_email_confirmations
    UsersMailer.confirm_payment(self).deliver
    AdminsMailer.payment_received(self).deliver
  end

end

テスト ファイル:

require 'spec_helper'

describe Payment do

    describe AdminsMailer do


        before :each do
            Admin.delete_all
        User.delete_all
        @quotation = FactoryGirl.create(:quotation)
        @submission = @quotation.submission
        @payment = Payment.new(:method => 'paypal', :amount => @quotation.price, :transaction_id => '4543332', :quotation_id => @quotation.id)

        end

        it "should deliver the admin email payment email" do
            @payment.save
            AdminsMailer.should_receive(:payment_received).with(@payment)

        end


    end
end

これにより、次の結果が生成されます。

Failure/Error: AdminsMailer.should_receive(:payment_received).with(@payment)
       (<AdminsMailer (class)>).payment_received(#<Payment id: 54, method: "paypal", amount: #<BigDecimal:7fabd1e449c0,'0.5E3',9(36)>, transaction_id: "4543332", created_at: "2013-09-27 11:30:53", updated_at: "2013-09-27 11:30:53", quotation_id: 58>)
           expected: 1 time

メールが送信されたことをテストするにはどうすればよいですか?

received: 0 times
4

1 に答える 1