exception_notification 4.6.0 → 5.0.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 +4 -4
- data/CHANGELOG.rdoc +30 -0
- data/CONTRIBUTING.md +23 -51
- data/README.md +65 -31
- data/Rakefile +14 -7
- data/exception_notification.gemspec +36 -32
- data/lib/exception_notification/rack.rb +4 -4
- data/lib/exception_notification/rails.rb +2 -2
- data/lib/exception_notification/rake.rb +3 -7
- data/lib/exception_notification/resque.rb +2 -2
- data/lib/exception_notification/sidekiq.rb +8 -23
- data/lib/exception_notification/version.rb +1 -1
- data/lib/exception_notification.rb +3 -3
- data/lib/exception_notifier/datadog_notifier.rb +26 -26
- data/lib/exception_notifier/email_notifier.rb +34 -30
- data/lib/exception_notifier/google_chat_notifier.rb +9 -9
- data/lib/exception_notifier/hipchat_notifier.rb +12 -12
- data/lib/exception_notifier/irc_notifier.rb +6 -6
- data/lib/exception_notifier/mattermost_notifier.rb +13 -13
- data/lib/exception_notifier/modules/error_grouping.rb +5 -5
- data/lib/exception_notifier/modules/formatter.rb +12 -12
- data/lib/exception_notifier/notifier.rb +3 -3
- data/lib/exception_notifier/slack_notifier.rb +16 -16
- data/lib/exception_notifier/sns_notifier.rb +9 -9
- data/lib/exception_notifier/teams_notifier.rb +61 -57
- data/lib/exception_notifier/webhook_notifier.rb +3 -3
- data/lib/exception_notifier.rb +27 -26
- data/lib/generators/exception_notification/install_generator.rb +7 -7
- data/lib/generators/exception_notification/templates/exception_notification.rb.erb +26 -27
- metadata +41 -110
- data/Appraisals +0 -9
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -352
- data/gemfiles/rails5_2.gemfile +0 -7
- data/gemfiles/rails6_0.gemfile +0 -7
- data/gemfiles/rails6_1.gemfile +0 -7
- data/gemfiles/rails7_0.gemfile +0 -7
- data/test/exception_notification/rack_test.rb +0 -106
- data/test/exception_notification/rake_test.rb +0 -38
- data/test/exception_notification/resque_test.rb +0 -54
- data/test/exception_notifier/datadog_notifier_test.rb +0 -153
- data/test/exception_notifier/email_notifier_test.rb +0 -351
- data/test/exception_notifier/google_chat_notifier_test.rb +0 -185
- data/test/exception_notifier/hipchat_notifier_test.rb +0 -218
- data/test/exception_notifier/irc_notifier_test.rb +0 -139
- data/test/exception_notifier/mattermost_notifier_test.rb +0 -251
- data/test/exception_notifier/modules/error_grouping_test.rb +0 -167
- data/test/exception_notifier/modules/formatter_test.rb +0 -152
- data/test/exception_notifier/sidekiq_test.rb +0 -34
- data/test/exception_notifier/slack_notifier_test.rb +0 -229
- data/test/exception_notifier/sns_notifier_test.rb +0 -178
- data/test/exception_notifier/teams_notifier_test.rb +0 -92
- data/test/exception_notifier/webhook_notifier_test.rb +0 -98
- data/test/exception_notifier_test.rb +0 -288
- data/test/support/exception_notifier_helper.rb +0 -14
- data/test/support/views/exception_notifier/_new_bkg_section.html.erb +0 -1
- data/test/support/views/exception_notifier/_new_bkg_section.text.erb +0 -1
- data/test/support/views/exception_notifier/_new_section.html.erb +0 -1
- data/test/support/views/exception_notifier/_new_section.text.erb +0 -1
- data/test/test_helper.rb +0 -19
@@ -1,288 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ExceptionOne < StandardError; end
|
6
|
-
class ExceptionTwo < StandardError; end
|
7
|
-
|
8
|
-
class ExceptionNotifierTest < ActiveSupport::TestCase
|
9
|
-
setup do
|
10
|
-
ExceptionNotifier.register_exception_notifier(:email, exception_recipients: %w[dummyexceptions@example.com])
|
11
|
-
|
12
|
-
@notifier_calls = 0
|
13
|
-
@test_notifier = ->(_exception, _options) { @notifier_calls += 1 }
|
14
|
-
end
|
15
|
-
|
16
|
-
teardown do
|
17
|
-
ExceptionNotifier.reset_notifiers!
|
18
|
-
|
19
|
-
Rails.cache.clear if defined?(Rails) && Rails.respond_to?(:cache)
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'should have default ignored exceptions' do
|
23
|
-
assert_equal ExceptionNotifier.ignored_exceptions,
|
24
|
-
['ActiveRecord::RecordNotFound', 'Mongoid::Errors::DocumentNotFound',
|
25
|
-
'AbstractController::ActionNotFound', 'ActionController::RoutingError',
|
26
|
-
'ActionController::UnknownFormat', 'ActionController::UrlGenerationError']
|
27
|
-
end
|
28
|
-
|
29
|
-
test 'should have email notifier registered' do
|
30
|
-
assert_equal ExceptionNotifier.notifiers, [:email]
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'should have a valid email notifier' do
|
34
|
-
@email_notifier = ExceptionNotifier.registered_exception_notifier(:email)
|
35
|
-
refute_nil @email_notifier
|
36
|
-
assert_equal @email_notifier.class, ExceptionNotifier::EmailNotifier
|
37
|
-
assert_respond_to @email_notifier, :call
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'should allow register/unregister another notifier' do
|
41
|
-
called = false
|
42
|
-
proc_notifier = ->(_exception, _options) { called = true }
|
43
|
-
ExceptionNotifier.register_exception_notifier(:proc, proc_notifier)
|
44
|
-
|
45
|
-
assert_equal ExceptionNotifier.notifiers.sort, %i[email proc]
|
46
|
-
|
47
|
-
exception = StandardError.new
|
48
|
-
|
49
|
-
ExceptionNotifier.notify_exception(exception)
|
50
|
-
assert called
|
51
|
-
|
52
|
-
ExceptionNotifier.unregister_exception_notifier(:proc)
|
53
|
-
assert_equal ExceptionNotifier.notifiers, [:email]
|
54
|
-
end
|
55
|
-
|
56
|
-
test 'should allow select notifiers to send error to' do
|
57
|
-
notifier1_calls = 0
|
58
|
-
notifier1 = ->(_exception, _options) { notifier1_calls += 1 }
|
59
|
-
ExceptionNotifier.register_exception_notifier(:notifier1, notifier1)
|
60
|
-
|
61
|
-
notifier2_calls = 0
|
62
|
-
notifier2 = ->(_exception, _options) { notifier2_calls += 1 }
|
63
|
-
ExceptionNotifier.register_exception_notifier(:notifier2, notifier2)
|
64
|
-
|
65
|
-
assert_equal ExceptionNotifier.notifiers.sort, %i[email notifier1 notifier2]
|
66
|
-
|
67
|
-
exception = StandardError.new
|
68
|
-
ExceptionNotifier.notify_exception(exception)
|
69
|
-
assert_equal notifier1_calls, 1
|
70
|
-
assert_equal notifier2_calls, 1
|
71
|
-
|
72
|
-
ExceptionNotifier.notify_exception(exception, notifiers: :notifier1)
|
73
|
-
assert_equal notifier1_calls, 2
|
74
|
-
assert_equal notifier2_calls, 1
|
75
|
-
|
76
|
-
ExceptionNotifier.notify_exception(exception, notifiers: :notifier2)
|
77
|
-
assert_equal notifier1_calls, 2
|
78
|
-
assert_equal notifier2_calls, 2
|
79
|
-
|
80
|
-
ExceptionNotifier.unregister_exception_notifier(:notifier1)
|
81
|
-
ExceptionNotifier.unregister_exception_notifier(:notifier2)
|
82
|
-
assert_equal ExceptionNotifier.notifiers, [:email]
|
83
|
-
end
|
84
|
-
|
85
|
-
test 'should ignore exception if satisfies conditional ignore' do
|
86
|
-
env = 'production'
|
87
|
-
ExceptionNotifier.ignore_if do |_exception, _options|
|
88
|
-
env != 'production'
|
89
|
-
end
|
90
|
-
|
91
|
-
ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
|
92
|
-
|
93
|
-
exception = StandardError.new
|
94
|
-
|
95
|
-
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
96
|
-
assert_equal @notifier_calls, 1
|
97
|
-
|
98
|
-
env = 'development'
|
99
|
-
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
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, ->(_, _) {})
|
168
|
-
|
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)
|
176
|
-
end
|
177
|
-
|
178
|
-
test 'should not send notification if one of ignored exceptions' do
|
179
|
-
ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
|
180
|
-
|
181
|
-
exception = StandardError.new
|
182
|
-
|
183
|
-
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
184
|
-
assert_equal @notifier_calls, 1
|
185
|
-
|
186
|
-
ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: 'StandardError')
|
187
|
-
assert_equal @notifier_calls, 1
|
188
|
-
end
|
189
|
-
|
190
|
-
test 'should not send notification if subclass of one of ignored exceptions' do
|
191
|
-
ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
|
192
|
-
|
193
|
-
class StandardErrorSubclass < StandardError
|
194
|
-
end
|
195
|
-
|
196
|
-
exception = StandardErrorSubclass.new
|
197
|
-
|
198
|
-
ExceptionNotifier.notify_exception(exception, notifiers: :test)
|
199
|
-
assert_equal @notifier_calls, 1
|
200
|
-
|
201
|
-
ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: 'StandardError')
|
202
|
-
assert_equal @notifier_calls, 1
|
203
|
-
end
|
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
|
-
|
237
|
-
test 'should call received block' do
|
238
|
-
@block_called = false
|
239
|
-
notifier = ->(_exception, _options, &block) { block.call }
|
240
|
-
ExceptionNotifier.register_exception_notifier(:test, notifier)
|
241
|
-
|
242
|
-
exception = ExceptionOne.new
|
243
|
-
|
244
|
-
ExceptionNotifier.notify_exception(exception) do
|
245
|
-
@block_called = true
|
246
|
-
end
|
247
|
-
|
248
|
-
assert @block_called
|
249
|
-
end
|
250
|
-
|
251
|
-
test 'should not call group_error! or send_notification? if error_grouping false' do
|
252
|
-
exception = StandardError.new
|
253
|
-
ExceptionNotifier.expects(:group_error!).never
|
254
|
-
ExceptionNotifier.expects(:send_notification?).never
|
255
|
-
|
256
|
-
ExceptionNotifier.notify_exception(exception)
|
257
|
-
end
|
258
|
-
|
259
|
-
test 'should call group_error! and send_notification? if error_grouping true' do
|
260
|
-
ExceptionNotifier.error_grouping = true
|
261
|
-
|
262
|
-
exception = StandardError.new
|
263
|
-
ExceptionNotifier.expects(:group_error!).once
|
264
|
-
ExceptionNotifier.expects(:send_notification?).once
|
265
|
-
|
266
|
-
ExceptionNotifier.notify_exception(exception)
|
267
|
-
end
|
268
|
-
|
269
|
-
test 'should skip notification if send_notification? is false' do
|
270
|
-
ExceptionNotifier.error_grouping = true
|
271
|
-
|
272
|
-
exception = StandardError.new
|
273
|
-
ExceptionNotifier.expects(:group_error!).once.returns(1)
|
274
|
-
ExceptionNotifier.expects(:send_notification?).with(exception, 1).once.returns(false)
|
275
|
-
|
276
|
-
refute ExceptionNotifier.notify_exception(exception)
|
277
|
-
end
|
278
|
-
|
279
|
-
test 'should send notification if send_notification? is true' do
|
280
|
-
ExceptionNotifier.error_grouping = true
|
281
|
-
|
282
|
-
exception = StandardError.new
|
283
|
-
ExceptionNotifier.expects(:group_error!).once.returns(1)
|
284
|
-
ExceptionNotifier.expects(:send_notification?).with(exception, 1).once.returns(true)
|
285
|
-
|
286
|
-
assert ExceptionNotifier.notify_exception(exception)
|
287
|
-
end
|
288
|
-
end
|
@@ -1,14 +0,0 @@
|
|
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
|
@@ -1 +0,0 @@
|
|
1
|
-
* New background section for testing
|
@@ -1 +0,0 @@
|
|
1
|
-
* New background section for testing
|
@@ -1 +0,0 @@
|
|
1
|
-
* New html section for testing
|
@@ -1 +0,0 @@
|
|
1
|
-
* New text section for testing
|
data/test/test_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'coveralls'
|
4
|
-
Coveralls.wear!
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
7
|
-
require 'exception_notification'
|
8
|
-
|
9
|
-
require 'minitest/autorun'
|
10
|
-
require 'mocha/minitest'
|
11
|
-
require 'active_support/test_case'
|
12
|
-
require 'action_mailer'
|
13
|
-
|
14
|
-
ExceptionNotifier.testing_mode!
|
15
|
-
require 'support/exception_notifier_helper'
|
16
|
-
|
17
|
-
Time.zone = 'UTC'
|
18
|
-
ActionMailer::Base.delivery_method = :test
|
19
|
-
ActionMailer::Base.append_view_path "#{File.dirname(__FILE__)}/support/views"
|