|
1 | 1 | require "test_helper"
|
2 | 2 |
|
3 | 3 | class EmailErrorReporter::ErrorMailerTest < ActionMailer::TestCase
|
| 4 | + setup do |
| 5 | + @exception = Exception.new("some message") |
| 6 | + end |
| 7 | + |
4 | 8 | test "renders the template correctly" do
|
5 |
| - exception = Exception.new("some message") |
6 |
| - email = EmailErrorReporter::ErrorMailer.error( |
7 |
| - exception, |
8 |
| - handled: true, |
9 |
| - severity: :info, |
10 |
| - context: {} |
11 |
| - ) |
12 |
| - assert_equal [], email.to |
13 |
| - assert_equal "Exception", email.subject |
14 |
| - assert_equal read_fixture("error").join, email.body.to_s |
| 9 | + assert_equal [], error_mail.to |
| 10 | + assert_equal read_fixture("error").join, error_mail.body.to_s |
15 | 11 | end
|
16 | 12 |
|
17 | 13 | test "renders a backtrace" do
|
18 |
| - exception = Exception.new("some message") |
19 |
| - exception.set_backtrace(["foo", "bar"]) |
| 14 | + @exception.set_backtrace(["foo", "bar"]) |
| 15 | + |
| 16 | + assert_equal [], error_mail.to |
| 17 | + assert_equal read_fixture("error_with_backtrace").join, error_mail.body.to_s |
| 18 | + end |
| 19 | + |
| 20 | + test "severity: error" do |
| 21 | + email = error_mail(severity: :error) |
| 22 | + assert_equal "🔥" + " Exception", email.subject |
| 23 | + end |
| 24 | + |
| 25 | + test "severity: warning" do |
| 26 | + email = error_mail(severity: :warning) |
| 27 | + assert_equal "⚠️" + " Exception", email.subject |
| 28 | + end |
| 29 | + |
| 30 | + test "severity: info" do |
| 31 | + email = error_mail(severity: :info) |
| 32 | + assert_equal "ℹ️" + " Exception", email.subject |
| 33 | + end |
| 34 | + |
| 35 | + private |
| 36 | + |
| 37 | + def error_mail(**kwargs) |
20 | 38 | email = EmailErrorReporter::ErrorMailer.error(
|
21 |
| - exception, |
| 39 | + @exception, |
22 | 40 | handled: true,
|
23 | 41 | severity: :info,
|
24 |
| - context: {} |
| 42 | + context: {}, |
| 43 | + **kwargs |
25 | 44 | )
|
26 |
| - assert_equal [], email.to |
27 |
| - assert_equal "Exception", email.subject |
28 |
| - assert_equal read_fixture("error_with_backtrace").join, email.body.to_s |
29 | 45 | end
|
30 | 46 | end
|
0 commit comments