exception_notification 4.6.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 (59) 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 +27 -33
  6. data/README.md +65 -31
  7. data/Rakefile +14 -7
  8. data/exception_notification.gemspec +27 -30
  9. data/gemfiles/pinned_dependencies.gemfile +8 -0
  10. data/gemfiles/rails7_1.gemfile +5 -0
  11. data/gemfiles/rails7_2.gemfile +5 -0
  12. data/gemfiles/rails8_0.gemfile +5 -0
  13. data/lib/exception_notification/rack.rb +4 -4
  14. data/lib/exception_notification/rails.rb +2 -2
  15. data/lib/exception_notification/rake.rb +3 -7
  16. data/lib/exception_notification/resque.rb +2 -2
  17. data/lib/exception_notification/sidekiq.rb +8 -23
  18. data/lib/exception_notification/version.rb +1 -1
  19. data/lib/exception_notification.rb +3 -3
  20. data/lib/exception_notifier/datadog_notifier.rb +26 -26
  21. data/lib/exception_notifier/email_notifier.rb +34 -30
  22. data/lib/exception_notifier/google_chat_notifier.rb +9 -9
  23. data/lib/exception_notifier/hipchat_notifier.rb +12 -12
  24. data/lib/exception_notifier/irc_notifier.rb +6 -6
  25. data/lib/exception_notifier/mattermost_notifier.rb +13 -13
  26. data/lib/exception_notifier/modules/error_grouping.rb +5 -5
  27. data/lib/exception_notifier/modules/formatter.rb +12 -12
  28. data/lib/exception_notifier/notifier.rb +3 -3
  29. data/lib/exception_notifier/slack_notifier.rb +16 -16
  30. data/lib/exception_notifier/sns_notifier.rb +9 -9
  31. data/lib/exception_notifier/teams_notifier.rb +61 -57
  32. data/lib/exception_notifier/webhook_notifier.rb +3 -3
  33. data/lib/exception_notifier.rb +27 -26
  34. data/lib/generators/exception_notification/install_generator.rb +7 -7
  35. data/lib/generators/exception_notification/templates/exception_notification.rb.erb +26 -27
  36. data/test/exception_notification/rack_test.rb +14 -14
  37. data/test/exception_notification/rake_test.rb +13 -13
  38. data/test/exception_notification/resque_test.rb +14 -14
  39. data/test/exception_notifier/datadog_notifier_test.rb +47 -46
  40. data/test/exception_notifier/email_notifier_test.rb +89 -98
  41. data/test/exception_notifier/google_chat_notifier_test.rb +77 -77
  42. data/test/exception_notifier/hipchat_notifier_test.rb +76 -74
  43. data/test/exception_notifier/irc_notifier_test.rb +26 -26
  44. data/test/exception_notifier/mattermost_notifier_test.rb +77 -77
  45. data/test/exception_notifier/modules/error_grouping_test.rb +39 -39
  46. data/test/exception_notifier/modules/formatter_test.rb +51 -49
  47. data/test/exception_notifier/sidekiq_test.rb +17 -10
  48. data/test/exception_notifier/slack_notifier_test.rb +66 -67
  49. data/test/exception_notifier/sns_notifier_test.rb +73 -70
  50. data/test/exception_notifier/teams_notifier_test.rb +33 -33
  51. data/test/exception_notifier/webhook_notifier_test.rb +34 -34
  52. data/test/exception_notifier_test.rb +51 -41
  53. data/test/test_helper.rb +8 -11
  54. metadata +45 -85
  55. data/Appraisals +0 -9
  56. data/gemfiles/rails5_2.gemfile +0 -7
  57. data/gemfiles/rails6_0.gemfile +0 -7
  58. data/gemfiles/rails6_1.gemfile +0 -7
  59. data/gemfiles/rails7_0.gemfile +0 -7
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'timecop'
3
+ require "test_helper"
4
+ require "timecop"
5
5
 
6
6
  class FormatterTest < ActiveSupport::TestCase
7
7
  setup do
8
- @exception = RuntimeError.new('test')
9
- Timecop.freeze('2018-12-09 12:07:16 UTC')
8
+ @exception = RuntimeError.new("test")
9
+ Timecop.freeze("2018-12-09 12:07:16 UTC")
10
10
  end
11
11
 
12
12
  teardown do
@@ -16,14 +16,14 @@ class FormatterTest < ActiveSupport::TestCase
16
16
  #
17
17
  # #title
18
18
  #
19
- test 'title returns correct content' do
19
+ test "title returns correct content" do
20
20
  formatter = ExceptionNotifier::Formatter.new(@exception)
21
21
 
22
22
  title = if defined?(::Rails) && ::Rails.respond_to?(:env)
23
- '⚠️ Error occurred in test ⚠️'
24
- else
25
- '⚠️ Error occurred ⚠️'
26
- end
23
+ "⚠️ Error occurred in test ⚠️"
24
+ else
25
+ "⚠️ Error occurred ⚠️"
26
+ end
27
27
 
28
28
  assert_equal title, formatter.title
29
29
  end
@@ -31,69 +31,69 @@ class FormatterTest < ActiveSupport::TestCase
31
31
  #
32
32
  # #subtitle
33
33
  #
34
- test 'subtitle without accumulated error' do
34
+ test "subtitle without accumulated error" do
35
35
  formatter = ExceptionNotifier::Formatter.new(@exception)
36
- assert_equal 'A *RuntimeError* occurred.', formatter.subtitle
36
+ assert_equal "A *RuntimeError* occurred.", formatter.subtitle
37
37
  end
38
38
 
39
- test 'subtitle with accumulated error' do
39
+ test "subtitle with accumulated error" do
40
40
  formatter = ExceptionNotifier::Formatter.new(@exception, accumulated_errors_count: 3)
41
- assert_equal '3 *RuntimeError* occurred.', formatter.subtitle
41
+ assert_equal "3 *RuntimeError* occurred.", formatter.subtitle
42
42
  end
43
43
 
44
- test 'subtitle with controller' do
44
+ test "subtitle with controller" do
45
45
  env = Rack::MockRequest.env_for(
46
- '/', 'action_controller.instance' => test_controller
46
+ "/", "action_controller.instance" => test_controller
47
47
  )
48
48
 
49
49
  formatter = ExceptionNotifier::Formatter.new(@exception, env: env)
50
- assert_equal 'A *RuntimeError* occurred in *home#index*.', formatter.subtitle
50
+ assert_equal "A *RuntimeError* occurred in *home#index*.", formatter.subtitle
51
51
  end
52
52
 
53
53
  #
54
54
  # #app_name
55
55
  #
56
- test 'app_name defaults to Rails app name' do
56
+ test "app_name defaults to Rails app name" do
57
57
  formatter = ExceptionNotifier::Formatter.new(@exception)
58
58
 
59
59
  if defined?(::Rails) && ::Rails.respond_to?(:application)
60
- assert_equal 'dummy', formatter.app_name
60
+ assert_equal "dummy", formatter.app_name
61
61
  else
62
62
  assert_nil formatter.app_name
63
63
  end
64
64
  end
65
65
 
66
- test 'app_name can be overwritten using options' do
67
- formatter = ExceptionNotifier::Formatter.new(@exception, app_name: 'test')
68
- assert_equal 'test', formatter.app_name
66
+ test "app_name can be overwritten using options" do
67
+ formatter = ExceptionNotifier::Formatter.new(@exception, app_name: "test")
68
+ assert_equal "test", formatter.app_name
69
69
  end
70
70
 
71
71
  #
72
72
  # #request_message
73
73
  #
74
- test 'request_message when env set' do
74
+ test "request_message when env set" do
75
75
  text = [
76
- '```',
77
- '* url : http://test.address/?id=foo',
78
- '* http_method : GET',
79
- '* ip_address : 127.0.0.1',
80
- '* parameters : {"id"=>"foo"}',
81
- '* timestamp : 2018-12-09 12:07:16 UTC',
82
- '```'
76
+ "```",
77
+ "* url : http://test.address/?id=foo",
78
+ "* http_method : GET",
79
+ "* ip_address : 127.0.0.1",
80
+ "* parameters : #{{"id" => "foo"}}", # standard:disable Lint/LiteralInInterpolation:
81
+ "* timestamp : 2018-12-09 12:07:16 UTC",
82
+ "```"
83
83
  ].join("\n")
84
84
 
85
85
  env = Rack::MockRequest.env_for(
86
- '/',
87
- 'HTTP_HOST' => 'test.address',
88
- 'REMOTE_ADDR' => '127.0.0.1',
89
- params: { id: 'foo' }
86
+ "/",
87
+ "HTTP_HOST" => "test.address",
88
+ "REMOTE_ADDR" => "127.0.0.1",
89
+ :params => {id: "foo"}
90
90
  )
91
91
 
92
92
  formatter = ExceptionNotifier::Formatter.new(@exception, env: env)
93
93
  assert_equal text, formatter.request_message
94
94
  end
95
95
 
96
- test 'request_message when env not set' do
96
+ test "request_message when env not set" do
97
97
  formatter = ExceptionNotifier::Formatter.new(@exception)
98
98
  assert_nil formatter.request_message
99
99
  end
@@ -101,24 +101,24 @@ class FormatterTest < ActiveSupport::TestCase
101
101
  #
102
102
  # #backtrace_message
103
103
  #
104
- test 'backtrace_message when backtrace set' do
104
+ test "backtrace_message when backtrace set" do
105
105
  text = [
106
- '```',
106
+ "```",
107
107
  "* app/controllers/my_controller.rb:53:in `my_controller_params'",
108
108
  "* app/controllers/my_controller.rb:34:in `update'",
109
- '```'
109
+ "```"
110
110
  ].join("\n")
111
111
 
112
112
  @exception.set_backtrace([
113
- "app/controllers/my_controller.rb:53:in `my_controller_params'",
114
- "app/controllers/my_controller.rb:34:in `update'"
115
- ])
113
+ "app/controllers/my_controller.rb:53:in `my_controller_params'",
114
+ "app/controllers/my_controller.rb:34:in `update'"
115
+ ])
116
116
 
117
117
  formatter = ExceptionNotifier::Formatter.new(@exception)
118
118
  assert_equal text, formatter.backtrace_message
119
119
  end
120
120
 
121
- test 'backtrace_message when no backtrace' do
121
+ test "backtrace_message when no backtrace" do
122
122
  formatter = ExceptionNotifier::Formatter.new(@exception)
123
123
  assert_nil formatter.backtrace_message
124
124
  end
@@ -126,26 +126,28 @@ class FormatterTest < ActiveSupport::TestCase
126
126
  #
127
127
  # #controller_and_action
128
128
  #
129
- test 'correct controller_and_action if controller is present' do
129
+ test "correct controller_and_action if controller is present" do
130
130
  env = Rack::MockRequest.env_for(
131
- '/', 'action_controller.instance' => test_controller
131
+ "/", "action_controller.instance" => test_controller
132
132
  )
133
133
 
134
134
  formatter = ExceptionNotifier::Formatter.new(@exception, env: env)
135
- assert_equal 'home#index', formatter.controller_and_action
135
+ assert_equal "home#index", formatter.controller_and_action
136
136
  end
137
137
 
138
- test 'controller_and_action is nil if no controller' do
139
- env = Rack::MockRequest.env_for('/')
138
+ test "controller_and_action is nil if no controller" do
139
+ env = Rack::MockRequest.env_for("/")
140
140
 
141
141
  formatter = ExceptionNotifier::Formatter.new(@exception, env: env)
142
142
  assert_nil formatter.controller_and_action
143
143
  end
144
144
 
145
+ private
146
+
145
147
  def test_controller
146
- controller = mock('controller')
147
- controller.stubs(:action_name).returns('index')
148
- controller.stubs(:controller_name).returns('home')
148
+ controller = mock("controller")
149
+ controller.stubs(:action_name).returns("index")
150
+ controller.stubs(:controller_name).returns("home")
149
151
 
150
152
  controller
151
153
  end
@@ -1,33 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
3
+ require "test_helper"
4
4
 
5
5
  # To allow sidekiq error handlers to be registered, sidekiq must be in
6
6
  # "server mode". This mode is triggered by loading sidekiq/cli. Note this
7
7
  # has to be loaded before exception_notification/sidekiq.
8
- require 'sidekiq/cli'
9
- require 'sidekiq/testing'
8
+ require "sidekiq/cli"
9
+ require "sidekiq/testing"
10
10
 
11
- require 'exception_notification/sidekiq'
11
+ require "exception_notification/sidekiq"
12
12
 
13
13
  class MockSidekiqServer
14
14
  include ::Sidekiq::Component
15
15
 
16
16
  def config
17
- Sidekiq.default_configuration
17
+ @config ||= (Sidekiq.default_configuration.tap { |config| config.logger = Logger.new(nil) })
18
18
  end
19
19
  end
20
20
 
21
21
  class SidekiqTest < ActiveSupport::TestCase
22
- test 'should call notify_exception when sidekiq raises an error' do
22
+ test "should call notify_exception when sidekiq raises an error" do
23
23
  server = MockSidekiqServer.new
24
24
  message = {}
25
25
  exception = RuntimeError.new
26
26
 
27
- ExceptionNotifier.expects(:notify_exception).with(
28
- exception,
29
- data: { sidekiq: message }
30
- )
27
+ if ::Sidekiq::VERSION < "7.1.5"
28
+ ExceptionNotifier.expects(:notify_exception).with(
29
+ exception,
30
+ data: {sidekiq: message}
31
+ )
32
+ else
33
+ ExceptionNotifier.expects(:notify_exception).with(
34
+ exception,
35
+ data: {sidekiq: {context: message, config: server.config}}
36
+ )
37
+ end
31
38
 
32
39
  server.handle_exception(exception, message)
33
40
  end
@@ -1,46 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'test_helper'
4
- require 'slack-notifier'
3
+ require "test_helper"
4
+ require "slack-notifier"
5
5
 
6
6
  class SlackNotifierTest < ActiveSupport::TestCase
7
7
  def setup
8
8
  @exception = fake_exception
9
9
  @exception.stubs(:backtrace).returns(fake_backtrace)
10
- @exception.stubs(:message).returns('exception message')
10
+ @exception.stubs(:message).returns("exception message")
11
11
  ExceptionNotifier::SlackNotifier.any_instance.stubs(:clean_backtrace).returns(fake_cleaned_backtrace)
12
- Socket.stubs(:gethostname).returns('example.com')
12
+ Socket.stubs(:gethostname).returns("example.com")
13
13
  end
14
14
 
15
- test 'should send a slack notification if properly configured' do
15
+ test "should send a slack notification if properly configured" do
16
16
  options = {
17
- webhook_url: 'http://slack.webhook.url'
17
+ webhook_url: "http://slack.webhook.url"
18
18
  }
19
19
 
20
- Slack::Notifier.any_instance.expects(:ping).with('', fake_notification)
20
+ Slack::Notifier.any_instance.expects(:ping).with("", fake_notification)
21
21
 
22
22
  slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
23
23
  slack_notifier.call(@exception)
24
24
  end
25
25
 
26
- test 'should send a slack notification without backtrace info if properly configured' do
26
+ test "should send a slack notification without backtrace info if properly configured" do
27
27
  options = {
28
- webhook_url: 'http://slack.webhook.url'
28
+ webhook_url: "http://slack.webhook.url"
29
29
  }
30
30
 
31
- Slack::Notifier.any_instance.expects(:ping).with('', fake_notification(fake_exception_without_backtrace))
31
+ Slack::Notifier.any_instance.expects(:ping).with("", fake_notification(fake_exception_without_backtrace))
32
32
 
33
33
  slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
34
34
  slack_notifier.call(fake_exception_without_backtrace)
35
35
  end
36
36
 
37
- test 'should send the notification to the specified channel' do
37
+ test "should send the notification to the specified channel" do
38
38
  options = {
39
- webhook_url: 'http://slack.webhook.url',
40
- channel: 'channel'
39
+ webhook_url: "http://slack.webhook.url",
40
+ channel: "channel"
41
41
  }
42
42
 
43
- Slack::Notifier.any_instance.expects(:ping).with('', fake_notification)
43
+ Slack::Notifier.any_instance.expects(:ping).with("", fake_notification)
44
44
 
45
45
  slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
46
46
  slack_notifier.call(@exception)
@@ -49,13 +49,13 @@ class SlackNotifierTest < ActiveSupport::TestCase
49
49
  assert_equal channel, options[:channel]
50
50
  end
51
51
 
52
- test 'should send the notification to the specified username' do
52
+ test "should send the notification to the specified username" do
53
53
  options = {
54
- webhook_url: 'http://slack.webhook.url',
55
- username: 'username'
54
+ webhook_url: "http://slack.webhook.url",
55
+ username: "username"
56
56
  }
57
57
 
58
- Slack::Notifier.any_instance.expects(:ping).with('', fake_notification)
58
+ Slack::Notifier.any_instance.expects(:ping).with("", fake_notification)
59
59
 
60
60
  slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
61
61
  slack_notifier.call(@exception)
@@ -64,26 +64,26 @@ class SlackNotifierTest < ActiveSupport::TestCase
64
64
  assert_equal username, options[:username]
65
65
  end
66
66
 
67
- test 'should send the notification with specific backtrace lines' do
67
+ test "should send the notification with specific backtrace lines" do
68
68
  options = {
69
- webhook_url: 'http://slack.webhook.url',
69
+ webhook_url: "http://slack.webhook.url",
70
70
  backtrace_lines: 1
71
71
  }
72
72
 
73
- Slack::Notifier.any_instance.expects(:ping).with('', fake_notification(@exception, {}, nil, 1))
73
+ Slack::Notifier.any_instance.expects(:ping).with("", fake_notification(@exception, {}, nil, 1))
74
74
 
75
75
  slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
76
76
  slack_notifier.call(@exception)
77
77
  end
78
78
 
79
- test 'should send the notification with additional fields' do
80
- field = { title: 'Branch', value: 'master', short: true }
79
+ test "should send the notification with additional fields" do
80
+ field = {title: "Branch", value: "master", short: true}
81
81
  options = {
82
- webhook_url: 'http://slack.webhook.url',
82
+ webhook_url: "http://slack.webhook.url",
83
83
  additional_fields: [field]
84
84
  }
85
85
 
86
- Slack::Notifier.any_instance.expects(:ping).with('', fake_notification(@exception, {}, nil, 10, [field]))
86
+ Slack::Notifier.any_instance.expects(:ping).with("", fake_notification(@exception, {}, nil, 10, [field]))
87
87
 
88
88
  slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
89
89
  slack_notifier.call(@exception)
@@ -92,17 +92,17 @@ class SlackNotifierTest < ActiveSupport::TestCase
92
92
  assert_equal additional_fields, options[:additional_fields]
93
93
  end
94
94
 
95
- test 'should pass the additional parameters to Slack::Notifier.ping' do
95
+ test "should pass the additional parameters to Slack::Notifier.ping" do
96
96
  options = {
97
- webhook_url: 'http://slack.webhook.url',
98
- username: 'test',
99
- custom_hook: 'hook',
97
+ webhook_url: "http://slack.webhook.url",
98
+ username: "test",
99
+ custom_hook: "hook",
100
100
  additional_parameters: {
101
- icon_url: 'icon'
101
+ icon_url: "icon"
102
102
  }
103
103
  }
104
104
 
105
- Slack::Notifier.any_instance.expects(:ping).with('', options[:additional_parameters].merge(fake_notification))
105
+ Slack::Notifier.any_instance.expects(:ping).with("", options[:additional_parameters].merge(fake_notification))
106
106
 
107
107
  slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
108
108
  slack_notifier.call(@exception)
@@ -117,57 +117,57 @@ class SlackNotifierTest < ActiveSupport::TestCase
117
117
  assert_nil slack_notifier.call(@exception)
118
118
  end
119
119
 
120
- test 'should pass along environment data' do
120
+ test "should pass along environment data" do
121
121
  options = {
122
- webhook_url: 'http://slack.webhook.url',
122
+ webhook_url: "http://slack.webhook.url",
123
123
  ignore_data_if: lambda { |k, v|
124
- k.to_s == 'key_to_be_ignored' || v.is_a?(Hash)
124
+ k.to_s == "key_to_be_ignored" || v.is_a?(Hash)
125
125
  }
126
126
  }
127
127
 
128
128
  notification_options = {
129
129
  env: {
130
- 'exception_notifier.exception_data' => { foo: 'bar', john: 'doe' }
130
+ "exception_notifier.exception_data" => {foo: "bar", john: "doe"}
131
131
  },
132
132
  data: {
133
- 'user_id' => 5,
134
- 'key_to_be_ignored' => 'whatever',
135
- 'ignore_as_well' => { what: 'ever' }
133
+ "user_id" => 5,
134
+ "key_to_be_ignored" => "whatever",
135
+ "ignore_as_well" => {what: "ever"}
136
136
  }
137
137
  }
138
138
 
139
139
  expected_data_string = "foo: bar\njohn: doe\nuser_id: 5"
140
140
 
141
141
  Slack::Notifier.any_instance
142
- .expects(:ping)
143
- .with('', fake_notification(@exception, notification_options, expected_data_string))
142
+ .expects(:ping)
143
+ .with("", fake_notification(@exception, notification_options, expected_data_string))
144
144
  slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
145
145
  slack_notifier.call(@exception, notification_options)
146
146
  end
147
147
 
148
- test 'should call pre/post_callback proc if specified' do
148
+ test "should call pre/post_callback proc if specified" do
149
149
  post_callback_called = 0
150
150
  options = {
151
- webhook_url: 'http://slack.webhook.url',
152
- username: 'test',
153
- custom_hook: 'hook',
151
+ webhook_url: "http://slack.webhook.url",
152
+ username: "test",
153
+ custom_hook: "hook",
154
154
  pre_callback: proc { |_opts, _notifier, backtrace, _message, message_opts|
155
- (message_opts[:attachments] = []) << { text: backtrace.join("\n").to_s, color: 'danger' }
155
+ (message_opts[:attachments] = []) << {text: backtrace.join("\n").to_s, color: "danger"}
156
156
  },
157
157
  post_callback: proc { |_opts, _notifier, _backtrace, _message, _message_opts|
158
158
  post_callback_called = 1
159
159
  },
160
160
  additional_parameters: {
161
- icon_url: 'icon'
161
+ icon_url: "icon"
162
162
  }
163
163
  }
164
164
 
165
- Slack::Notifier.any_instance.expects(:ping).with('',
166
- icon_url: 'icon',
167
- attachments: [{
168
- text: fake_backtrace.join("\n"),
169
- color: 'danger'
170
- }])
165
+ Slack::Notifier.any_instance.expects(:ping).with("",
166
+ {icon_url: "icon",
167
+ attachments: [{
168
+ text: fake_backtrace.join("\n"),
169
+ color: "danger"
170
+ }]})
171
171
 
172
172
  slack_notifier = ExceptionNotifier::SlackNotifier.new(options)
173
173
  slack_notifier.call(@exception)
@@ -178,36 +178,35 @@ class SlackNotifierTest < ActiveSupport::TestCase
178
178
 
179
179
  def fake_exception
180
180
  5 / 0
181
- rescue StandardError => e
181
+ rescue => e
182
182
  e
183
183
  end
184
184
 
185
185
  def fake_exception_without_backtrace
186
- StandardError.new('my custom error')
186
+ StandardError.new("my custom error")
187
187
  end
188
188
 
189
189
  def fake_backtrace
190
190
  [
191
- 'backtrace line 1', 'backtrace line 2', 'backtrace line 3',
192
- 'backtrace line 4', 'backtrace line 5', 'backtrace line 6'
191
+ "backtrace line 1", "backtrace line 2", "backtrace line 3",
192
+ "backtrace line 4", "backtrace line 5", "backtrace line 6"
193
193
  ]
194
194
  end
195
195
 
196
196
  def fake_cleaned_backtrace
197
- fake_backtrace[2..-1]
197
+ fake_backtrace[2..-1] # standard:disable Style/SlicingWithRange
198
198
  end
199
199
 
200
200
  def fake_notification(exception = @exception, notification_options = {},
201
- data_string = nil, expected_backtrace_lines = 10, additional_fields = [])
202
-
203
- exception_name = "*#{exception.class.to_s =~ /^[aeiou]/i ? 'An' : 'A'}* `#{exception.class}`"
201
+ data_string = nil, expected_backtrace_lines = 10, additional_fields = [])
202
+ exception_name = "*#{/^[aeiou]/i.match?(exception.class.to_s) ? "An" : "A"}* `#{exception.class}`"
204
203
  if notification_options[:env].nil?
205
204
  text = "#{exception_name} *occured in background*"
206
205
  else
207
206
  env = notification_options[:env]
208
207
 
209
- kontroller = env['action_controller.instance']
210
- request = "#{env['REQUEST_METHOD']} <#{env['REQUEST_URI']}>"
208
+ kontroller = env["action_controller.instance"]
209
+ request = "#{env["REQUEST_METHOD"]} <#{env["REQUEST_URI"]}>"
211
210
 
212
211
  text = "#{exception_name} *occurred while* `#{request}`"
213
212
  text += " *was processed by* `#{kontroller.controller_name}##{kontroller.action_name}`" if kontroller
@@ -215,15 +214,15 @@ class SlackNotifierTest < ActiveSupport::TestCase
215
214
 
216
215
  text += "\n"
217
216
 
218
- fields = [{ title: 'Exception', value: exception.message }]
219
- fields.push(title: 'Hostname', value: 'example.com')
217
+ fields = [{title: "Exception", value: exception.message}]
218
+ fields.push(title: "Hostname", value: "example.com")
220
219
  if exception.backtrace
221
220
  formatted_backtrace = "```#{fake_cleaned_backtrace.first(expected_backtrace_lines).join("\n")}```"
222
- fields.push(title: 'Backtrace', value: formatted_backtrace)
221
+ fields.push(title: "Backtrace", value: formatted_backtrace)
223
222
  end
224
- fields.push(title: 'Data', value: "```#{data_string}```") if data_string
223
+ fields.push(title: "Data", value: "```#{data_string}```") if data_string
225
224
  additional_fields.each { |f| fields.push(f) }
226
225
 
227
- { attachments: [color: 'danger', text: text, fields: fields, mrkdwn_in: %w[text fields]] }
226
+ {attachments: [color: "danger", text: text, fields: fields, mrkdwn_in: %w[text fields]]}
228
227
  end
229
228
  end