Skip to content

Commit

Permalink
Add tests for background_exception_notification method.
Browse files Browse the repository at this point in the history
  • Loading branch information
smartinez87 committed Aug 7, 2011
1 parent 7626e99 commit 8f2b6f8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/background_exception_notification_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'test_helper'

class BackgroundExceptionNotificationTest < ActiveSupport::TestCase
setup do
begin
1/0
rescue => e
@exception = e
@mail = ExceptionNotifier::Notifier.background_exception_notification(@exception)
end
end

test "should have raised an exception" do
assert_not_nil @exception
end

test "should have generated a notification email" do
assert_not_nil @mail
end

test "mail should have a from address set" do
assert @mail.from == ["[email protected]"]
end

test "mail should have a to address set" do
assert @mail.to == ["[email protected]"]
end

test "mail should have a descriptive subject" do
assert @mail.subject.include? "[Dummy ERROR] (ZeroDivisionError) \"divided by 0\""
end

test "mail should contain backtrace in body" do
assert @mail.body.include? "test/background_exception_notification_test.rb:6"
end

test "mail should not contain any attachments" do
assert @mail.attachments == []
end

test "should not send notification if one of ignored exceptions" do
begin
raise ActiveRecord::RecordNotFound
rescue => e
@ignored_exception = e
unless ExceptionNotifier.default_ignore_exceptions.include?(@ignored_exception.class)
@ignored_mail = ExceptionNotifier::Notifier.background_exception_notification(@exception)
end
end

assert @ignored_exception.class.inspect == "ActiveRecord::RecordNotFound"
assert_nil @ignored_mail
end
end

0 comments on commit 8f2b6f8

Please sign in to comment.