From 704f2cc6dee9d55d19bfad8e4a8308fdee71bf6f Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sun, 21 Jan 2007 23:20:44 +0000 Subject: Improve Test Coverage for raise_delivery_errors. [kevinclark] closes #7152 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6006 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionmailer/test/abstract_unit.rb | 9 +++++++++ actionmailer/test/mail_service_test.rb | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 8a30e39a2b..d1e69ce0fb 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -28,3 +28,12 @@ class Net::SMTP yield MockSMTP.new end end + +# Wrap tests that use Mocha and skip if unavailable. +def uses_mocha(test_name) + require 'mocha' + require 'stubba' + yield +rescue LoadError + $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again." +end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 7b1ec68725..aa68cb466f 100755 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -245,6 +245,8 @@ class TestMailer < ActionMailer::Base end end +uses_mocha 'ActionMailerTest' do + class ActionMailerTest < Test::Unit::TestCase include ActionMailer::Quoting @@ -261,13 +263,20 @@ class ActionMailerTest < Test::Unit::TestCase mail end + # Replacing logger work around for mocha bug. Should be fixed in mocha 0.3.3 def setup ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.raise_delivery_errors ActionMailer::Base.deliveries = [] + @original_logger = TestMailer.logger @recipient = 'test@localhost' end + + def teardown + TestMailer.logger = @original_logger + end def test_nested_parts created = nil @@ -435,6 +444,20 @@ class ActionMailerTest < Test::Unit::TestCase TestMailer.deliver_signed_up(@recipient) assert_equal 1, ActionMailer::Base.deliveries.size end + + def test_doesnt_raise_errors_when_raise_delivery_errors_is_false + ActionMailer::Base.raise_delivery_errors = false + TestMailer.any_instance.expects(:perform_delivery_test).raises(Exception) + assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) } + end + + def test_delivery_logs_sent_mail + mail = TestMailer.create_signed_up(@recipient) + logger = mock() + logger.expects(:info).with("Sent mail:\n #{mail.encoded}") + TestMailer.logger = logger + TestMailer.deliver_signed_up(@recipient) + end def test_unquote_quoted_printable_subject msg = <