How to test whether Mailer is enqueued 【Ruby on Rails】

Useful way

RSpec.describe 'test', type: :request do
include ActiveJob::TestHelper

context 'test1' do
def call
# ....some mailer functions
end
it 'send an email' do
expect { call }.to have_enqueued_job.on_queue('mailers')
expect(enqueued_jobs.size).to eq 1
end
end
end
[{:id=>"xxxxxxxxxxxxxxxx", :job=>ActionMailer::DeliveryJob, :args=>["Mailer", "method", "deliver_now", {"_aj_globalid"=>"gid://product/class/:id"}], :queue=>"mailers"}]

My LinkedIn account is below! Please contact me!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store