diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-05 21:56:18 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-11-05 21:56:18 +0000 |
commit | ba553f94248340b54b32cee1fcbd41295713d180 (patch) | |
tree | 232174d19991632ef0583cb685d5f3c520a510cd /actionmailer/test/test_helper_test.rb | |
parent | 2fbe0ae7a2d945dbd9d0e0abad23afde75db67fb (diff) | |
download | rails-ba553f94248340b54b32cee1fcbd41295713d180.tar.gz rails-ba553f94248340b54b32cee1fcbd41295713d180.tar.bz2 rails-ba553f94248340b54b32cee1fcbd41295713d180.zip |
Add assert_emails and assert_no_emails to test the number of emails delivered. Closes #6479.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5436 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/test/test_helper_test.rb')
-rw-r--r-- | actionmailer/test/test_helper_test.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb new file mode 100644 index 0000000000..a22e7a5991 --- /dev/null +++ b/actionmailer/test/test_helper_test.rb @@ -0,0 +1,79 @@ +require File.dirname(__FILE__) + '/abstract_unit' + +class TestHelperMailer < ActionMailer::Base + def test + recipients "test@example.com" + from "tester@example.com" + body render(:inline => "Hello, <%= @world %>", :body => { :world => "Earth" }) + end +end + +class TestHelperTest < Test::Unit::TestCase + def setup + ActionMailer::Base.delivery_method = :test + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.deliveries = [] + end + + def test_assert_emails + assert_nothing_raised do + assert_emails 1 do + TestHelperMailer.deliver_test + end + end + end + + def test_repeated_assert_emails_calls + assert_nothing_raised do + assert_emails 1 do + TestHelperMailer.deliver_test + end + end + + assert_nothing_raised do + assert_emails 2 do + TestHelperMailer.deliver_test + TestHelperMailer.deliver_test + end + end + end + + def test_assert_no_emails + assert_nothing_raised do + assert_no_emails do + TestHelperMailer.create_test + end + end + end + + def test_assert_emails_too_few_sent + error = assert_raises Test::Unit::AssertionFailedError do + assert_emails 2 do + TestHelperMailer.deliver_test + end + end + + assert_match /2 .* but 1/, error.message + end + + def test_assert_emails_too_many_sent + error = assert_raises Test::Unit::AssertionFailedError do + assert_emails 1 do + TestHelperMailer.deliver_test + TestHelperMailer.deliver_test + end + end + + assert_match /1 .* but 2/, error.message + end + + def test_assert_no_emails_failure + error = assert_raises Test::Unit::AssertionFailedError do + assert_no_emails do + TestHelperMailer.deliver_test + end + end + + assert_match /0 .* but 1/, error.message + end +end |