Permalink
Browse files

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
  • Loading branch information...
1 parent 8e82e29 commit 704f2cc6dee9d55d19bfad8e4a8308fdee71bf6f @NZKoz NZKoz committed Jan 21, 2007
Showing with 34 additions and 0 deletions.
  1. +9 −0 actionmailer/test/abstract_unit.rb
  2. +25 −0 actionmailer/test/mail_service_test.rb
View
9 actionmailer/test/abstract_unit.rb
@@ -28,3 +28,12 @@ def self.start(*args)
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
View
25 actionmailer/test/mail_service_test.rb
@@ -245,6 +245,8 @@ def receive(mail)
end
end
+uses_mocha 'ActionMailerTest' do
+
class ActionMailerTest < Test::Unit::TestCase
include ActionMailer::Quoting
@@ -261,13 +263,20 @@ def new_mail( charset="utf-8" )
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 @@ def test_perform_deliveries_flag
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 = <<EOF
@@ -789,6 +812,8 @@ def test_custom_content_type_attributes
end
end
+end # uses_mocha
+
class InheritableTemplateRootTest < Test::Unit::TestCase
def test_attr
expected = "#{File.dirname(__FILE__)}/fixtures/path.with.dots"

0 comments on commit 704f2cc

Please sign in to comment.