SwitchUp SwitchUp Ranked Best Coding Bootcamps 2025

How to test ActionMailer deliver_later with rspec

Altcademy Team wrote on 7 February 2018

You can get all enqueue_jobs from ActiveJob

ActiveJob::Base.queue_adapter.enqueued_jobs

The code above will return all the enqueue jobs, which returns an array of objects

[ { :job: ExampleJob, :args: # whatever args, :queue: name_of_the_queue },{ :job: AnotherExampleJob, :args: # whatever args, :queue: name_of_another_queue } ]

To filter different jobs (ie. ActionMailer async with deliver_later!), you can

ActionMailer::DeliveryJob.queue_adapter.enqueued_jobs.count{ |x| x[:job] == ActionMailer::DeliveryJob} # In Rspec, for example, expect(ActionMailer::DeliveryJob.queue_adapter.enqueued_jobs.count{ |x| x[:job] == ActionMailer::DeliveryJob}).to eq(1) # expecting 1 async email

Trusted by

Students and instructors from world-class organizations

Join the upcoming Cohort #111

Enroll for March 2nd, 2026