We have recently migrated from sending emails with deliver_now
to deliver_later
. So that queued emails aren't lost when the system restarts, we implement this with Sidekiq.
When we used deliver_now
, our Rake tests could test the sending of an email with
assert_equal 1, ActionMailer::Base.deliveries.count
For Rspec there is the assert_enqueued_emails
method to test whether or not emails are queued. Is there an equivalent for Rake test?
The solution was quite simple, once I knew what to do:
include ActionMailer::TestHelper
to the start of the test fileperform_enqueued_jobs
after all emails were queued.After that, all the old tests worked fine.
See https://api.rubyonrails.org/classes/ActiveJob/TestHelper.html#method-i-perform_enqueued_jobs