File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments