method
assert_enqueued_email_with
v6.1.7.7 -
Show latest stable
- Class:
ActionMailer::TestHelper
assert_enqueued_email_with(mailer, method, args: nil, queue: ActionMailer::Base.deliver_later_queue_name || "default", &block)public
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