Skip to content

Commit

Permalink
Improve Test Coverage for raise_delivery_errors. [kevinclark] closes #…
Browse files Browse the repository at this point in the history
…7152

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6006 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Jan 21, 2007
1 parent 8e82e29 commit 704f2cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions actionmailer/test/abstract_unit.rb
Expand Up @@ -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
25 changes: 25 additions & 0 deletions actionmailer/test/mail_service_test.rb
Expand Up @@ -245,6 +245,8 @@ def receive(mail)
end
end

uses_mocha 'ActionMailerTest' do

class ActionMailerTest < Test::Unit::TestCase
include ActionMailer::Quoting

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 704f2cc

Please sign in to comment.