module ActionMailer::TestHelper

def assert_emails(number, &block)

end
end
ContactMailer.welcome.deliver_later
ContactMailer.welcome.deliver_now
assert_emails 2 do

end
ContactMailer.welcome.deliver_now
assert_emails 1 do
def test_emails_again

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

end
assert_emails 2
ContactMailer.welcome.deliver_now
assert_emails 1
ContactMailer.welcome.deliver_now
assert_emails 0
def test_emails

Asserts that the number of emails sent matches the given number.
def assert_emails(number, &block)
  if block_given?
    diff = capture_emails(&block).length
    assert_equal number, diff, "#{number} emails expected, but #{diff} were sent"
  else
    assert_equal number, ActionMailer::Base.deliveries.size
  end
end