LoginSignup
14
12

More than 5 years have passed since last update.

rspecでcontrollerの処理をした時やmodelの処理時にメールが配信された事やメールの内容をテストしたい

Posted at

ActionMailer::Base.deliveriesを参照すると取得出来るっぽい
mailを取得したいなら、ActionMailer::Base.deliveries.lastで出来る。

describe "password_set_complete パスワード設定完了" do
  it "処理後、メールが配信される" do
    expect {
      post :password_set_complete, parameters
      mail = ActionMailer::Base.deliveries.last
      expect(mail.subject).to eq "PASSWORD登録のお知らせ"
    }.to change(ActionMailer::Base.deliveries, :size).by 1
  end
end

中々同じ事しているコード見つけられなかったのでメモ

14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12