Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
39
Help us understand the problem. What is going on with this article?
@sutetotanuki

ActionMailerのテスト

More than 5 years have passed since last update.

delivery_methodを :test に設定する

Rails 4 ではデフォでなってた。確認するだけ?

config/environments/test.rb
  # Tell Action Mailer not to deliver emails to the real world.                                                                                                                   
  # The :test delivery method accumulates sent emails in the                                                                                                                      
  # ActionMailer::Base.deliveries array.  
  config.action_mailer.delivery_method = :test

ActionMailer::Base.deliveriesで送信したMail::Messageにアクセスする

spec/some_spec.rb
describe "sample" do 
  #  グローバルな変数みたいなので毎回クリアする。
  after { ActionMailer::Base.deliveries.clear }

  it "sample" do 
    # メール送る処理
    ActionMailer::Base.deliveries.last #=> #<Mail::Message>
    ActionMailer::Base.deliveries.last.body #=> #<Mail::Body>

    expect(ActionMailer::Base.deliveries.last.body).to match(/wellcom/)
  end
end
39
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
39
Help us understand the problem. What is going on with this article?