instance method
capture_emails
Ruby on Rails 8.0.4
Since v7.1.6Signature
capture_emails(&block)
Returns any emails that are sent in the block.
def test_emails
emails = capture_emails do
ContactMailer.welcome.deliver_now
end
assert_equal "Hi there", emails.first.subject
emails = capture_emails do
ContactMailer.welcome.deliver_now
ContactMailer.welcome.deliver_later
end
assert_equal "Hi there", emails.first.subject
end
Parameters
-
blockblock
Source
# File actionmailer/lib/action_mailer/test_helper.rb, line 249
def capture_emails(&block)
original_count = ActionMailer::Base.deliveries.size
deliver_enqueued_emails(&block)
new_count = ActionMailer::Base.deliveries.size
diff = new_count - original_count
ActionMailer::Base.deliveries.last(diff)
end
Defined in actionmailer/lib/action_mailer/test_helper.rb line 249
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionMailer::TestHelper