exception_notification 5.0.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +14 -0
  3. data/exception_notification.gemspec +9 -2
  4. data/lib/exception_notification/version.rb +1 -1
  5. metadata +2 -31
  6. data/Gemfile +0 -5
  7. data/Gemfile.lock +0 -346
  8. data/gemfiles/pinned_dependencies.gemfile +0 -8
  9. data/gemfiles/rails7_1.gemfile +0 -5
  10. data/gemfiles/rails7_2.gemfile +0 -5
  11. data/gemfiles/rails8_0.gemfile +0 -5
  12. data/test/exception_notification/rack_test.rb +0 -106
  13. data/test/exception_notification/rake_test.rb +0 -38
  14. data/test/exception_notification/resque_test.rb +0 -54
  15. data/test/exception_notifier/datadog_notifier_test.rb +0 -154
  16. data/test/exception_notifier/email_notifier_test.rb +0 -342
  17. data/test/exception_notifier/google_chat_notifier_test.rb +0 -185
  18. data/test/exception_notifier/hipchat_notifier_test.rb +0 -220
  19. data/test/exception_notifier/irc_notifier_test.rb +0 -139
  20. data/test/exception_notifier/mattermost_notifier_test.rb +0 -251
  21. data/test/exception_notifier/modules/error_grouping_test.rb +0 -167
  22. data/test/exception_notifier/modules/formatter_test.rb +0 -154
  23. data/test/exception_notifier/sidekiq_test.rb +0 -41
  24. data/test/exception_notifier/slack_notifier_test.rb +0 -228
  25. data/test/exception_notifier/sns_notifier_test.rb +0 -181
  26. data/test/exception_notifier/teams_notifier_test.rb +0 -92
  27. data/test/exception_notifier/webhook_notifier_test.rb +0 -98
  28. data/test/exception_notifier_test.rb +0 -298
  29. data/test/support/exception_notifier_helper.rb +0 -14
  30. data/test/support/views/exception_notifier/_new_bkg_section.html.erb +0 -1
  31. data/test/support/views/exception_notifier/_new_bkg_section.text.erb +0 -1
  32. data/test/support/views/exception_notifier/_new_section.html.erb +0 -1
  33. data/test/support/views/exception_notifier/_new_section.text.erb +0 -1
  34. data/test/test_helper.rb +0 -16
@@ -1,298 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class ExceptionOne < StandardError; end
6
-
7
- class ExceptionTwo < StandardError; end
8
-
9
- class StandardErrorSubclass < StandardError; end
10
-
11
- class ExceptionNotifierTest < ActiveSupport::TestCase
12
- setup do
13
- ExceptionNotifier.register_exception_notifier(:email, exception_recipients: %w[dummyexceptions@example.com])
14
-
15
- @notifier_calls = 0
16
- @test_notifier = ->(_exception, _options) { @notifier_calls += 1 }
17
- end
18
-
19
- teardown do
20
- ExceptionNotifier.reset_notifiers!
21
-
22
- Rails.cache.clear if defined?(Rails) && Rails.respond_to?(:cache)
23
- end
24
-
25
- test "should have default ignored exceptions" do
26
- assert_equal ExceptionNotifier.ignored_exceptions,
27
- ["ActiveRecord::RecordNotFound", "Mongoid::Errors::DocumentNotFound",
28
- "AbstractController::ActionNotFound", "ActionController::RoutingError",
29
- "ActionController::UnknownFormat", "ActionController::UrlGenerationError",
30
- "ActionDispatch::Http::MimeNegotiation::InvalidType",
31
- "Rack::Utils::InvalidParameterError"]
32
- end
33
-
34
- test "should have email notifier registered" do
35
- assert_equal ExceptionNotifier.notifiers, [:email]
36
- end
37
-
38
- test "should have a valid email notifier" do
39
- @email_notifier = ExceptionNotifier.registered_exception_notifier(:email)
40
- refute_nil @email_notifier
41
- assert_equal @email_notifier.class, ExceptionNotifier::EmailNotifier
42
- assert_respond_to @email_notifier, :call
43
- end
44
-
45
- test "should allow register/unregister another notifier" do
46
- called = false
47
- proc_notifier = ->(_exception, _options) { called = true }
48
- ExceptionNotifier.register_exception_notifier(:proc, proc_notifier)
49
-
50
- assert_equal ExceptionNotifier.notifiers.sort, %i[email proc]
51
-
52
- exception = StandardError.new
53
-
54
- ExceptionNotifier.notify_exception(exception)
55
- assert called
56
-
57
- ExceptionNotifier.unregister_exception_notifier(:proc)
58
- assert_equal ExceptionNotifier.notifiers, [:email]
59
- end
60
-
61
- test "should allow select notifiers to send error to" do
62
- notifier1_calls = 0
63
- notifier1 = ->(_exception, _options) { notifier1_calls += 1 }
64
- ExceptionNotifier.register_exception_notifier(:notifier1, notifier1)
65
-
66
- notifier2_calls = 0
67
- notifier2 = ->(_exception, _options) { notifier2_calls += 1 }
68
- ExceptionNotifier.register_exception_notifier(:notifier2, notifier2)
69
-
70
- assert_equal ExceptionNotifier.notifiers.sort, %i[email notifier1 notifier2]
71
-
72
- exception = StandardError.new
73
- ExceptionNotifier.notify_exception(exception)
74
- assert_equal notifier1_calls, 1
75
- assert_equal notifier2_calls, 1
76
-
77
- ExceptionNotifier.notify_exception(exception, notifiers: :notifier1)
78
- assert_equal notifier1_calls, 2
79
- assert_equal notifier2_calls, 1
80
-
81
- ExceptionNotifier.notify_exception(exception, notifiers: :notifier2)
82
- assert_equal notifier1_calls, 2
83
- assert_equal notifier2_calls, 2
84
-
85
- ExceptionNotifier.unregister_exception_notifier(:notifier1)
86
- ExceptionNotifier.unregister_exception_notifier(:notifier2)
87
- assert_equal ExceptionNotifier.notifiers, [:email]
88
- end
89
-
90
- test "should ignore exception if satisfies conditional ignore" do
91
- env = "production"
92
- ExceptionNotifier.ignore_if do |_exception, _options|
93
- env != "production"
94
- end
95
-
96
- ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
97
-
98
- exception = StandardError.new
99
-
100
- ExceptionNotifier.notify_exception(exception, notifiers: :test)
101
- assert_equal @notifier_calls, 1
102
-
103
- env = "development"
104
- ExceptionNotifier.notify_exception(exception, notifiers: :test)
105
- assert_equal @notifier_calls, 1
106
- end
107
-
108
- test "should ignore exception if satisfies by-notifier conditional ignore" do
109
- notifier1_calls = 0
110
- notifier1 = ->(_exception, _options) { notifier1_calls += 1 }
111
- ExceptionNotifier.register_exception_notifier(:notifier1, notifier1)
112
-
113
- notifier2_calls = 0
114
- notifier2 = ->(_exception, _options) { notifier2_calls += 1 }
115
- ExceptionNotifier.register_exception_notifier(:notifier2, notifier2)
116
-
117
- env = "production"
118
- ExceptionNotifier.ignore_notifier_if(:notifier1) do |_exception, _options|
119
- env == "development"
120
- end
121
- ExceptionNotifier.ignore_notifier_if(:notifier2) do |_exception, _options|
122
- env == "production"
123
- end
124
-
125
- exception = StandardError.new
126
-
127
- ExceptionNotifier.notify_exception(exception)
128
- assert_equal notifier1_calls, 1
129
- assert_equal notifier2_calls, 0
130
-
131
- env = "development"
132
-
133
- ExceptionNotifier.notify_exception(exception)
134
- assert_equal notifier1_calls, 1
135
- assert_equal notifier2_calls, 1
136
-
137
- env = "test"
138
-
139
- ExceptionNotifier.notify_exception(exception)
140
- assert_equal notifier1_calls, 2
141
- assert_equal notifier2_calls, 2
142
- end
143
-
144
- test "should return false if all the registered notifiers are ignored" do
145
- ExceptionNotifier.notifiers.each do |notifier|
146
- # make sure to register no other notifiers but the tested ones
147
- ExceptionNotifier.unregister_exception_notifier(notifier)
148
- end
149
-
150
- ExceptionNotifier.register_exception_notifier(:notifier1, ->(_, _) {})
151
- ExceptionNotifier.register_exception_notifier(:notifier2, ->(_, _) {})
152
-
153
- ExceptionNotifier.ignore_notifier_if(:notifier1) do |exception, _options|
154
- exception.message =~ /non_critical_error/
155
- end
156
- ExceptionNotifier.ignore_notifier_if(:notifier2) do |exception, _options|
157
- exception.message =~ /non_critical_error/
158
- end
159
-
160
- exception = StandardError.new("a non_critical_error occured.")
161
-
162
- refute ExceptionNotifier.notify_exception(exception)
163
- end
164
-
165
- test "should return true if one of the notifiers fires" do
166
- ExceptionNotifier.notifiers.each do |notifier|
167
- # make sure to register no other notifiers but the tested ones
168
- ExceptionNotifier.unregister_exception_notifier(notifier)
169
- end
170
-
171
- ExceptionNotifier.register_exception_notifier(:notifier1, ->(_, _) {})
172
- ExceptionNotifier.register_exception_notifier(:notifier2, ->(_, _) {})
173
-
174
- ExceptionNotifier.ignore_notifier_if(:notifier1) do |exception, _options|
175
- exception.message =~ /non-critical\serror/
176
- end
177
-
178
- exception = StandardError.new("a non-critical error occured")
179
-
180
- assert ExceptionNotifier.notify_exception(exception)
181
- end
182
-
183
- test "should not send notification if one of ignored exceptions" do
184
- ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
185
-
186
- exception = StandardError.new
187
-
188
- ExceptionNotifier.notify_exception(exception, notifiers: :test)
189
- assert_equal @notifier_calls, 1
190
-
191
- ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: "StandardError")
192
- assert_equal @notifier_calls, 1
193
- end
194
-
195
- test "should not send notification if subclass of one of ignored exceptions" do
196
- ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
197
-
198
- exception = StandardErrorSubclass.new
199
-
200
- ExceptionNotifier.notify_exception(exception, notifiers: :test)
201
- assert_equal @notifier_calls, 1
202
-
203
- ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: "StandardError")
204
- assert_equal @notifier_calls, 1
205
- end
206
-
207
- test "should not send notification if extended module one of ignored exceptions" do
208
- ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
209
-
210
- # Define module at runtime
211
- Object.const_set(:StandardErrorModule, Module.new)
212
-
213
- exception = StandardError.new
214
- exception.extend StandardErrorModule
215
-
216
- ExceptionNotifier.notify_exception(exception, notifiers: :test)
217
- assert_equal @notifier_calls, 1
218
-
219
- ignore_exceptions = "StandardErrorModule"
220
- ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: ignore_exceptions)
221
- assert_equal @notifier_calls, 1
222
- ensure
223
- # Clean up by removing the module
224
- Object.send(:remove_const, :StandardErrorModule)
225
- end
226
-
227
- test "should not send notification if prepended module at singleton class one of ignored exceptions" do
228
- ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
229
-
230
- # Define module at runtime
231
- Object.const_set(:StandardErrorModule, Module.new)
232
-
233
- exception = StandardError.new
234
- exception.singleton_class.prepend StandardErrorModule
235
-
236
- ExceptionNotifier.notify_exception(exception, notifiers: :test)
237
- assert_equal @notifier_calls, 1
238
-
239
- ignore_exceptions = "StandardErrorModule"
240
- ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: ignore_exceptions)
241
- assert_equal @notifier_calls, 1
242
- ensure
243
- # Clean up by removing the module
244
- Object.send(:remove_const, :StandardErrorModule)
245
- end
246
-
247
- test "should call received block" do
248
- @block_called = false
249
- notifier = ->(_exception, _options, &block) { block.call }
250
- ExceptionNotifier.register_exception_notifier(:test, notifier)
251
-
252
- exception = ExceptionOne.new
253
-
254
- ExceptionNotifier.notify_exception(exception) do
255
- @block_called = true
256
- end
257
-
258
- assert @block_called
259
- end
260
-
261
- test "should not call group_error! or send_notification? if error_grouping false" do
262
- exception = StandardError.new
263
- ExceptionNotifier.expects(:group_error!).never
264
- ExceptionNotifier.expects(:send_notification?).never
265
-
266
- ExceptionNotifier.notify_exception(exception)
267
- end
268
-
269
- test "should call group_error! and send_notification? if error_grouping true" do
270
- ExceptionNotifier.error_grouping = true
271
-
272
- exception = StandardError.new
273
- ExceptionNotifier.expects(:group_error!).once
274
- ExceptionNotifier.expects(:send_notification?).once
275
-
276
- ExceptionNotifier.notify_exception(exception)
277
- end
278
-
279
- test "should skip notification if send_notification? is false" 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(false)
285
-
286
- refute ExceptionNotifier.notify_exception(exception)
287
- end
288
-
289
- test "should send notification if send_notification? is true" do
290
- ExceptionNotifier.error_grouping = true
291
-
292
- exception = StandardError.new
293
- ExceptionNotifier.expects(:group_error!).once.returns(1)
294
- ExceptionNotifier.expects(:send_notification?).with(exception, 1).once.returns(true)
295
-
296
- assert ExceptionNotifier.notify_exception(exception)
297
- end
298
- 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,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "exception_notification"
5
-
6
- require "minitest/autorun"
7
- require "mocha/minitest"
8
- require "active_support/test_case"
9
- require "action_mailer"
10
-
11
- ExceptionNotifier.testing_mode!
12
- require "support/exception_notifier_helper"
13
-
14
- Time.zone = "UTC"
15
- ActionMailer::Base.delivery_method = :test
16
- ActionMailer::Base.append_view_path "#{File.dirname(__FILE__)}/support/views"