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
This commit is contained in:
Michael Koziarski
2007-01-21 23:20:44 +00:00
parent 8e82e29010
commit 704f2cc6de
2 changed files with 34 additions and 0 deletions

View File

@@ -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

View File

@@ -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 = <<EOF
@@ -789,6 +812,8 @@ EOF
end
end
end # uses_mocha
class InheritableTemplateRootTest < Test::Unit::TestCase
def test_attr
expected = "#{File.dirname(__FILE__)}/fixtures/path.with.dots"