`assert_emails` in block form use the given number as expected value

This commit is contained in:
yuuji.yaginuma 2015-05-09 18:59:59 +09:00
parent 684bbe86cd
commit 49a59cc6a5
3 changed files with 17 additions and 1 deletions

View File

@ -1,3 +1,8 @@
* `assert_emails` in block form use the given number as expected value.
This makes the error message much easier to understand.
*Yuji Yaginuma*
* Add support for inline images in mailer previews by using an interceptor
class to convert cid: urls in image src attributes to data urls.

View File

@ -34,7 +34,7 @@ module ActionMailer
original_count = ActionMailer::Base.deliveries.size
yield
new_count = ActionMailer::Base.deliveries.size
assert_equal original_count + number, new_count, "#{number} emails expected, but #{new_count - original_count} were sent"
assert_equal number, new_count - original_count, "#{number} emails expected, but #{new_count - original_count} were sent"
else
assert_equal number, ActionMailer::Base.deliveries.size
end

View File

@ -112,6 +112,17 @@ class TestHelperMailerTest < ActionMailer::TestCase
assert_match(/1 .* but 2/, error.message)
end
def test_assert_emails_message
TestHelperMailer.test.deliver_now
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_emails 2 do
TestHelperMailer.test.deliver_now
end
end
assert_match "Expected: 2", error.message
assert_match "Actual: 1", error.message
end
def test_assert_no_emails_failure
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_no_emails do