時は、perform_enqueued_jobs
と書く。
it do
perform_enqueued_jobs do
subject
end
expect(ActionMailer::Base.deliveries.size).to(eq(1))
end
とりあえず動いてるか?のテストしたい時はこれで良さそう。
ちゃんとどのメソッドが呼ばれてるか?みたいなテストにしたいなら、呼ばれてるMailerをスタブしないとダメそう。
一周回って、結合テスト的に呼び出し〜どんな内容のメールが送信されているか?でテストするなら、このように書くことでメールの内容が検証できる。
mail = ActionMailer::Base.deliveries.last
expect(mail.subject).to eq('Expected Subject')
expect(mail.to).to eq(['example@example.com'])
expect(mail.from).to eq(['from@example.com'])
expect(mail.body.encoded).to match('Expected Body Content')
サービスの開始時なんかはこういうテストだけを書いておくほうが変更時に楽かもしれないなー。
という何番煎じかわからん小ネタでした。