exception_notification 4.4.0 → 4.4.1
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 +5 -5
- data/Appraisals +3 -1
- data/CHANGELOG.rdoc +10 -0
- data/Gemfile +2 -0
- data/README.md +34 -8
- data/Rakefile +2 -0
- data/examples/sample_app.rb +2 -0
- data/examples/sinatra/Gemfile +2 -0
- data/examples/sinatra/config.ru +2 -0
- data/examples/sinatra/sinatra_app.rb +6 -2
- data/exception_notification.gemspec +9 -8
- 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 +3 -3
- data/lib/exception_notification.rb +2 -0
- data/lib/exception_notification/rack.rb +24 -13
- data/lib/exception_notification/rails.rb +2 -0
- data/lib/exception_notification/resque.rb +2 -0
- data/lib/exception_notification/sidekiq.rb +5 -3
- data/lib/exception_notification/version.rb +3 -1
- data/lib/exception_notifier.rb +46 -7
- data/lib/exception_notifier/base_notifier.rb +8 -2
- data/lib/exception_notifier/campfire_notifier.rb +2 -0
- data/lib/exception_notifier/datadog_notifier.rb +12 -9
- data/lib/exception_notifier/email_notifier.rb +11 -3
- data/lib/exception_notifier/google_chat_notifier.rb +2 -0
- data/lib/exception_notifier/hipchat_notifier.rb +2 -0
- data/lib/exception_notifier/irc_notifier.rb +4 -3
- data/lib/exception_notifier/mattermost_notifier.rb +10 -0
- data/lib/exception_notifier/modules/backtrace_cleaner.rb +2 -0
- data/lib/exception_notifier/modules/error_grouping.rb +19 -9
- data/lib/exception_notifier/modules/formatter.rb +3 -0
- data/lib/exception_notifier/notifier.rb +5 -1
- data/lib/exception_notifier/slack_notifier.rb +2 -0
- data/lib/exception_notifier/sns_notifier.rb +4 -3
- data/lib/exception_notifier/teams_notifier.rb +10 -3
- data/lib/exception_notifier/webhook_notifier.rb +3 -3
- data/lib/generators/exception_notification/install_generator.rb +8 -2
- data/test/exception_notification/rack_test.rb +48 -2
- data/test/exception_notification/resque_test.rb +2 -0
- data/test/exception_notifier/campfire_notifier_test.rb +8 -1
- data/test/exception_notifier/datadog_notifier_test.rb +2 -0
- data/test/exception_notifier/email_notifier_test.rb +29 -3
- data/test/exception_notifier/google_chat_notifier_test.rb +15 -11
- data/test/exception_notifier/hipchat_notifier_test.rb +8 -2
- data/test/exception_notifier/irc_notifier_test.rb +2 -0
- data/test/exception_notifier/mattermost_notifier_test.rb +73 -24
- data/test/exception_notifier/modules/error_grouping_test.rb +2 -0
- data/test/exception_notifier/modules/formatter_test.rb +2 -0
- data/test/exception_notifier/sidekiq_test.rb +3 -11
- data/test/exception_notifier/slack_notifier_test.rb +12 -10
- data/test/exception_notifier/sns_notifier_test.rb +9 -7
- data/test/exception_notifier/teams_notifier_test.rb +2 -0
- data/test/exception_notifier/webhook_notifier_test.rb +6 -4
- data/test/exception_notifier_test.rb +112 -6
- data/test/support/exception_notifier_helper.rb +14 -0
- data/test/test_helper.rb +5 -1
- metadata +22 -27
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
require 'httparty'
|
3
5
|
|
@@ -88,9 +90,9 @@ class WebhookNotifierTest < ActiveSupport::TestCase
|
|
88
90
|
|
89
91
|
def fake_exception
|
90
92
|
@fake_exception ||= begin
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
93
|
+
5 / 0
|
94
|
+
rescue StandardError => e
|
95
|
+
e
|
96
|
+
end
|
95
97
|
end
|
96
98
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class ExceptionOne < StandardError; end
|
@@ -12,17 +14,16 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
12
14
|
end
|
13
15
|
|
14
16
|
teardown do
|
15
|
-
ExceptionNotifier.
|
16
|
-
ExceptionNotifier.notification_trigger = nil
|
17
|
-
ExceptionNotifier.class_eval('@@notifiers.delete_if { |k, _| k.to_s != "email"}') # reset notifiers
|
17
|
+
ExceptionNotifier.reset_notifiers!
|
18
18
|
|
19
19
|
Rails.cache.clear if defined?(Rails) && Rails.respond_to?(:cache)
|
20
20
|
end
|
21
21
|
|
22
22
|
test 'should have default ignored exceptions' do
|
23
23
|
assert_equal ExceptionNotifier.ignored_exceptions,
|
24
|
-
['ActiveRecord::RecordNotFound', 'Mongoid::Errors::DocumentNotFound',
|
25
|
-
'
|
24
|
+
['ActiveRecord::RecordNotFound', 'Mongoid::Errors::DocumentNotFound',
|
25
|
+
'AbstractController::ActionNotFound', 'ActionController::RoutingError',
|
26
|
+
'ActionController::UnknownFormat', 'ActionController::UrlGenerationError']
|
26
27
|
end
|
27
28
|
|
28
29
|
test 'should have email notifier registered' do
|
@@ -97,8 +98,81 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
97
98
|
env = 'development'
|
98
99
|
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
99
100
|
assert_equal @notifier_calls, 1
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'should ignore exception if satisfies by-notifier conditional ignore' do
|
104
|
+
notifier1_calls = 0
|
105
|
+
notifier1 = ->(_exception, _options) { notifier1_calls += 1 }
|
106
|
+
ExceptionNotifier.register_exception_notifier(:notifier1, notifier1)
|
107
|
+
|
108
|
+
notifier2_calls = 0
|
109
|
+
notifier2 = ->(_exception, _options) { notifier2_calls += 1 }
|
110
|
+
ExceptionNotifier.register_exception_notifier(:notifier2, notifier2)
|
111
|
+
|
112
|
+
env = 'production'
|
113
|
+
ExceptionNotifier.ignore_notifier_if(:notifier1) do |_exception, _options|
|
114
|
+
env == 'development'
|
115
|
+
end
|
116
|
+
ExceptionNotifier.ignore_notifier_if(:notifier2) do |_exception, _options|
|
117
|
+
env == 'production'
|
118
|
+
end
|
119
|
+
|
120
|
+
exception = StandardError.new
|
121
|
+
|
122
|
+
ExceptionNotifier.notify_exception(exception)
|
123
|
+
assert_equal notifier1_calls, 1
|
124
|
+
assert_equal notifier2_calls, 0
|
125
|
+
|
126
|
+
env = 'development'
|
127
|
+
|
128
|
+
ExceptionNotifier.notify_exception(exception)
|
129
|
+
assert_equal notifier1_calls, 1
|
130
|
+
assert_equal notifier2_calls, 1
|
131
|
+
|
132
|
+
env = 'test'
|
133
|
+
|
134
|
+
ExceptionNotifier.notify_exception(exception)
|
135
|
+
assert_equal notifier1_calls, 2
|
136
|
+
assert_equal notifier2_calls, 2
|
137
|
+
end
|
138
|
+
|
139
|
+
test 'should return false if all the registered notifiers are ignored' do
|
140
|
+
ExceptionNotifier.notifiers.each do |notifier|
|
141
|
+
# make sure to register no other notifiers but the tested ones
|
142
|
+
ExceptionNotifier.unregister_exception_notifier(notifier)
|
143
|
+
end
|
144
|
+
|
145
|
+
ExceptionNotifier.register_exception_notifier(:notifier1, ->(_, _) {})
|
146
|
+
ExceptionNotifier.register_exception_notifier(:notifier2, ->(_, _) {})
|
147
|
+
|
148
|
+
ExceptionNotifier.ignore_notifier_if(:notifier1) do |exception, _options|
|
149
|
+
exception.message =~ /non_critical_error/
|
150
|
+
end
|
151
|
+
ExceptionNotifier.ignore_notifier_if(:notifier2) do |exception, _options|
|
152
|
+
exception.message =~ /non_critical_error/
|
153
|
+
end
|
154
|
+
|
155
|
+
exception = StandardError.new('a non_critical_error occured.')
|
156
|
+
|
157
|
+
refute ExceptionNotifier.notify_exception(exception)
|
158
|
+
end
|
159
|
+
|
160
|
+
test 'should return true if one of the notifiers fires' do
|
161
|
+
ExceptionNotifier.notifiers.each do |notifier|
|
162
|
+
# make sure to register no other notifiers but the tested ones
|
163
|
+
ExceptionNotifier.unregister_exception_notifier(notifier)
|
164
|
+
end
|
165
|
+
|
166
|
+
ExceptionNotifier.register_exception_notifier(:notifier1, ->(_, _) {})
|
167
|
+
ExceptionNotifier.register_exception_notifier(:notifier2, ->(_, _) {})
|
100
168
|
|
101
|
-
ExceptionNotifier.
|
169
|
+
ExceptionNotifier.ignore_notifier_if(:notifier1) do |exception, _options|
|
170
|
+
exception.message =~ /non-critical\serror/
|
171
|
+
end
|
172
|
+
|
173
|
+
exception = StandardError.new('a non-critical error occured')
|
174
|
+
|
175
|
+
assert ExceptionNotifier.notify_exception(exception)
|
102
176
|
end
|
103
177
|
|
104
178
|
test 'should not send notification if one of ignored exceptions' do
|
@@ -128,6 +202,38 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
|
|
128
202
|
assert_equal @notifier_calls, 1
|
129
203
|
end
|
130
204
|
|
205
|
+
test 'should not send notification if extended module one of ignored exceptions' do
|
206
|
+
ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
|
207
|
+
|
208
|
+
module StandardErrorModule; end
|
209
|
+
|
210
|
+
exception = StandardError.new
|
211
|
+
exception.extend StandardErrorModule
|
212
|
+
|
213
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
214
|
+
assert_equal @notifier_calls, 1
|
215
|
+
|
216
|
+
ignore_exceptions = 'ExceptionNotifierTest::StandardErrorModule'
|
217
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: ignore_exceptions)
|
218
|
+
assert_equal @notifier_calls, 1
|
219
|
+
end
|
220
|
+
|
221
|
+
test 'should not send notification if prepended module at singleton class one of ignored exceptions' do
|
222
|
+
ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
|
223
|
+
|
224
|
+
module StandardErrorModule; end
|
225
|
+
|
226
|
+
exception = StandardError.new
|
227
|
+
exception.singleton_class.prepend StandardErrorModule
|
228
|
+
|
229
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
230
|
+
assert_equal @notifier_calls, 1
|
231
|
+
|
232
|
+
ignore_exceptions = 'ExceptionNotifierTest::StandardErrorModule'
|
233
|
+
ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: ignore_exceptions)
|
234
|
+
assert_equal @notifier_calls, 1
|
235
|
+
end
|
236
|
+
|
131
237
|
test 'should call received block' do
|
132
238
|
@block_called = false
|
133
239
|
notifier = ->(_exception, _options, &block) { block.call }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# this extension allows ExceptionNotifier to reset all the glocal settings
|
4
|
+
# (i.e. class vars that otherwise remains during the test)
|
5
|
+
# please remembeer to call this method each time after you set such settings
|
6
|
+
# to prevent order dependent test fails.
|
7
|
+
module ExceptionNotifier
|
8
|
+
def self.reset_notifiers!
|
9
|
+
@@notifiers = {}
|
10
|
+
clear_ignore_conditions!
|
11
|
+
ExceptionNotifier.error_grouping = false
|
12
|
+
ExceptionNotifier.notification_trigger = nil
|
13
|
+
end
|
14
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'coveralls'
|
2
4
|
Coveralls.wear!
|
3
5
|
|
4
|
-
$LOAD_PATH.unshift File.expand_path('
|
6
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
5
7
|
require 'exception_notification'
|
6
8
|
|
7
9
|
require 'minitest/autorun'
|
@@ -10,6 +12,8 @@ require 'active_support/test_case'
|
|
10
12
|
require 'action_mailer'
|
11
13
|
|
12
14
|
ExceptionNotifier.testing_mode!
|
15
|
+
require 'support/exception_notifier_helper'
|
16
|
+
|
13
17
|
Time.zone = 'UTC'
|
14
18
|
ActionMailer::Base.delivery_method = :test
|
15
19
|
ActionMailer::Base.append_view_path "#{File.dirname(__FILE__)}/support/views"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exception_notification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.4.
|
4
|
+
version: 4.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamis Buck
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionmailer
|
@@ -150,33 +150,33 @@ dependencies:
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: 0.10.2
|
152
152
|
- !ruby/object:Gem::Dependency
|
153
|
-
name:
|
153
|
+
name: mocha
|
154
154
|
requirement: !ruby/object:Gem::Requirement
|
155
155
|
requirements:
|
156
|
-
- - "
|
156
|
+
- - ">="
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version: 0.
|
158
|
+
version: 0.13.0
|
159
159
|
type: :development
|
160
160
|
prerelease: false
|
161
161
|
version_requirements: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
|
-
- - "
|
163
|
+
- - ">="
|
164
164
|
- !ruby/object:Gem::Version
|
165
|
-
version: 0.
|
165
|
+
version: 0.13.0
|
166
166
|
- !ruby/object:Gem::Dependency
|
167
|
-
name:
|
167
|
+
name: mock_redis
|
168
168
|
requirement: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
|
-
- - "
|
170
|
+
- - "~>"
|
171
171
|
- !ruby/object:Gem::Version
|
172
|
-
version: 0.
|
172
|
+
version: 0.19.0
|
173
173
|
type: :development
|
174
174
|
prerelease: false
|
175
175
|
version_requirements: !ruby/object:Gem::Requirement
|
176
176
|
requirements:
|
177
|
-
- - "
|
177
|
+
- - "~>"
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version: 0.
|
179
|
+
version: 0.19.0
|
180
180
|
- !ruby/object:Gem::Dependency
|
181
181
|
name: rails
|
182
182
|
requirement: !ruby/object:Gem::Requirement
|
@@ -217,34 +217,28 @@ dependencies:
|
|
217
217
|
requirements:
|
218
218
|
- - '='
|
219
219
|
- !ruby/object:Gem::Version
|
220
|
-
version: 0.
|
220
|
+
version: 0.78.0
|
221
221
|
type: :development
|
222
222
|
prerelease: false
|
223
223
|
version_requirements: !ruby/object:Gem::Requirement
|
224
224
|
requirements:
|
225
225
|
- - '='
|
226
226
|
- !ruby/object:Gem::Version
|
227
|
-
version: 0.
|
227
|
+
version: 0.78.0
|
228
228
|
- !ruby/object:Gem::Dependency
|
229
229
|
name: sidekiq
|
230
230
|
requirement: !ruby/object:Gem::Requirement
|
231
231
|
requirements:
|
232
|
-
- - "
|
233
|
-
- !ruby/object:Gem::Version
|
234
|
-
version: 3.0.0
|
235
|
-
- - "<"
|
232
|
+
- - ">="
|
236
233
|
- !ruby/object:Gem::Version
|
237
|
-
version:
|
234
|
+
version: 5.0.4
|
238
235
|
type: :development
|
239
236
|
prerelease: false
|
240
237
|
version_requirements: !ruby/object:Gem::Requirement
|
241
238
|
requirements:
|
242
|
-
- - "
|
243
|
-
- !ruby/object:Gem::Version
|
244
|
-
version: 3.0.0
|
245
|
-
- - "<"
|
239
|
+
- - ">="
|
246
240
|
- !ruby/object:Gem::Version
|
247
|
-
version:
|
241
|
+
version: 5.0.4
|
248
242
|
- !ruby/object:Gem::Dependency
|
249
243
|
name: slack-notifier
|
250
244
|
requirement: !ruby/object:Gem::Requirement
|
@@ -386,6 +380,7 @@ files:
|
|
386
380
|
- test/exception_notifier/teams_notifier_test.rb
|
387
381
|
- test/exception_notifier/webhook_notifier_test.rb
|
388
382
|
- test/exception_notifier_test.rb
|
383
|
+
- test/support/exception_notifier_helper.rb
|
389
384
|
- test/support/views/exception_notifier/_new_bkg_section.html.erb
|
390
385
|
- test/support/views/exception_notifier/_new_bkg_section.text.erb
|
391
386
|
- test/support/views/exception_notifier/_new_section.html.erb
|
@@ -403,15 +398,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
403
398
|
requirements:
|
404
399
|
- - ">="
|
405
400
|
- !ruby/object:Gem::Version
|
406
|
-
version: '2.
|
401
|
+
version: '2.3'
|
407
402
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
408
403
|
requirements:
|
409
404
|
- - ">="
|
410
405
|
- !ruby/object:Gem::Version
|
411
406
|
version: 1.8.11
|
412
407
|
requirements: []
|
413
|
-
|
414
|
-
rubygems_version: 2.5.1
|
408
|
+
rubygems_version: 3.1.2
|
415
409
|
signing_key:
|
416
410
|
specification_version: 4
|
417
411
|
summary: Exception notification for Rails apps
|
@@ -433,6 +427,7 @@ test_files:
|
|
433
427
|
- test/exception_notifier/teams_notifier_test.rb
|
434
428
|
- test/exception_notifier/webhook_notifier_test.rb
|
435
429
|
- test/exception_notifier_test.rb
|
430
|
+
- test/support/exception_notifier_helper.rb
|
436
431
|
- test/support/views/exception_notifier/_new_bkg_section.html.erb
|
437
432
|
- test/support/views/exception_notifier/_new_bkg_section.text.erb
|
438
433
|
- test/support/views/exception_notifier/_new_section.html.erb
|