When you set up an ActionMailer
email, the default configuration is for it
to use ActiveJob
to send the emails. As of Rails 5, it will do so
asynchronously..
Depending on your preferences for testing emails, you may prefer ActiveJob
to send the emails synchronously. This can be done by changing the
queue_adapter
back to :inline
in your config/environments/test.rb
.
config.active_job.queue_adapter = :inline
If you also configure the delivery_method
as :test
:
config.action_mailer.delivery_method = :test
then emails will be queued up in ActionMailer::Base.deliveries
allowing
you to write a test like this:
expect(ActionMailer::Base.deliveries.count).to eq(1)
Check out the
docs for more on
ActionMailer
.