exception_notification 4.5.0 → 5.0.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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +16 -0
  3. data/CONTRIBUTING.md +23 -51
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +346 -0
  6. data/README.md +149 -59
  7. data/Rakefile +14 -7
  8. data/docs/notifiers/slack.md +0 -7
  9. data/exception_notification.gemspec +28 -31
  10. data/gemfiles/pinned_dependencies.gemfile +8 -0
  11. data/gemfiles/rails7_1.gemfile +5 -0
  12. data/gemfiles/rails7_2.gemfile +5 -0
  13. data/gemfiles/rails8_0.gemfile +5 -0
  14. data/lib/exception_notification/rack.rb +4 -4
  15. data/lib/exception_notification/rails/runner_tie.rb +31 -0
  16. data/lib/exception_notification/rails.rb +16 -0
  17. data/lib/exception_notification/rake.rb +56 -0
  18. data/lib/exception_notification/resque.rb +2 -2
  19. data/lib/exception_notification/sidekiq.rb +8 -23
  20. data/lib/exception_notification/version.rb +1 -1
  21. data/lib/exception_notification.rb +3 -3
  22. data/lib/exception_notifier/datadog_notifier.rb +26 -26
  23. data/lib/exception_notifier/email_notifier.rb +34 -30
  24. data/lib/exception_notifier/google_chat_notifier.rb +9 -9
  25. data/lib/exception_notifier/hipchat_notifier.rb +12 -12
  26. data/lib/exception_notifier/irc_notifier.rb +6 -6
  27. data/lib/exception_notifier/mattermost_notifier.rb +13 -13
  28. data/lib/exception_notifier/modules/error_grouping.rb +5 -5
  29. data/lib/exception_notifier/modules/formatter.rb +12 -12
  30. data/lib/exception_notifier/notifier.rb +3 -3
  31. data/lib/exception_notifier/slack_notifier.rb +18 -15
  32. data/lib/exception_notifier/sns_notifier.rb +9 -9
  33. data/lib/exception_notifier/teams_notifier.rb +66 -59
  34. data/lib/exception_notifier/views/exception_notifier/_data.html.erb +1 -1
  35. data/lib/exception_notifier/views/exception_notifier/_data.text.erb +1 -1
  36. data/lib/exception_notifier/views/exception_notifier/_session.html.erb +1 -1
  37. data/lib/exception_notifier/views/exception_notifier/_session.text.erb +1 -1
  38. data/lib/exception_notifier/webhook_notifier.rb +3 -3
  39. data/lib/exception_notifier.rb +27 -26
  40. data/lib/generators/exception_notification/install_generator.rb +8 -8
  41. data/lib/generators/exception_notification/templates/exception_notification.rb.erb +28 -27
  42. data/test/exception_notification/rack_test.rb +14 -14
  43. data/test/exception_notification/rake_test.rb +38 -0
  44. data/test/exception_notification/resque_test.rb +14 -14
  45. data/test/exception_notifier/datadog_notifier_test.rb +47 -46
  46. data/test/exception_notifier/email_notifier_test.rb +89 -104
  47. data/test/exception_notifier/google_chat_notifier_test.rb +77 -77
  48. data/test/exception_notifier/hipchat_notifier_test.rb +76 -80
  49. data/test/exception_notifier/irc_notifier_test.rb +26 -26
  50. data/test/exception_notifier/mattermost_notifier_test.rb +77 -77
  51. data/test/exception_notifier/modules/error_grouping_test.rb +39 -39
  52. data/test/exception_notifier/modules/formatter_test.rb +51 -49
  53. data/test/exception_notifier/sidekiq_test.rb +21 -10
  54. data/test/exception_notifier/slack_notifier_test.rb +66 -67
  55. data/test/exception_notifier/sns_notifier_test.rb +73 -70
  56. data/test/exception_notifier/teams_notifier_test.rb +33 -33
  57. data/test/exception_notifier/webhook_notifier_test.rb +34 -34
  58. data/test/exception_notifier_test.rb +51 -41
  59. data/test/test_helper.rb +8 -11
  60. metadata +58 -99
  61. data/Appraisals +0 -9
  62. data/examples/sample_app.rb +0 -56
  63. data/examples/sinatra/Gemfile +0 -10
  64. data/examples/sinatra/Gemfile.lock +0 -95
  65. data/examples/sinatra/Procfile +0 -2
  66. data/examples/sinatra/README.md +0 -11
  67. data/examples/sinatra/config.ru +0 -5
  68. data/examples/sinatra/sinatra_app.rb +0 -40
  69. data/gemfiles/rails5_2.gemfile +0 -7
  70. data/gemfiles/rails6_0.gemfile +0 -7
  71. data/gemfiles/rails6_1.gemfile +0 -7
  72. data/gemfiles/rails7_0.gemfile +0 -7
@@ -1,43 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'rack'
5
-
6
- # silence_warnings trick around require can be removed once
7
- # https://github.com/hipchat/hipchat-rb/pull/174
8
- # gets merged and released
9
- silence_warnings do
10
- require 'hipchat'
11
- end
3
+ require "test_helper"
4
+ require "rack"
5
+ require "hipchat"
12
6
 
13
7
  class HipchatNotifierTest < ActiveSupport::TestCase
14
- test 'should send hipchat notification if properly configured' do
8
+ test "should send hipchat notification if properly configured" do
15
9
  options = {
16
- api_token: 'good_token',
17
- room_name: 'room_name',
18
- color: 'yellow'
10
+ api_token: "good_token",
11
+ room_name: "room_name",
12
+ color: "yellow"
19
13
  }
20
14
 
21
- HipChat::Room.any_instance.expects(:send).with('Exception', fake_body, color: 'yellow')
15
+ HipChat::Room.any_instance.expects(:send).with("Exception", fake_body, {color: "yellow"})
22
16
 
23
17
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
24
18
  hipchat.call(fake_exception)
25
19
  end
26
20
 
27
- test 'should call pre/post_callback if specified' do
21
+ test "should call pre/post_callback if specified" do
28
22
  pre_callback_called = 0
29
23
  post_callback_called = 0
30
24
  options = {
31
- api_token: 'good_token',
32
- room_name: 'room_name',
33
- color: 'yellow',
25
+ api_token: "good_token",
26
+ room_name: "room_name",
27
+ color: "yellow",
34
28
  pre_callback: proc { |*| pre_callback_called += 1 },
35
29
  post_callback: proc { |*| post_callback_called += 1 }
36
30
  }
37
31
 
38
32
  HipChat::Room.any_instance
39
- .expects(:send)
40
- .with('Exception', fake_body, { color: 'yellow' }.merge(options.except(:api_token, :room_name)))
33
+ .expects(:send)
34
+ .with("Exception", fake_body, {color: "yellow"}.merge(options.except(:api_token, :room_name)))
41
35
 
42
36
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
43
37
  hipchat.call(fake_exception)
@@ -45,152 +39,154 @@ class HipchatNotifierTest < ActiveSupport::TestCase
45
39
  assert_equal(1, post_callback_called)
46
40
  end
47
41
 
48
- test 'should send hipchat notification without backtrace info if properly configured' do
42
+ test "should send hipchat notification without backtrace info if properly configured" do
49
43
  options = {
50
- api_token: 'good_token',
51
- room_name: 'room_name',
52
- color: 'yellow'
44
+ api_token: "good_token",
45
+ room_name: "room_name",
46
+ color: "yellow"
53
47
  }
54
48
 
55
- HipChat::Room.any_instance.expects(:send).with('Exception', fake_body_without_backtrace, color: 'yellow')
49
+ HipChat::Room.any_instance.expects(:send).with("Exception", fake_body_without_backtrace, {color: "yellow"})
56
50
 
57
51
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
58
52
  hipchat.call(fake_exception_without_backtrace)
59
53
  end
60
54
 
61
- test 'should allow custom from value if set' do
55
+ test "should allow custom from value if set" do
62
56
  options = {
63
- api_token: 'good_token',
64
- room_name: 'room_name',
65
- from: 'TrollFace'
57
+ api_token: "good_token",
58
+ room_name: "room_name",
59
+ from: "TrollFace"
66
60
  }
67
61
 
68
- HipChat::Room.any_instance.expects(:send).with('TrollFace', fake_body, color: 'red')
62
+ HipChat::Room.any_instance.expects(:send).with("TrollFace", fake_body, {color: "red"})
69
63
 
70
64
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
71
65
  hipchat.call(fake_exception)
72
66
  end
73
67
 
74
- test 'should not send hipchat notification if badly configured' do
68
+ test "should not send hipchat notification if badly configured" do
75
69
  wrong_params = {
76
- api_token: 'bad_token',
77
- room_name: 'test_room'
70
+ api_token: "bad_token",
71
+ room_name: "test_room"
78
72
  }
79
73
 
80
- HipChat::Client.stubs(:new).with('bad_token', api_version: 'v1').returns(nil)
74
+ HipChat::Client.stubs(:new).with("bad_token", {api_version: "v1"}).returns(nil)
81
75
 
82
76
  hipchat = ExceptionNotifier::HipchatNotifier.new(wrong_params)
83
77
  assert_nil hipchat.room
84
78
  end
85
79
 
86
- test 'should not send hipchat notification if api_key is missing' do
87
- wrong_params = { room_name: 'test_room' }
80
+ test "should not send hipchat notification if api_key is missing" do
81
+ wrong_params = {room_name: "test_room"}
88
82
 
89
- HipChat::Client.stubs(:new).with(nil, api_version: 'v1').returns(nil)
83
+ HipChat::Client.stubs(:new).with(nil, {api_version: "v1"}).returns(nil)
90
84
 
91
85
  hipchat = ExceptionNotifier::HipchatNotifier.new(wrong_params)
92
86
  assert_nil hipchat.room
93
87
  end
94
88
 
95
- test 'should not send hipchat notification if room_name is missing' do
96
- wrong_params = { api_token: 'good_token' }
89
+ test "should not send hipchat notification if room_name is missing" do
90
+ wrong_params = {api_token: "good_token"}
97
91
 
98
- HipChat::Client.stubs(:new).with('good_token', api_version: 'v1').returns({})
92
+ HipChat::Client.stubs(:new).with("good_token", {api_version: "v1"}).returns({})
99
93
 
100
94
  hipchat = ExceptionNotifier::HipchatNotifier.new(wrong_params)
101
95
  assert_nil hipchat.room
102
96
  end
103
97
 
104
- test 'should send hipchat notification with message_template' do
98
+ test "should send hipchat notification with message_template" do
105
99
  options = {
106
- api_token: 'good_token',
107
- room_name: 'room_name',
108
- color: 'yellow',
100
+ api_token: "good_token",
101
+ room_name: "room_name",
102
+ color: "yellow",
109
103
  message_template: ->(exception, _) { "This is custom message: '#{exception.message}'" }
110
104
  }
111
105
 
112
106
  HipChat::Room.any_instance
113
- .expects(:send)
114
- .with('Exception', "This is custom message: '#{fake_exception.message}'", color: 'yellow')
107
+ .expects(:send)
108
+ .with("Exception", "This is custom message: '#{fake_exception.message}'", {color: "yellow"})
115
109
 
116
110
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
117
111
  hipchat.call(fake_exception)
118
112
  end
119
113
 
120
- test 'should send hipchat notification exclude accumulated errors count' do
114
+ test "should send hipchat notification exclude accumulated errors count" do
121
115
  options = {
122
- api_token: 'good_token',
123
- room_name: 'room_name',
124
- color: 'yellow'
116
+ api_token: "good_token",
117
+ room_name: "room_name",
118
+ color: "yellow"
125
119
  }
126
120
 
127
- HipChat::Room.any_instance.expects(:send).with { |_, msg, _| msg.start_with?('A new exception occurred:') }
121
+ HipChat::Room.any_instance.expects(:send).with { |_, msg, _| msg.start_with?("A new exception occurred:") }
128
122
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
129
123
  hipchat.call(fake_exception)
130
124
  end
131
125
 
132
- test 'should send hipchat notification include accumulated errors count' do
126
+ test "should send hipchat notification include accumulated errors count" do
133
127
  options = {
134
- api_token: 'good_token',
135
- room_name: 'room_name',
136
- color: 'yellow'
128
+ api_token: "good_token",
129
+ room_name: "room_name",
130
+ color: "yellow"
137
131
  }
138
132
 
139
- HipChat::Room.any_instance.expects(:send).with { |_, msg, _| msg.start_with?('The exception occurred 3 times:') }
133
+ HipChat::Room.any_instance.expects(:send).with { |_, msg, _| msg.start_with?("The exception occurred 3 times:") }
140
134
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
141
135
  hipchat.call(fake_exception, accumulated_errors_count: 3)
142
136
  end
143
137
 
144
- test 'should send hipchat notification with HTML-escaped meessage if using default message_template' do
138
+ test "should send hipchat notification with HTML-escaped meessage if using default message_template" do
145
139
  options = {
146
- api_token: 'good_token',
147
- room_name: 'room_name',
148
- color: 'yellow'
140
+ api_token: "good_token",
141
+ room_name: "room_name",
142
+ color: "yellow"
149
143
  }
150
144
 
151
145
  exception = fake_exception_with_html_characters
152
146
  body = "A new exception occurred: '#{Rack::Utils.escape_html(exception.message)}' on '#{exception.backtrace.first}'"
153
147
 
154
- HipChat::Room.any_instance.expects(:send).with('Exception', body, color: 'yellow')
148
+ HipChat::Room.any_instance.expects(:send).with("Exception", body, {color: "yellow"})
155
149
 
156
150
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
157
151
  hipchat.call(exception)
158
152
  end
159
153
 
160
- test 'should use APIv1 if api_version is not specified' do
154
+ test "should use APIv1 if api_version is not specified" do
161
155
  options = {
162
- api_token: 'good_token',
163
- room_name: 'room_name'
156
+ api_token: "good_token",
157
+ room_name: "room_name"
164
158
  }
165
159
 
166
- HipChat::Client.stubs(:new).with('good_token', api_version: 'v1').returns({})
160
+ HipChat::Client.expects(:new).with("good_token", {api_version: "v1"}).returns({})
167
161
 
168
162
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
169
163
  hipchat.call(fake_exception)
170
164
  end
171
165
 
172
- test 'should use APIv2 when specified' do
166
+ test "should use APIv2 when specified" do
173
167
  options = {
174
- api_token: 'good_token',
175
- room_name: 'room_name',
176
- api_version: 'v2'
168
+ api_token: "good_token",
169
+ room_name: "room_name",
170
+ api_version: "v2"
177
171
  }
178
172
 
179
- HipChat::Client.stubs(:new).with('good_token', api_version: 'v2').returns({})
173
+ HipChat::Client.expects(:new).with("good_token", {api_version: "v2"}).returns({})
180
174
 
181
175
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
182
176
  hipchat.call(fake_exception)
183
177
  end
184
178
 
185
- test 'should allow server_url value (for a self-hosted HipChat Server) if set' do
179
+ test "should allow server_url value (for a self-hosted HipChat Server) if set" do
186
180
  options = {
187
- api_token: 'good_token',
188
- room_name: 'room_name',
189
- api_version: 'v2',
190
- server_url: 'https://domain.com'
181
+ api_token: "good_token",
182
+ room_name: "room_name",
183
+ api_version: "v2",
184
+ server_url: "https://domain.com"
191
185
  }
192
186
 
193
- HipChat::Client.stubs(:new).with('good_token', api_version: 'v2', server_url: 'https://domain.com').returns({})
187
+ HipChat::Client.expects(:new)
188
+ .with("good_token", {api_version: "v2", server_url: "https://domain.com"})
189
+ .returns({})
194
190
 
195
191
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
196
192
  hipchat.call(fake_exception)
@@ -204,13 +200,13 @@ class HipchatNotifierTest < ActiveSupport::TestCase
204
200
 
205
201
  def fake_exception
206
202
  5 / 0
207
- rescue StandardError => e
203
+ rescue => e
208
204
  e
209
205
  end
210
206
 
211
207
  def fake_exception_with_html_characters
212
- raise StandardError, 'an error with <html> characters'
213
- rescue StandardError => e
208
+ raise StandardError, "an error with <html> characters"
209
+ rescue => e
214
210
  e
215
211
  end
216
212
 
@@ -219,6 +215,6 @@ class HipchatNotifierTest < ActiveSupport::TestCase
219
215
  end
220
216
 
221
217
  def fake_exception_without_backtrace
222
- StandardError.new('my custom error')
218
+ StandardError.new("my custom error")
223
219
  end
224
220
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'carrier-pigeon'
3
+ require "test_helper"
4
+ require "carrier-pigeon"
5
5
 
6
6
  class IrcNotifierTest < ActiveSupport::TestCase
7
- test 'should send irc notification if properly configured' do
7
+ test "should send irc notification if properly configured" do
8
8
  options = {
9
- domain: 'irc.example.com'
9
+ domain: "irc.example.com"
10
10
  }
11
11
 
12
12
  CarrierPigeon.expects(:send).with(has_key(:uri)) do |v|
@@ -17,15 +17,15 @@ class IrcNotifierTest < ActiveSupport::TestCase
17
17
  irc.call(fake_exception)
18
18
  end
19
19
 
20
- test 'should exclude errors count in message if :accumulated_errors_count nil' do
20
+ test "should exclude errors count in message if :accumulated_errors_count nil" do
21
21
  irc = ExceptionNotifier::IrcNotifier.new({})
22
22
  irc.stubs(:active?).returns(true)
23
23
 
24
- irc.expects(:send_message).with { |message| message.include?('divided by 0') }.once
24
+ irc.expects(:send_message).with { |message| message.include?("divided by 0") }.once
25
25
  irc.call(fake_exception)
26
26
  end
27
27
 
28
- test 'should include errors count in message if :accumulated_errors_count is 3' do
28
+ test "should include errors count in message if :accumulated_errors_count is 3" do
29
29
  irc = ExceptionNotifier::IrcNotifier.new({})
30
30
  irc.stubs(:active?).returns(true)
31
31
 
@@ -33,12 +33,12 @@ class IrcNotifierTest < ActiveSupport::TestCase
33
33
  irc.call(fake_exception, accumulated_errors_count: 3)
34
34
  end
35
35
 
36
- test 'should call pre/post_callback if specified' do
36
+ test "should call pre/post_callback if specified" do
37
37
  pre_callback_called = 0
38
38
  post_callback_called = 0
39
39
 
40
40
  options = {
41
- domain: 'irc.example.com',
41
+ domain: "irc.example.com",
42
42
  pre_callback: proc { |*| pre_callback_called += 1 },
43
43
  post_callback: proc { |*| post_callback_called += 1 }
44
44
  }
@@ -53,9 +53,9 @@ class IrcNotifierTest < ActiveSupport::TestCase
53
53
  assert_equal(1, post_callback_called)
54
54
  end
55
55
 
56
- test 'should send irc notification without backtrace info if properly configured' do
56
+ test "should send irc notification without backtrace info if properly configured" do
57
57
  options = {
58
- domain: 'irc.example.com'
58
+ domain: "irc.example.com"
59
59
  }
60
60
 
61
61
  CarrierPigeon.expects(:send).with(has_key(:uri)) do |v|
@@ -66,24 +66,24 @@ class IrcNotifierTest < ActiveSupport::TestCase
66
66
  irc.call(fake_exception_without_backtrace)
67
67
  end
68
68
 
69
- test 'should properly construct URI from constituent parts' do
69
+ test "should properly construct URI from constituent parts" do
70
70
  options = {
71
- nick: 'BadNewsBot',
72
- password: 'secret',
73
- domain: 'irc.example.com',
71
+ nick: "BadNewsBot",
72
+ password: "secret",
73
+ domain: "irc.example.com",
74
74
  port: 9999,
75
- channel: '#exceptions'
75
+ channel: "#exceptions"
76
76
  }
77
77
 
78
- CarrierPigeon.expects(:send).with(has_entry(uri: 'irc://BadNewsBot:secret@irc.example.com:9999/#exceptions'))
78
+ CarrierPigeon.expects(:send).with(has_entry(uri: "irc://BadNewsBot:secret@irc.example.com:9999/#exceptions"))
79
79
 
80
80
  irc = ExceptionNotifier::IrcNotifier.new(options)
81
81
  irc.call(fake_exception)
82
82
  end
83
83
 
84
- test 'should properly add recipients if specified' do
84
+ test "should properly add recipients if specified" do
85
85
  options = {
86
- domain: 'irc.example.com',
86
+ domain: "irc.example.com",
87
87
  recipients: %w[peter michael samir]
88
88
  }
89
89
 
@@ -95,13 +95,13 @@ class IrcNotifierTest < ActiveSupport::TestCase
95
95
  irc.call(fake_exception)
96
96
  end
97
97
 
98
- test 'should properly set miscellaneous options' do
98
+ test "should properly set miscellaneous options" do
99
99
  options = {
100
- domain: 'irc.example.com',
100
+ domain: "irc.example.com",
101
101
  ssl: true,
102
102
  join: true,
103
103
  notice: true,
104
- prefix: '[test notification]'
104
+ prefix: "[test notification]"
105
105
  }
106
106
 
107
107
  entries = {
@@ -118,8 +118,8 @@ class IrcNotifierTest < ActiveSupport::TestCase
118
118
  irc.call(fake_exception)
119
119
  end
120
120
 
121
- test 'should not send irc notification if badly configured' do
122
- wrong_params = { domain: '##scriptkiddie.com###' }
121
+ test "should not send irc notification if badly configured" do
122
+ wrong_params = {domain: "##scriptkiddie.com###"}
123
123
  irc = ExceptionNotifier::IrcNotifier.new(wrong_params)
124
124
 
125
125
  assert_nil irc.call(fake_exception)
@@ -129,11 +129,11 @@ class IrcNotifierTest < ActiveSupport::TestCase
129
129
 
130
130
  def fake_exception
131
131
  5 / 0
132
- rescue StandardError => e
132
+ rescue => e
133
133
  e
134
134
  end
135
135
 
136
136
  def fake_exception_without_backtrace
137
- StandardError.new('my custom error')
137
+ StandardError.new("my custom error")
138
138
  end
139
139
  end