forked from smartinez87/exception_notification
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for background_exception_notification method.
- Loading branch information
1 parent
7626e99
commit 8f2b6f8
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |