Skip to content

Commit 8f2b6f8

Browse files
committed
Add tests for background_exception_notification method.
1 parent 7626e99 commit 8f2b6f8

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require 'test_helper'
2+
3+
class BackgroundExceptionNotificationTest < ActiveSupport::TestCase
4+
setup do
5+
begin
6+
1/0
7+
rescue => e
8+
@exception = e
9+
@mail = ExceptionNotifier::Notifier.background_exception_notification(@exception)
10+
end
11+
end
12+
13+
test "should have raised an exception" do
14+
assert_not_nil @exception
15+
end
16+
17+
test "should have generated a notification email" do
18+
assert_not_nil @mail
19+
end
20+
21+
test "mail should have a from address set" do
22+
assert @mail.from == ["[email protected]"]
23+
end
24+
25+
test "mail should have a to address set" do
26+
assert @mail.to == ["[email protected]"]
27+
end
28+
29+
test "mail should have a descriptive subject" do
30+
assert @mail.subject.include? "[Dummy ERROR] (ZeroDivisionError) \"divided by 0\""
31+
end
32+
33+
test "mail should contain backtrace in body" do
34+
assert @mail.body.include? "test/background_exception_notification_test.rb:6"
35+
end
36+
37+
test "mail should not contain any attachments" do
38+
assert @mail.attachments == []
39+
end
40+
41+
test "should not send notification if one of ignored exceptions" do
42+
begin
43+
raise ActiveRecord::RecordNotFound
44+
rescue => e
45+
@ignored_exception = e
46+
unless ExceptionNotifier.default_ignore_exceptions.include?(@ignored_exception.class)
47+
@ignored_mail = ExceptionNotifier::Notifier.background_exception_notification(@exception)
48+
end
49+
end
50+
51+
assert @ignored_exception.class.inspect == "ActiveRecord::RecordNotFound"
52+
assert_nil @ignored_mail
53+
end
54+
end

0 commit comments

Comments
 (0)