instance method
assert_enqueued_email_with
Ruby on Rails 6.1.7.10
Since v5.2.8.1Signature
assert_enqueued_email_with(mailer, method, args: nil, queue: ActionMailer::Base.deliver_later_queue_name || "default", &block)
Asserts that a specific email has been enqueued, optionally matching arguments.
def test_email ContactMailer.welcome.deliver_later assert_enqueued_email_with ContactMailer, :welcome end def test_email_with_arguments ContactMailer.welcome("Hello", "Goodbye").deliver_later assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"] end
If a block is passed, that block should cause the specified email to be enqueued.
def test_email_in_block assert_enqueued_email_with ContactMailer, :welcome do ContactMailer.welcome.deliver_later end end
If args is provided as a Hash, a parameterized email is matched.
def test_parameterized_email assert_enqueued_email_with ContactMailer, :welcome, args: {email: 'user@example.com'} do ContactMailer.with(email: 'user@example.com').welcome.deliver_later end end
Parameters
-
mailerreq -
methodreq -
argskey = nil -
queuekey = ActionMailer::Base.deliver_later_queue_name || "default" -
blockblock
Source
# File actionmailer/lib/action_mailer/test_helper.rb, line 126
def assert_enqueued_email_with(mailer, method, args: nil, queue: ActionMailer::Base.deliver_later_queue_name || "default", &block)
args = if args.is_a?(Hash)
[mailer.to_s, method.to_s, "deliver_now", params: args, args: []]
else
[mailer.to_s, method.to_s, "deliver_now", args: Array(args)]
end
assert_enqueued_with(job: mailer.delivery_job, args: args, queue: queue.to_s, &block)
end
Defined in actionmailer/lib/action_mailer/test_helper.rb line 126
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionMailer::TestHelper