Method: ActionMailer::TestHelper#assert_enqueued_emails

Defined in:
actionmailer/lib/action_mailer/test_helper.rb

#assert_enqueued_emails(number, &block) ⇒ Object

Asserts that the number of emails enqueued for later delivery matches the given number.

def test_emails
  assert_enqueued_emails 0
  ContactMailer.welcome.deliver_later
  assert_enqueued_emails 1
  ContactMailer.welcome.deliver_later
  assert_enqueued_emails 2
end

If a block is passed, that block should cause the specified number of emails to be enqueued.

def test_emails_again
  assert_enqueued_emails 1 do
    ContactMailer.welcome.deliver_later
  end

  assert_enqueued_emails 2 do
    ContactMailer.welcome.deliver_later
    ContactMailer.welcome.deliver_later
  end
end


114
115
116
# File 'actionmailer/lib/action_mailer/test_helper.rb', line 114

def assert_enqueued_emails(number, &block)
  assert_enqueued_jobs(number, only: ->(job) { delivery_job_filter(job) }, &block)
end