exception_notification 4.3.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Appraisals +2 -2
- data/CHANGELOG.rdoc +14 -0
- data/CONTRIBUTING.md +18 -0
- data/Gemfile +1 -1
- data/README.md +64 -935
- data/Rakefile +2 -2
- data/docs/notifiers/campfire.md +50 -0
- data/docs/notifiers/custom.md +42 -0
- data/docs/notifiers/datadog.md +51 -0
- data/docs/notifiers/email.md +195 -0
- data/docs/notifiers/google_chat.md +31 -0
- data/docs/notifiers/hipchat.md +66 -0
- data/docs/notifiers/irc.md +97 -0
- data/docs/notifiers/mattermost.md +115 -0
- data/docs/notifiers/slack.md +161 -0
- data/docs/notifiers/sns.md +37 -0
- data/docs/notifiers/teams.md +54 -0
- data/docs/notifiers/webhook.md +60 -0
- data/examples/sample_app.rb +54 -0
- data/examples/sinatra/Gemfile +6 -6
- data/examples/sinatra/config.ru +1 -1
- data/examples/sinatra/sinatra_app.rb +14 -10
- data/exception_notification.gemspec +27 -22
- data/gemfiles/rails4_0.gemfile +3 -3
- data/gemfiles/rails4_1.gemfile +3 -3
- data/gemfiles/rails4_2.gemfile +3 -3
- data/gemfiles/rails5_0.gemfile +3 -3
- data/gemfiles/rails5_1.gemfile +3 -3
- data/gemfiles/rails5_2.gemfile +7 -0
- data/gemfiles/rails6_0.gemfile +7 -0
- data/lib/exception_notification.rb +1 -0
- data/lib/exception_notification/rack.rb +8 -21
- data/lib/exception_notification/resque.rb +8 -10
- data/lib/exception_notification/sidekiq.rb +8 -12
- data/lib/exception_notification/version.rb +3 -0
- data/lib/exception_notifier.rb +20 -3
- data/lib/exception_notifier/base_notifier.rb +2 -3
- data/lib/exception_notifier/campfire_notifier.rb +12 -13
- data/lib/exception_notifier/datadog_notifier.rb +153 -0
- data/lib/exception_notifier/email_notifier.rb +64 -87
- data/lib/exception_notifier/google_chat_notifier.rb +25 -119
- data/lib/exception_notifier/hipchat_notifier.rb +11 -12
- data/lib/exception_notifier/irc_notifier.rb +32 -30
- data/lib/exception_notifier/mattermost_notifier.rb +47 -140
- data/lib/exception_notifier/modules/backtrace_cleaner.rb +0 -2
- data/lib/exception_notifier/modules/error_grouping.rb +5 -5
- data/lib/exception_notifier/modules/formatter.rb +118 -0
- data/lib/exception_notifier/notifier.rb +5 -6
- data/lib/exception_notifier/slack_notifier.rb +63 -40
- data/lib/exception_notifier/sns_notifier.rb +17 -11
- data/lib/exception_notifier/teams_notifier.rb +58 -44
- data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +1 -1
- data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +1 -1
- data/lib/exception_notifier/views/exception_notifier/_request.text.erb +1 -1
- data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +2 -2
- data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +2 -2
- data/lib/exception_notifier/webhook_notifier.rb +14 -11
- data/lib/generators/exception_notification/install_generator.rb +5 -5
- data/lib/generators/exception_notification/templates/{exception_notification.rb → exception_notification.rb.erb} +13 -11
- data/test/exception_notification/rack_test.rb +27 -11
- data/test/exception_notification/resque_test.rb +52 -0
- data/test/exception_notifier/campfire_notifier_test.rb +42 -42
- data/test/exception_notifier/datadog_notifier_test.rb +151 -0
- data/test/exception_notifier/email_notifier_test.rb +269 -153
- data/test/exception_notifier/google_chat_notifier_test.rb +154 -101
- data/test/exception_notifier/hipchat_notifier_test.rb +78 -81
- data/test/exception_notifier/irc_notifier_test.rb +34 -34
- data/test/exception_notifier/mattermost_notifier_test.rb +164 -67
- data/test/exception_notifier/modules/error_grouping_test.rb +39 -40
- data/test/exception_notifier/modules/formatter_test.rb +150 -0
- data/test/exception_notifier/sidekiq_test.rb +6 -6
- data/test/exception_notifier/slack_notifier_test.rb +61 -60
- data/test/exception_notifier/sns_notifier_test.rb +27 -32
- data/test/exception_notifier/teams_notifier_test.rb +23 -26
- data/test/exception_notifier/webhook_notifier_test.rb +48 -46
- data/test/exception_notifier_test.rb +41 -38
- data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.html.erb +0 -0
- data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.text.erb +0 -0
- data/test/{dummy/app → support}/views/exception_notifier/_new_section.html.erb +0 -0
- data/test/{dummy/app → support}/views/exception_notifier/_new_section.text.erb +0 -0
- data/test/test_helper.rb +11 -14
- metadata +136 -166
- data/test/dummy/.gitignore +0 -4
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/controllers/posts_controller.rb +0 -30
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/helpers/posts_helper.rb +0 -2
- data/test/dummy/app/models/post.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/app/views/posts/_form.html.erb +0 -0
- data/test/dummy/app/views/posts/new.html.erb +0 -0
- data/test/dummy/app/views/posts/show.html.erb +0 -0
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -42
- data/test/dummy/config/boot.rb +0 -6
- data/test/dummy/config/database.yml +0 -22
- data/test/dummy/config/environment.rb +0 -17
- data/test/dummy/config/environments/development.rb +0 -25
- data/test/dummy/config/environments/production.rb +0 -50
- data/test/dummy/config/environments/test.rb +0 -35
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -10
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -8
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -3
- data/test/dummy/db/migrate/20110729022608_create_posts.rb +0 -15
- data/test/dummy/db/schema.rb +0 -24
- data/test/dummy/db/seeds.rb +0 -7
- data/test/dummy/lib/tasks/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/images/rails.png +0 -0
- data/test/dummy/public/index.html +0 -239
- data/test/dummy/public/javascripts/application.js +0 -2
- data/test/dummy/public/javascripts/controls.js +0 -965
- data/test/dummy/public/javascripts/dragdrop.js +0 -974
- data/test/dummy/public/javascripts/effects.js +0 -1123
- data/test/dummy/public/javascripts/prototype.js +0 -6001
- data/test/dummy/public/javascripts/rails.js +0 -191
- data/test/dummy/public/robots.txt +0 -5
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/public/stylesheets/scaffold.css +0 -56
- data/test/dummy/script/rails +0 -6
- data/test/dummy/test/functional/posts_controller_test.rb +0 -237
- data/test/dummy/test/test_helper.rb +0 -7
|
@@ -2,19 +2,18 @@ require 'test_helper'
|
|
|
2
2
|
require 'httparty'
|
|
3
3
|
|
|
4
4
|
class TeamsNotifierTest < ActiveSupport::TestCase
|
|
5
|
-
|
|
6
|
-
test "should send notification if properly configured" do
|
|
5
|
+
test 'should send notification if properly configured' do
|
|
7
6
|
options = {
|
|
8
|
-
:
|
|
7
|
+
webhook_url: 'http://localhost:8000'
|
|
9
8
|
}
|
|
10
9
|
teams_notifier = ExceptionNotifier::TeamsNotifier.new
|
|
11
10
|
teams_notifier.httparty = FakeHTTParty.new
|
|
12
11
|
|
|
13
|
-
options = teams_notifier.call ArgumentError.new(
|
|
12
|
+
options = teams_notifier.call ArgumentError.new('foo'), options
|
|
14
13
|
|
|
15
14
|
body = ActiveSupport::JSON.decode options[:body]
|
|
16
|
-
assert body.
|
|
17
|
-
assert body.
|
|
15
|
+
assert body.key? 'title'
|
|
16
|
+
assert body.key? 'sections'
|
|
18
17
|
|
|
19
18
|
sections = body['sections']
|
|
20
19
|
header = sections[0]
|
|
@@ -24,15 +23,15 @@ class TeamsNotifierTest < ActiveSupport::TestCase
|
|
|
24
23
|
assert_equal 'foo', header['activitySubtitle']
|
|
25
24
|
end
|
|
26
25
|
|
|
27
|
-
test
|
|
26
|
+
test 'should send notification with create gitlab issue link if specified' do
|
|
28
27
|
options = {
|
|
29
|
-
:
|
|
30
|
-
:
|
|
28
|
+
webhook_url: 'http://localhost:8000',
|
|
29
|
+
git_url: 'github.com/aschen'
|
|
31
30
|
}
|
|
32
31
|
teams_notifier = ExceptionNotifier::TeamsNotifier.new
|
|
33
32
|
teams_notifier.httparty = FakeHTTParty.new
|
|
34
33
|
|
|
35
|
-
options = teams_notifier.call ArgumentError.new(
|
|
34
|
+
options = teams_notifier.call ArgumentError.new('foo'), options
|
|
36
35
|
|
|
37
36
|
body = ActiveSupport::JSON.decode options[:body]
|
|
38
37
|
|
|
@@ -44,27 +43,27 @@ class TeamsNotifierTest < ActiveSupport::TestCase
|
|
|
44
43
|
|
|
45
44
|
test 'should add other HTTParty options to params' do
|
|
46
45
|
options = {
|
|
47
|
-
:
|
|
48
|
-
:
|
|
49
|
-
:
|
|
50
|
-
:
|
|
51
|
-
:
|
|
52
|
-
:
|
|
46
|
+
webhook_url: 'http://localhost:8000',
|
|
47
|
+
username: 'Test Bot',
|
|
48
|
+
avatar: 'http://site.com/icon.png',
|
|
49
|
+
basic_auth: {
|
|
50
|
+
username: 'clara',
|
|
51
|
+
password: 'password'
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
teams_notifier = ExceptionNotifier::TeamsNotifier.new
|
|
56
55
|
teams_notifier.httparty = FakeHTTParty.new
|
|
57
56
|
|
|
58
|
-
options = teams_notifier.call ArgumentError.new(
|
|
57
|
+
options = teams_notifier.call ArgumentError.new('foo'), options
|
|
59
58
|
|
|
60
|
-
assert options.
|
|
59
|
+
assert options.key? :basic_auth
|
|
61
60
|
assert 'clara', options[:basic_auth][:username]
|
|
62
61
|
assert 'password', options[:basic_auth][:password]
|
|
63
62
|
end
|
|
64
63
|
|
|
65
64
|
test "should use 'A' for exceptions count if :accumulated_errors_count option is nil" do
|
|
66
65
|
teams_notifier = ExceptionNotifier::TeamsNotifier.new
|
|
67
|
-
exception = ArgumentError.new(
|
|
66
|
+
exception = ArgumentError.new('foo')
|
|
68
67
|
teams_notifier.instance_variable_set(:@exception, exception)
|
|
69
68
|
teams_notifier.instance_variable_set(:@options, {})
|
|
70
69
|
|
|
@@ -73,11 +72,11 @@ class TeamsNotifierTest < ActiveSupport::TestCase
|
|
|
73
72
|
assert_equal 'A *ArgumentError* occurred.', header['activityTitle']
|
|
74
73
|
end
|
|
75
74
|
|
|
76
|
-
test
|
|
75
|
+
test 'should use direct errors count if :accumulated_errors_count option is 5' do
|
|
77
76
|
teams_notifier = ExceptionNotifier::TeamsNotifier.new
|
|
78
|
-
exception = ArgumentError.new(
|
|
77
|
+
exception = ArgumentError.new('foo')
|
|
79
78
|
teams_notifier.instance_variable_set(:@exception, exception)
|
|
80
|
-
teams_notifier.instance_variable_set(:@options,
|
|
79
|
+
teams_notifier.instance_variable_set(:@options, accumulated_errors_count: 5)
|
|
81
80
|
message_text = teams_notifier.send(:message_text)
|
|
82
81
|
header = message_text['sections'][0]
|
|
83
82
|
assert_equal '5 *ArgumentError* occurred.', header['activityTitle']
|
|
@@ -85,9 +84,7 @@ class TeamsNotifierTest < ActiveSupport::TestCase
|
|
|
85
84
|
end
|
|
86
85
|
|
|
87
86
|
class FakeHTTParty
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return options
|
|
87
|
+
def post(_url, options)
|
|
88
|
+
options
|
|
91
89
|
end
|
|
92
|
-
|
|
93
90
|
end
|
|
@@ -2,42 +2,41 @@ require 'test_helper'
|
|
|
2
2
|
require 'httparty'
|
|
3
3
|
|
|
4
4
|
class WebhookNotifierTest < ActiveSupport::TestCase
|
|
5
|
-
|
|
6
|
-
test "should send webhook notification if properly configured" do
|
|
5
|
+
test 'should send webhook notification if properly configured' do
|
|
7
6
|
ExceptionNotifier::WebhookNotifier.stubs(:new).returns(Object.new)
|
|
8
|
-
webhook = ExceptionNotifier::WebhookNotifier.new(
|
|
7
|
+
webhook = ExceptionNotifier::WebhookNotifier.new(url: 'http://localhost:8000')
|
|
9
8
|
webhook.stubs(:call).returns(fake_response)
|
|
10
9
|
response = webhook.call(fake_exception)
|
|
11
10
|
|
|
12
11
|
refute_nil response
|
|
13
12
|
assert_equal response[:status], 200
|
|
14
|
-
assert_equal response[:body][:exception][:error_class],
|
|
15
|
-
assert_includes response[:body][:exception][:message],
|
|
16
|
-
assert_includes response[:body][:exception][:backtrace],
|
|
13
|
+
assert_equal response[:body][:exception][:error_class], 'ZeroDivisionError'
|
|
14
|
+
assert_includes response[:body][:exception][:message], 'divided by 0'
|
|
15
|
+
assert_includes response[:body][:exception][:backtrace], '/exception_notification/test/webhook_notifier_test.rb:48'
|
|
17
16
|
|
|
18
|
-
assert response[:body][:request][:cookies].
|
|
19
|
-
assert_equal response[:body][:request][:url],
|
|
20
|
-
assert_equal response[:body][:request][:ip_address],
|
|
21
|
-
assert response[:body][:request][:environment].
|
|
22
|
-
assert_equal response[:body][:request][:controller],
|
|
23
|
-
assert response[:body][:request][:session].
|
|
24
|
-
assert response[:body][:request][:parameters].
|
|
25
|
-
assert response[:body][:data][:extra_data].
|
|
17
|
+
assert response[:body][:request][:cookies].key?(:cookie_item1)
|
|
18
|
+
assert_equal response[:body][:request][:url], 'http://example.com/example'
|
|
19
|
+
assert_equal response[:body][:request][:ip_address], '192.168.1.1'
|
|
20
|
+
assert response[:body][:request][:environment].key?(:env_item1)
|
|
21
|
+
assert_equal response[:body][:request][:controller], '#<ControllerName:0x007f9642a04d00>'
|
|
22
|
+
assert response[:body][:request][:session].key?(:session_item1)
|
|
23
|
+
assert response[:body][:request][:parameters].key?(:controller)
|
|
24
|
+
assert response[:body][:data][:extra_data].key?(:data_item1)
|
|
26
25
|
end
|
|
27
26
|
|
|
28
|
-
test
|
|
27
|
+
test 'should send webhook notification with correct params data' do
|
|
29
28
|
url = 'http://localhost:8000'
|
|
30
29
|
fake_exception.stubs(:backtrace).returns('the backtrace')
|
|
31
|
-
webhook = ExceptionNotifier::WebhookNotifier.new(
|
|
30
|
+
webhook = ExceptionNotifier::WebhookNotifier.new(url: url)
|
|
32
31
|
|
|
33
32
|
HTTParty.expects(:send).with(:post, url, fake_params)
|
|
34
33
|
|
|
35
34
|
webhook.call(fake_exception)
|
|
36
35
|
end
|
|
37
36
|
|
|
38
|
-
test
|
|
37
|
+
test 'should call pre/post_callback if specified' do
|
|
39
38
|
HTTParty.stubs(:send).returns(fake_response)
|
|
40
|
-
webhook = ExceptionNotifier::WebhookNotifier.new(
|
|
39
|
+
webhook = ExceptionNotifier::WebhookNotifier.new(url: 'http://localhost:8000')
|
|
41
40
|
webhook.call(fake_exception)
|
|
42
41
|
end
|
|
43
42
|
|
|
@@ -45,49 +44,52 @@ class WebhookNotifierTest < ActiveSupport::TestCase
|
|
|
45
44
|
|
|
46
45
|
def fake_response
|
|
47
46
|
{
|
|
48
|
-
:
|
|
49
|
-
:
|
|
50
|
-
:
|
|
51
|
-
:
|
|
52
|
-
:
|
|
53
|
-
:
|
|
47
|
+
status: 200,
|
|
48
|
+
body: {
|
|
49
|
+
exception: {
|
|
50
|
+
error_class: 'ZeroDivisionError',
|
|
51
|
+
message: 'divided by 0',
|
|
52
|
+
backtrace: '/exception_notification/test/webhook_notifier_test.rb:48:in `/'
|
|
54
53
|
},
|
|
55
|
-
:
|
|
56
|
-
:
|
|
54
|
+
data: {
|
|
55
|
+
extra_data: { data_item1: 'datavalue1', data_item2: 'datavalue2' }
|
|
57
56
|
},
|
|
58
|
-
:
|
|
59
|
-
:
|
|
60
|
-
:
|
|
61
|
-
:
|
|
62
|
-
:
|
|
63
|
-
:
|
|
64
|
-
:
|
|
65
|
-
:
|
|
57
|
+
request: {
|
|
58
|
+
cookies: { cookie_item1: 'cookieitemvalue1', cookie_item2: 'cookieitemvalue2' },
|
|
59
|
+
url: 'http://example.com/example',
|
|
60
|
+
ip_address: '192.168.1.1',
|
|
61
|
+
environment: { env_item1: 'envitem1', env_item2: 'envitem2' },
|
|
62
|
+
controller: '#<ControllerName:0x007f9642a04d00>',
|
|
63
|
+
session: { session_item1: 'sessionitem1', session_item2: 'sessionitem2' },
|
|
64
|
+
parameters: { action: 'index', controller: 'projects' }
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
end
|
|
70
69
|
|
|
71
70
|
def fake_params
|
|
72
|
-
{
|
|
73
|
-
:
|
|
74
|
-
:
|
|
75
|
-
:
|
|
76
|
-
:
|
|
77
|
-
|
|
78
|
-
:
|
|
79
|
-
:
|
|
80
|
-
:backtrace => 'the backtrace'
|
|
71
|
+
params = {
|
|
72
|
+
body: {
|
|
73
|
+
server: Socket.gethostname,
|
|
74
|
+
process: $PROCESS_ID,
|
|
75
|
+
exception: {
|
|
76
|
+
error_class: 'ZeroDivisionError',
|
|
77
|
+
message: 'divided by 0'.inspect,
|
|
78
|
+
backtrace: 'the backtrace'
|
|
81
79
|
},
|
|
82
|
-
:
|
|
80
|
+
data: {}
|
|
83
81
|
}
|
|
84
82
|
}
|
|
83
|
+
|
|
84
|
+
params[:body][:rails_root] = Rails.root if defined?(::Rails) && Rails.respond_to?(:root)
|
|
85
|
+
|
|
86
|
+
params
|
|
85
87
|
end
|
|
86
88
|
|
|
87
89
|
def fake_exception
|
|
88
90
|
@fake_exception ||= begin
|
|
89
|
-
5/0
|
|
90
|
-
rescue
|
|
91
|
+
5 / 0
|
|
92
|
+
rescue StandardError => e
|
|
91
93
|
e
|
|
92
94
|
end
|
|
93
95
|
end
|
|
@@ -1,44 +1,47 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
class ExceptionOne < StandardError;end
|
|
4
|
-
class ExceptionTwo < StandardError;end
|
|
3
|
+
class ExceptionOne < StandardError; end
|
|
4
|
+
class ExceptionTwo < StandardError; end
|
|
5
5
|
|
|
6
6
|
class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
7
7
|
setup do
|
|
8
|
+
ExceptionNotifier.register_exception_notifier(:email, exception_recipients: %w[dummyexceptions@example.com])
|
|
9
|
+
|
|
8
10
|
@notifier_calls = 0
|
|
9
|
-
@test_notifier =
|
|
11
|
+
@test_notifier = ->(_exception, _options) { @notifier_calls += 1 }
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
teardown do
|
|
13
15
|
ExceptionNotifier.error_grouping = false
|
|
14
16
|
ExceptionNotifier.notification_trigger = nil
|
|
15
|
-
ExceptionNotifier.class_eval(
|
|
16
|
-
|
|
17
|
+
ExceptionNotifier.class_eval('@@notifiers.delete_if { |k, _| k.to_s != "email"}') # reset notifiers
|
|
18
|
+
|
|
19
|
+
Rails.cache.clear if defined?(Rails) && Rails.respond_to?(:cache)
|
|
17
20
|
end
|
|
18
21
|
|
|
19
|
-
test
|
|
22
|
+
test 'should have default ignored exceptions' do
|
|
20
23
|
assert_equal ExceptionNotifier.ignored_exceptions,
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
['ActiveRecord::RecordNotFound', 'Mongoid::Errors::DocumentNotFound', 'AbstractController::ActionNotFound',
|
|
25
|
+
'ActionController::RoutingError', 'ActionController::UnknownFormat', 'ActionController::UrlGenerationError']
|
|
23
26
|
end
|
|
24
27
|
|
|
25
|
-
test
|
|
28
|
+
test 'should have email notifier registered' do
|
|
26
29
|
assert_equal ExceptionNotifier.notifiers, [:email]
|
|
27
30
|
end
|
|
28
31
|
|
|
29
|
-
test
|
|
32
|
+
test 'should have a valid email notifier' do
|
|
30
33
|
@email_notifier = ExceptionNotifier.registered_exception_notifier(:email)
|
|
31
34
|
refute_nil @email_notifier
|
|
32
35
|
assert_equal @email_notifier.class, ExceptionNotifier::EmailNotifier
|
|
33
36
|
assert_respond_to @email_notifier, :call
|
|
34
37
|
end
|
|
35
38
|
|
|
36
|
-
test
|
|
39
|
+
test 'should allow register/unregister another notifier' do
|
|
37
40
|
called = false
|
|
38
|
-
proc_notifier =
|
|
41
|
+
proc_notifier = ->(_exception, _options) { called = true }
|
|
39
42
|
ExceptionNotifier.register_exception_notifier(:proc, proc_notifier)
|
|
40
43
|
|
|
41
|
-
assert_equal ExceptionNotifier.notifiers.sort, [
|
|
44
|
+
assert_equal ExceptionNotifier.notifiers.sort, %i[email proc]
|
|
42
45
|
|
|
43
46
|
exception = StandardError.new
|
|
44
47
|
|
|
@@ -49,27 +52,27 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
|
49
52
|
assert_equal ExceptionNotifier.notifiers, [:email]
|
|
50
53
|
end
|
|
51
54
|
|
|
52
|
-
test
|
|
55
|
+
test 'should allow select notifiers to send error to' do
|
|
53
56
|
notifier1_calls = 0
|
|
54
|
-
notifier1 =
|
|
57
|
+
notifier1 = ->(_exception, _options) { notifier1_calls += 1 }
|
|
55
58
|
ExceptionNotifier.register_exception_notifier(:notifier1, notifier1)
|
|
56
59
|
|
|
57
60
|
notifier2_calls = 0
|
|
58
|
-
notifier2 =
|
|
61
|
+
notifier2 = ->(_exception, _options) { notifier2_calls += 1 }
|
|
59
62
|
ExceptionNotifier.register_exception_notifier(:notifier2, notifier2)
|
|
60
63
|
|
|
61
|
-
assert_equal ExceptionNotifier.notifiers.sort, [
|
|
64
|
+
assert_equal ExceptionNotifier.notifiers.sort, %i[email notifier1 notifier2]
|
|
62
65
|
|
|
63
66
|
exception = StandardError.new
|
|
64
67
|
ExceptionNotifier.notify_exception(exception)
|
|
65
68
|
assert_equal notifier1_calls, 1
|
|
66
69
|
assert_equal notifier2_calls, 1
|
|
67
70
|
|
|
68
|
-
ExceptionNotifier.notify_exception(exception,
|
|
71
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :notifier1)
|
|
69
72
|
assert_equal notifier1_calls, 2
|
|
70
73
|
assert_equal notifier2_calls, 1
|
|
71
74
|
|
|
72
|
-
ExceptionNotifier.notify_exception(exception,
|
|
75
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :notifier2)
|
|
73
76
|
assert_equal notifier1_calls, 2
|
|
74
77
|
assert_equal notifier2_calls, 2
|
|
75
78
|
|
|
@@ -78,39 +81,39 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
|
78
81
|
assert_equal ExceptionNotifier.notifiers, [:email]
|
|
79
82
|
end
|
|
80
83
|
|
|
81
|
-
test
|
|
82
|
-
env =
|
|
83
|
-
ExceptionNotifier.ignore_if do |
|
|
84
|
-
env !=
|
|
84
|
+
test 'should ignore exception if satisfies conditional ignore' do
|
|
85
|
+
env = 'production'
|
|
86
|
+
ExceptionNotifier.ignore_if do |_exception, _options|
|
|
87
|
+
env != 'production'
|
|
85
88
|
end
|
|
86
89
|
|
|
87
90
|
ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
|
|
88
91
|
|
|
89
92
|
exception = StandardError.new
|
|
90
93
|
|
|
91
|
-
ExceptionNotifier.notify_exception(exception,
|
|
94
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
|
92
95
|
assert_equal @notifier_calls, 1
|
|
93
96
|
|
|
94
|
-
env =
|
|
95
|
-
ExceptionNotifier.notify_exception(exception,
|
|
97
|
+
env = 'development'
|
|
98
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
|
96
99
|
assert_equal @notifier_calls, 1
|
|
97
100
|
|
|
98
101
|
ExceptionNotifier.clear_ignore_conditions!
|
|
99
102
|
end
|
|
100
103
|
|
|
101
|
-
test
|
|
104
|
+
test 'should not send notification if one of ignored exceptions' do
|
|
102
105
|
ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
|
|
103
106
|
|
|
104
107
|
exception = StandardError.new
|
|
105
108
|
|
|
106
|
-
ExceptionNotifier.notify_exception(exception,
|
|
109
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
|
107
110
|
assert_equal @notifier_calls, 1
|
|
108
111
|
|
|
109
|
-
ExceptionNotifier.notify_exception(exception,
|
|
112
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: 'StandardError')
|
|
110
113
|
assert_equal @notifier_calls, 1
|
|
111
114
|
end
|
|
112
115
|
|
|
113
|
-
test
|
|
116
|
+
test 'should not send notification if subclass of one of ignored exceptions' do
|
|
114
117
|
ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
|
|
115
118
|
|
|
116
119
|
class StandardErrorSubclass < StandardError
|
|
@@ -118,16 +121,16 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
|
118
121
|
|
|
119
122
|
exception = StandardErrorSubclass.new
|
|
120
123
|
|
|
121
|
-
ExceptionNotifier.notify_exception(exception,
|
|
124
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
|
122
125
|
assert_equal @notifier_calls, 1
|
|
123
126
|
|
|
124
|
-
ExceptionNotifier.notify_exception(exception,
|
|
127
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: 'StandardError')
|
|
125
128
|
assert_equal @notifier_calls, 1
|
|
126
129
|
end
|
|
127
130
|
|
|
128
|
-
test
|
|
131
|
+
test 'should call received block' do
|
|
129
132
|
@block_called = false
|
|
130
|
-
notifier =
|
|
133
|
+
notifier = ->(_exception, _options, &block) { block.call }
|
|
131
134
|
ExceptionNotifier.register_exception_notifier(:test, notifier)
|
|
132
135
|
|
|
133
136
|
exception = ExceptionOne.new
|
|
@@ -139,7 +142,7 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
|
139
142
|
assert @block_called
|
|
140
143
|
end
|
|
141
144
|
|
|
142
|
-
test
|
|
145
|
+
test 'should not call group_error! or send_notification? if error_grouping false' do
|
|
143
146
|
exception = StandardError.new
|
|
144
147
|
ExceptionNotifier.expects(:group_error!).never
|
|
145
148
|
ExceptionNotifier.expects(:send_notification?).never
|
|
@@ -147,7 +150,7 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
|
147
150
|
ExceptionNotifier.notify_exception(exception)
|
|
148
151
|
end
|
|
149
152
|
|
|
150
|
-
test
|
|
153
|
+
test 'should call group_error! and send_notification? if error_grouping true' do
|
|
151
154
|
ExceptionNotifier.error_grouping = true
|
|
152
155
|
|
|
153
156
|
exception = StandardError.new
|
|
@@ -157,7 +160,7 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
|
157
160
|
ExceptionNotifier.notify_exception(exception)
|
|
158
161
|
end
|
|
159
162
|
|
|
160
|
-
test
|
|
163
|
+
test 'should skip notification if send_notification? is false' do
|
|
161
164
|
ExceptionNotifier.error_grouping = true
|
|
162
165
|
|
|
163
166
|
exception = StandardError.new
|
|
@@ -167,7 +170,7 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
|
167
170
|
refute ExceptionNotifier.notify_exception(exception)
|
|
168
171
|
end
|
|
169
172
|
|
|
170
|
-
test
|
|
173
|
+
test 'should send notification if send_notification? is true' do
|
|
171
174
|
ExceptionNotifier.error_grouping = true
|
|
172
175
|
|
|
173
176
|
exception = StandardError.new
|
|
File without changes
|
|
File without changes
|