2
我用摩卡,測試::單位和delayed_job的時候打來電話,想測試郵件方法是否已執行,就像這樣:無法測試,如果方法是使用delayed_job的「延遲」的方法
test "should send info about paid payment" do
payment = Payment.new :contractor_name => "notempty", :address => "notempty"
UserMailer.expects(:send_payment_info)
payment.set_paid!
end
# model method
def set_paid!
self.status = 'paid'
self.paid_at = Date.today
self.save!
UserMailer.delay.send_payment_info self
end
無使用延遲的方法,測試按預期工作,但它(我已經推遲:: Worker.delay_jobs = Rails.env.test在初始配置!?)我得到:
NoMethodError: undefined method
deliver' for nil:NilClass app/models/payment.rb:33:in
set_paid!' test/unit/payment_test.rb:50:in `test_should_send_info_about_paid_payment'
而且我不知道如何解決這個問題?也許我應該使用不同的UserMailer?