exception_notification 4.3.0 → 4.4.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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +2 -2
  3. data/CHANGELOG.rdoc +14 -0
  4. data/CONTRIBUTING.md +18 -0
  5. data/Gemfile +1 -1
  6. data/README.md +64 -935
  7. data/Rakefile +2 -2
  8. data/docs/notifiers/campfire.md +50 -0
  9. data/docs/notifiers/custom.md +42 -0
  10. data/docs/notifiers/datadog.md +51 -0
  11. data/docs/notifiers/email.md +195 -0
  12. data/docs/notifiers/google_chat.md +31 -0
  13. data/docs/notifiers/hipchat.md +66 -0
  14. data/docs/notifiers/irc.md +97 -0
  15. data/docs/notifiers/mattermost.md +115 -0
  16. data/docs/notifiers/slack.md +161 -0
  17. data/docs/notifiers/sns.md +37 -0
  18. data/docs/notifiers/teams.md +54 -0
  19. data/docs/notifiers/webhook.md +60 -0
  20. data/examples/sample_app.rb +54 -0
  21. data/examples/sinatra/Gemfile +6 -6
  22. data/examples/sinatra/config.ru +1 -1
  23. data/examples/sinatra/sinatra_app.rb +14 -10
  24. data/exception_notification.gemspec +27 -22
  25. data/gemfiles/rails4_0.gemfile +3 -3
  26. data/gemfiles/rails4_1.gemfile +3 -3
  27. data/gemfiles/rails4_2.gemfile +3 -3
  28. data/gemfiles/rails5_0.gemfile +3 -3
  29. data/gemfiles/rails5_1.gemfile +3 -3
  30. data/gemfiles/rails5_2.gemfile +7 -0
  31. data/gemfiles/rails6_0.gemfile +7 -0
  32. data/lib/exception_notification.rb +1 -0
  33. data/lib/exception_notification/rack.rb +8 -21
  34. data/lib/exception_notification/resque.rb +8 -10
  35. data/lib/exception_notification/sidekiq.rb +8 -12
  36. data/lib/exception_notification/version.rb +3 -0
  37. data/lib/exception_notifier.rb +20 -3
  38. data/lib/exception_notifier/base_notifier.rb +2 -3
  39. data/lib/exception_notifier/campfire_notifier.rb +12 -13
  40. data/lib/exception_notifier/datadog_notifier.rb +153 -0
  41. data/lib/exception_notifier/email_notifier.rb +64 -87
  42. data/lib/exception_notifier/google_chat_notifier.rb +25 -119
  43. data/lib/exception_notifier/hipchat_notifier.rb +11 -12
  44. data/lib/exception_notifier/irc_notifier.rb +32 -30
  45. data/lib/exception_notifier/mattermost_notifier.rb +47 -140
  46. data/lib/exception_notifier/modules/backtrace_cleaner.rb +0 -2
  47. data/lib/exception_notifier/modules/error_grouping.rb +5 -5
  48. data/lib/exception_notifier/modules/formatter.rb +118 -0
  49. data/lib/exception_notifier/notifier.rb +5 -6
  50. data/lib/exception_notifier/slack_notifier.rb +63 -40
  51. data/lib/exception_notifier/sns_notifier.rb +17 -11
  52. data/lib/exception_notifier/teams_notifier.rb +58 -44
  53. data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +1 -1
  54. data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +1 -1
  55. data/lib/exception_notifier/views/exception_notifier/_request.text.erb +1 -1
  56. data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +2 -2
  57. data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +2 -2
  58. data/lib/exception_notifier/webhook_notifier.rb +14 -11
  59. data/lib/generators/exception_notification/install_generator.rb +5 -5
  60. data/lib/generators/exception_notification/templates/{exception_notification.rb → exception_notification.rb.erb} +13 -11
  61. data/test/exception_notification/rack_test.rb +27 -11
  62. data/test/exception_notification/resque_test.rb +52 -0
  63. data/test/exception_notifier/campfire_notifier_test.rb +42 -42
  64. data/test/exception_notifier/datadog_notifier_test.rb +151 -0
  65. data/test/exception_notifier/email_notifier_test.rb +269 -153
  66. data/test/exception_notifier/google_chat_notifier_test.rb +154 -101
  67. data/test/exception_notifier/hipchat_notifier_test.rb +78 -81
  68. data/test/exception_notifier/irc_notifier_test.rb +34 -34
  69. data/test/exception_notifier/mattermost_notifier_test.rb +164 -67
  70. data/test/exception_notifier/modules/error_grouping_test.rb +39 -40
  71. data/test/exception_notifier/modules/formatter_test.rb +150 -0
  72. data/test/exception_notifier/sidekiq_test.rb +6 -6
  73. data/test/exception_notifier/slack_notifier_test.rb +61 -60
  74. data/test/exception_notifier/sns_notifier_test.rb +27 -32
  75. data/test/exception_notifier/teams_notifier_test.rb +23 -26
  76. data/test/exception_notifier/webhook_notifier_test.rb +48 -46
  77. data/test/exception_notifier_test.rb +41 -38
  78. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.html.erb +0 -0
  79. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.text.erb +0 -0
  80. data/test/{dummy/app → support}/views/exception_notifier/_new_section.html.erb +0 -0
  81. data/test/{dummy/app → support}/views/exception_notifier/_new_section.text.erb +0 -0
  82. data/test/test_helper.rb +11 -14
  83. metadata +136 -166
  84. data/test/dummy/.gitignore +0 -4
  85. data/test/dummy/Rakefile +0 -7
  86. data/test/dummy/app/controllers/application_controller.rb +0 -3
  87. data/test/dummy/app/controllers/posts_controller.rb +0 -30
  88. data/test/dummy/app/helpers/application_helper.rb +0 -2
  89. data/test/dummy/app/helpers/posts_helper.rb +0 -2
  90. data/test/dummy/app/models/post.rb +0 -2
  91. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  92. data/test/dummy/app/views/posts/_form.html.erb +0 -0
  93. data/test/dummy/app/views/posts/new.html.erb +0 -0
  94. data/test/dummy/app/views/posts/show.html.erb +0 -0
  95. data/test/dummy/config.ru +0 -4
  96. data/test/dummy/config/application.rb +0 -42
  97. data/test/dummy/config/boot.rb +0 -6
  98. data/test/dummy/config/database.yml +0 -22
  99. data/test/dummy/config/environment.rb +0 -17
  100. data/test/dummy/config/environments/development.rb +0 -25
  101. data/test/dummy/config/environments/production.rb +0 -50
  102. data/test/dummy/config/environments/test.rb +0 -35
  103. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  104. data/test/dummy/config/initializers/inflections.rb +0 -10
  105. data/test/dummy/config/initializers/mime_types.rb +0 -5
  106. data/test/dummy/config/initializers/secret_token.rb +0 -8
  107. data/test/dummy/config/initializers/session_store.rb +0 -8
  108. data/test/dummy/config/locales/en.yml +0 -5
  109. data/test/dummy/config/routes.rb +0 -3
  110. data/test/dummy/db/migrate/20110729022608_create_posts.rb +0 -15
  111. data/test/dummy/db/schema.rb +0 -24
  112. data/test/dummy/db/seeds.rb +0 -7
  113. data/test/dummy/lib/tasks/.gitkeep +0 -0
  114. data/test/dummy/public/404.html +0 -26
  115. data/test/dummy/public/422.html +0 -26
  116. data/test/dummy/public/500.html +0 -26
  117. data/test/dummy/public/favicon.ico +0 -0
  118. data/test/dummy/public/images/rails.png +0 -0
  119. data/test/dummy/public/index.html +0 -239
  120. data/test/dummy/public/javascripts/application.js +0 -2
  121. data/test/dummy/public/javascripts/controls.js +0 -965
  122. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  123. data/test/dummy/public/javascripts/effects.js +0 -1123
  124. data/test/dummy/public/javascripts/prototype.js +0 -6001
  125. data/test/dummy/public/javascripts/rails.js +0 -191
  126. data/test/dummy/public/robots.txt +0 -5
  127. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  128. data/test/dummy/public/stylesheets/scaffold.css +0 -56
  129. data/test/dummy/script/rails +0 -6
  130. data/test/dummy/test/functional/posts_controller_test.rb +0 -237
  131. data/test/dummy/test/test_helper.rb +0 -7
@@ -2,19 +2,18 @@ require 'test_helper'
2
2
  require 'httparty'
3
3
 
4
4
  class TeamsNotifierTest < ActiveSupport::TestCase
5
-
6
- test "should send notification if properly configured" do
5
+ test 'should send notification if properly configured' do
7
6
  options = {
8
- :webhook_url => 'http://localhost:8000'
7
+ webhook_url: 'http://localhost:8000'
9
8
  }
10
9
  teams_notifier = ExceptionNotifier::TeamsNotifier.new
11
10
  teams_notifier.httparty = FakeHTTParty.new
12
11
 
13
- options = teams_notifier.call ArgumentError.new("foo"), options
12
+ options = teams_notifier.call ArgumentError.new('foo'), options
14
13
 
15
14
  body = ActiveSupport::JSON.decode options[:body]
16
- assert body.has_key? 'title'
17
- assert body.has_key? 'sections'
15
+ assert body.key? 'title'
16
+ assert body.key? 'sections'
18
17
 
19
18
  sections = body['sections']
20
19
  header = sections[0]
@@ -24,15 +23,15 @@ class TeamsNotifierTest < ActiveSupport::TestCase
24
23
  assert_equal 'foo', header['activitySubtitle']
25
24
  end
26
25
 
27
- test "should send notification with create gitlab issue link if specified" do
26
+ test 'should send notification with create gitlab issue link if specified' do
28
27
  options = {
29
- :webhook_url => 'http://localhost:8000',
30
- :git_url => 'github.com/aschen'
28
+ webhook_url: 'http://localhost:8000',
29
+ git_url: 'github.com/aschen'
31
30
  }
32
31
  teams_notifier = ExceptionNotifier::TeamsNotifier.new
33
32
  teams_notifier.httparty = FakeHTTParty.new
34
33
 
35
- options = teams_notifier.call ArgumentError.new("foo"), options
34
+ options = teams_notifier.call ArgumentError.new('foo'), options
36
35
 
37
36
  body = ActiveSupport::JSON.decode options[:body]
38
37
 
@@ -44,27 +43,27 @@ class TeamsNotifierTest < ActiveSupport::TestCase
44
43
 
45
44
  test 'should add other HTTParty options to params' do
46
45
  options = {
47
- :webhook_url => 'http://localhost:8000',
48
- :username => "Test Bot",
49
- :avatar => 'http://site.com/icon.png',
50
- :basic_auth => {
51
- :username => 'clara',
52
- :password => 'password'
46
+ webhook_url: 'http://localhost:8000',
47
+ username: 'Test Bot',
48
+ avatar: 'http://site.com/icon.png',
49
+ basic_auth: {
50
+ username: 'clara',
51
+ password: 'password'
53
52
  }
54
53
  }
55
54
  teams_notifier = ExceptionNotifier::TeamsNotifier.new
56
55
  teams_notifier.httparty = FakeHTTParty.new
57
56
 
58
- options = teams_notifier.call ArgumentError.new("foo"), options
57
+ options = teams_notifier.call ArgumentError.new('foo'), options
59
58
 
60
- assert options.has_key? :basic_auth
59
+ assert options.key? :basic_auth
61
60
  assert 'clara', options[:basic_auth][:username]
62
61
  assert 'password', options[:basic_auth][:password]
63
62
  end
64
63
 
65
64
  test "should use 'A' for exceptions count if :accumulated_errors_count option is nil" do
66
65
  teams_notifier = ExceptionNotifier::TeamsNotifier.new
67
- exception = ArgumentError.new("foo")
66
+ exception = ArgumentError.new('foo')
68
67
  teams_notifier.instance_variable_set(:@exception, exception)
69
68
  teams_notifier.instance_variable_set(:@options, {})
70
69
 
@@ -73,11 +72,11 @@ class TeamsNotifierTest < ActiveSupport::TestCase
73
72
  assert_equal 'A *ArgumentError* occurred.', header['activityTitle']
74
73
  end
75
74
 
76
- test "should use direct errors count if :accumulated_errors_count option is 5" do
75
+ test 'should use direct errors count if :accumulated_errors_count option is 5' do
77
76
  teams_notifier = ExceptionNotifier::TeamsNotifier.new
78
- exception = ArgumentError.new("foo")
77
+ exception = ArgumentError.new('foo')
79
78
  teams_notifier.instance_variable_set(:@exception, exception)
80
- teams_notifier.instance_variable_set(:@options, { accumulated_errors_count: 5 })
79
+ teams_notifier.instance_variable_set(:@options, accumulated_errors_count: 5)
81
80
  message_text = teams_notifier.send(:message_text)
82
81
  header = message_text['sections'][0]
83
82
  assert_equal '5 *ArgumentError* occurred.', header['activityTitle']
@@ -85,9 +84,7 @@ class TeamsNotifierTest < ActiveSupport::TestCase
85
84
  end
86
85
 
87
86
  class FakeHTTParty
88
-
89
- def post(url, options)
90
- return options
87
+ def post(_url, options)
88
+ options
91
89
  end
92
-
93
90
  end
@@ -2,42 +2,41 @@ require 'test_helper'
2
2
  require 'httparty'
3
3
 
4
4
  class WebhookNotifierTest < ActiveSupport::TestCase
5
-
6
- test "should send webhook notification if properly configured" do
5
+ test 'should send webhook notification if properly configured' do
7
6
  ExceptionNotifier::WebhookNotifier.stubs(:new).returns(Object.new)
8
- webhook = ExceptionNotifier::WebhookNotifier.new({:url => 'http://localhost:8000'})
7
+ webhook = ExceptionNotifier::WebhookNotifier.new(url: 'http://localhost:8000')
9
8
  webhook.stubs(:call).returns(fake_response)
10
9
  response = webhook.call(fake_exception)
11
10
 
12
11
  refute_nil response
13
12
  assert_equal response[:status], 200
14
- assert_equal response[:body][:exception][:error_class], "ZeroDivisionError"
15
- assert_includes response[:body][:exception][:message], "divided by 0"
16
- assert_includes response[:body][:exception][:backtrace], "/exception_notification/test/webhook_notifier_test.rb:48"
13
+ assert_equal response[:body][:exception][:error_class], 'ZeroDivisionError'
14
+ assert_includes response[:body][:exception][:message], 'divided by 0'
15
+ assert_includes response[:body][:exception][:backtrace], '/exception_notification/test/webhook_notifier_test.rb:48'
17
16
 
18
- assert response[:body][:request][:cookies].has_key?(:cookie_item1)
19
- assert_equal response[:body][:request][:url], "http://example.com/example"
20
- assert_equal response[:body][:request][:ip_address], "192.168.1.1"
21
- assert response[:body][:request][:environment].has_key?(:env_item1)
22
- assert_equal response[:body][:request][:controller], "#<ControllerName:0x007f9642a04d00>"
23
- assert response[:body][:request][:session].has_key?(:session_item1)
24
- assert response[:body][:request][:parameters].has_key?(:controller)
25
- assert response[:body][:data][:extra_data].has_key?(:data_item1)
17
+ assert response[:body][:request][:cookies].key?(:cookie_item1)
18
+ assert_equal response[:body][:request][:url], 'http://example.com/example'
19
+ assert_equal response[:body][:request][:ip_address], '192.168.1.1'
20
+ assert response[:body][:request][:environment].key?(:env_item1)
21
+ assert_equal response[:body][:request][:controller], '#<ControllerName:0x007f9642a04d00>'
22
+ assert response[:body][:request][:session].key?(:session_item1)
23
+ assert response[:body][:request][:parameters].key?(:controller)
24
+ assert response[:body][:data][:extra_data].key?(:data_item1)
26
25
  end
27
26
 
28
- test "should send webhook notification with correct params data" do
27
+ test 'should send webhook notification with correct params data' do
29
28
  url = 'http://localhost:8000'
30
29
  fake_exception.stubs(:backtrace).returns('the backtrace')
31
- webhook = ExceptionNotifier::WebhookNotifier.new({:url => url})
30
+ webhook = ExceptionNotifier::WebhookNotifier.new(url: url)
32
31
 
33
32
  HTTParty.expects(:send).with(:post, url, fake_params)
34
33
 
35
34
  webhook.call(fake_exception)
36
35
  end
37
36
 
38
- test "should call pre/post_callback if specified" do
37
+ test 'should call pre/post_callback if specified' do
39
38
  HTTParty.stubs(:send).returns(fake_response)
40
- webhook = ExceptionNotifier::WebhookNotifier.new({:url => 'http://localhost:8000'})
39
+ webhook = ExceptionNotifier::WebhookNotifier.new(url: 'http://localhost:8000')
41
40
  webhook.call(fake_exception)
42
41
  end
43
42
 
@@ -45,49 +44,52 @@ class WebhookNotifierTest < ActiveSupport::TestCase
45
44
 
46
45
  def fake_response
47
46
  {
48
- :status => 200,
49
- :body => {
50
- :exception => {
51
- :error_class => 'ZeroDivisionError',
52
- :message => 'divided by 0',
53
- :backtrace => '/exception_notification/test/webhook_notifier_test.rb:48:in `/'
47
+ status: 200,
48
+ body: {
49
+ exception: {
50
+ error_class: 'ZeroDivisionError',
51
+ message: 'divided by 0',
52
+ backtrace: '/exception_notification/test/webhook_notifier_test.rb:48:in `/'
54
53
  },
55
- :data => {
56
- :extra_data => {:data_item1 => "datavalue1", :data_item2 => "datavalue2"}
54
+ data: {
55
+ extra_data: { data_item1: 'datavalue1', data_item2: 'datavalue2' }
57
56
  },
58
- :request => {
59
- :cookies => {:cookie_item1 => 'cookieitemvalue1', :cookie_item2 => 'cookieitemvalue2'},
60
- :url => 'http://example.com/example',
61
- :ip_address => '192.168.1.1',
62
- :environment => {:env_item1 => "envitem1", :env_item2 => "envitem2"},
63
- :controller => '#<ControllerName:0x007f9642a04d00>',
64
- :session => {:session_item1 => "sessionitem1", :session_item2 => "sessionitem2"},
65
- :parameters => {:action =>"index", :controller =>"projects"}
57
+ request: {
58
+ cookies: { cookie_item1: 'cookieitemvalue1', cookie_item2: 'cookieitemvalue2' },
59
+ url: 'http://example.com/example',
60
+ ip_address: '192.168.1.1',
61
+ environment: { env_item1: 'envitem1', env_item2: 'envitem2' },
62
+ controller: '#<ControllerName:0x007f9642a04d00>',
63
+ session: { session_item1: 'sessionitem1', session_item2: 'sessionitem2' },
64
+ parameters: { action: 'index', controller: 'projects' }
66
65
  }
67
66
  }
68
67
  }
69
68
  end
70
69
 
71
70
  def fake_params
72
- {
73
- :body => {
74
- :server => Socket.gethostname,
75
- :process => $$,
76
- :rails_root => Rails.root,
77
- :exception => {
78
- :error_class => 'ZeroDivisionError',
79
- :message => 'divided by 0'.inspect,
80
- :backtrace => 'the backtrace'
71
+ params = {
72
+ body: {
73
+ server: Socket.gethostname,
74
+ process: $PROCESS_ID,
75
+ exception: {
76
+ error_class: 'ZeroDivisionError',
77
+ message: 'divided by 0'.inspect,
78
+ backtrace: 'the backtrace'
81
79
  },
82
- :data => {}
80
+ data: {}
83
81
  }
84
82
  }
83
+
84
+ params[:body][:rails_root] = Rails.root if defined?(::Rails) && Rails.respond_to?(:root)
85
+
86
+ params
85
87
  end
86
88
 
87
89
  def fake_exception
88
90
  @fake_exception ||= begin
89
- 5/0
90
- rescue Exception => e
91
+ 5 / 0
92
+ rescue StandardError => e
91
93
  e
92
94
  end
93
95
  end
@@ -1,44 +1,47 @@
1
1
  require 'test_helper'
2
2
 
3
- class ExceptionOne < StandardError;end
4
- class ExceptionTwo < StandardError;end
3
+ class ExceptionOne < StandardError; end
4
+ class ExceptionTwo < StandardError; end
5
5
 
6
6
  class ExceptionNotifierTest < ActiveSupport::TestCase
7
7
  setup do
8
+ ExceptionNotifier.register_exception_notifier(:email, exception_recipients: %w[dummyexceptions@example.com])
9
+
8
10
  @notifier_calls = 0
9
- @test_notifier = lambda { |exception, options| @notifier_calls += 1 }
11
+ @test_notifier = ->(_exception, _options) { @notifier_calls += 1 }
10
12
  end
11
13
 
12
14
  teardown do
13
15
  ExceptionNotifier.error_grouping = false
14
16
  ExceptionNotifier.notification_trigger = nil
15
- ExceptionNotifier.class_eval("@@notifiers.delete_if { |k, _| k.to_s != \"email\"}") # reset notifiers
16
- Rails.cache.clear
17
+ ExceptionNotifier.class_eval('@@notifiers.delete_if { |k, _| k.to_s != "email"}') # reset notifiers
18
+
19
+ Rails.cache.clear if defined?(Rails) && Rails.respond_to?(:cache)
17
20
  end
18
21
 
19
- test "should have default ignored exceptions" do
22
+ test 'should have default ignored exceptions' do
20
23
  assert_equal ExceptionNotifier.ignored_exceptions,
21
- ['ActiveRecord::RecordNotFound', 'Mongoid::Errors::DocumentNotFound', 'AbstractController::ActionNotFound',
22
- 'ActionController::RoutingError', 'ActionController::UnknownFormat', 'ActionController::UrlGenerationError']
24
+ ['ActiveRecord::RecordNotFound', 'Mongoid::Errors::DocumentNotFound', 'AbstractController::ActionNotFound',
25
+ 'ActionController::RoutingError', 'ActionController::UnknownFormat', 'ActionController::UrlGenerationError']
23
26
  end
24
27
 
25
- test "should have email notifier registered" do
28
+ test 'should have email notifier registered' do
26
29
  assert_equal ExceptionNotifier.notifiers, [:email]
27
30
  end
28
31
 
29
- test "should have a valid email notifier" do
32
+ test 'should have a valid email notifier' do
30
33
  @email_notifier = ExceptionNotifier.registered_exception_notifier(:email)
31
34
  refute_nil @email_notifier
32
35
  assert_equal @email_notifier.class, ExceptionNotifier::EmailNotifier
33
36
  assert_respond_to @email_notifier, :call
34
37
  end
35
38
 
36
- test "should allow register/unregister another notifier" do
39
+ test 'should allow register/unregister another notifier' do
37
40
  called = false
38
- proc_notifier = lambda { |exception, options| called = true }
41
+ proc_notifier = ->(_exception, _options) { called = true }
39
42
  ExceptionNotifier.register_exception_notifier(:proc, proc_notifier)
40
43
 
41
- assert_equal ExceptionNotifier.notifiers.sort, [:email, :proc]
44
+ assert_equal ExceptionNotifier.notifiers.sort, %i[email proc]
42
45
 
43
46
  exception = StandardError.new
44
47
 
@@ -49,27 +52,27 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
49
52
  assert_equal ExceptionNotifier.notifiers, [:email]
50
53
  end
51
54
 
52
- test "should allow select notifiers to send error to" do
55
+ test 'should allow select notifiers to send error to' do
53
56
  notifier1_calls = 0
54
- notifier1 = lambda { |exception, options| notifier1_calls += 1 }
57
+ notifier1 = ->(_exception, _options) { notifier1_calls += 1 }
55
58
  ExceptionNotifier.register_exception_notifier(:notifier1, notifier1)
56
59
 
57
60
  notifier2_calls = 0
58
- notifier2 = lambda { |exception, options| notifier2_calls += 1 }
61
+ notifier2 = ->(_exception, _options) { notifier2_calls += 1 }
59
62
  ExceptionNotifier.register_exception_notifier(:notifier2, notifier2)
60
63
 
61
- assert_equal ExceptionNotifier.notifiers.sort, [:email, :notifier1, :notifier2]
64
+ assert_equal ExceptionNotifier.notifiers.sort, %i[email notifier1 notifier2]
62
65
 
63
66
  exception = StandardError.new
64
67
  ExceptionNotifier.notify_exception(exception)
65
68
  assert_equal notifier1_calls, 1
66
69
  assert_equal notifier2_calls, 1
67
70
 
68
- ExceptionNotifier.notify_exception(exception, {:notifiers => :notifier1})
71
+ ExceptionNotifier.notify_exception(exception, notifiers: :notifier1)
69
72
  assert_equal notifier1_calls, 2
70
73
  assert_equal notifier2_calls, 1
71
74
 
72
- ExceptionNotifier.notify_exception(exception, {:notifiers => :notifier2})
75
+ ExceptionNotifier.notify_exception(exception, notifiers: :notifier2)
73
76
  assert_equal notifier1_calls, 2
74
77
  assert_equal notifier2_calls, 2
75
78
 
@@ -78,39 +81,39 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
78
81
  assert_equal ExceptionNotifier.notifiers, [:email]
79
82
  end
80
83
 
81
- test "should ignore exception if satisfies conditional ignore" do
82
- env = "production"
83
- ExceptionNotifier.ignore_if do |exception, options|
84
- env != "production"
84
+ test 'should ignore exception if satisfies conditional ignore' do
85
+ env = 'production'
86
+ ExceptionNotifier.ignore_if do |_exception, _options|
87
+ env != 'production'
85
88
  end
86
89
 
87
90
  ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
88
91
 
89
92
  exception = StandardError.new
90
93
 
91
- ExceptionNotifier.notify_exception(exception, {:notifiers => :test})
94
+ ExceptionNotifier.notify_exception(exception, notifiers: :test)
92
95
  assert_equal @notifier_calls, 1
93
96
 
94
- env = "development"
95
- ExceptionNotifier.notify_exception(exception, {:notifiers => :test})
97
+ env = 'development'
98
+ ExceptionNotifier.notify_exception(exception, notifiers: :test)
96
99
  assert_equal @notifier_calls, 1
97
100
 
98
101
  ExceptionNotifier.clear_ignore_conditions!
99
102
  end
100
103
 
101
- test "should not send notification if one of ignored exceptions" do
104
+ test 'should not send notification if one of ignored exceptions' do
102
105
  ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
103
106
 
104
107
  exception = StandardError.new
105
108
 
106
- ExceptionNotifier.notify_exception(exception, {:notifiers => :test})
109
+ ExceptionNotifier.notify_exception(exception, notifiers: :test)
107
110
  assert_equal @notifier_calls, 1
108
111
 
109
- ExceptionNotifier.notify_exception(exception, {:notifiers => :test, :ignore_exceptions => 'StandardError' })
112
+ ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: 'StandardError')
110
113
  assert_equal @notifier_calls, 1
111
114
  end
112
115
 
113
- test "should not send notification if subclass of one of ignored exceptions" do
116
+ test 'should not send notification if subclass of one of ignored exceptions' do
114
117
  ExceptionNotifier.register_exception_notifier(:test, @test_notifier)
115
118
 
116
119
  class StandardErrorSubclass < StandardError
@@ -118,16 +121,16 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
118
121
 
119
122
  exception = StandardErrorSubclass.new
120
123
 
121
- ExceptionNotifier.notify_exception(exception, {:notifiers => :test})
124
+ ExceptionNotifier.notify_exception(exception, notifiers: :test)
122
125
  assert_equal @notifier_calls, 1
123
126
 
124
- ExceptionNotifier.notify_exception(exception, {:notifiers => :test, :ignore_exceptions => 'StandardError' })
127
+ ExceptionNotifier.notify_exception(exception, notifiers: :test, ignore_exceptions: 'StandardError')
125
128
  assert_equal @notifier_calls, 1
126
129
  end
127
130
 
128
- test "should call received block" do
131
+ test 'should call received block' do
129
132
  @block_called = false
130
- notifier = lambda { |exception, options, &block| block.call }
133
+ notifier = ->(_exception, _options, &block) { block.call }
131
134
  ExceptionNotifier.register_exception_notifier(:test, notifier)
132
135
 
133
136
  exception = ExceptionOne.new
@@ -139,7 +142,7 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
139
142
  assert @block_called
140
143
  end
141
144
 
142
- test "should not call group_error! or send_notification? if error_grouping false" do
145
+ test 'should not call group_error! or send_notification? if error_grouping false' do
143
146
  exception = StandardError.new
144
147
  ExceptionNotifier.expects(:group_error!).never
145
148
  ExceptionNotifier.expects(:send_notification?).never
@@ -147,7 +150,7 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
147
150
  ExceptionNotifier.notify_exception(exception)
148
151
  end
149
152
 
150
- test "should call group_error! and send_notification? if error_grouping true" do
153
+ test 'should call group_error! and send_notification? if error_grouping true' do
151
154
  ExceptionNotifier.error_grouping = true
152
155
 
153
156
  exception = StandardError.new
@@ -157,7 +160,7 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
157
160
  ExceptionNotifier.notify_exception(exception)
158
161
  end
159
162
 
160
- test "should skip notification if send_notification? is false" do
163
+ test 'should skip notification if send_notification? is false' do
161
164
  ExceptionNotifier.error_grouping = true
162
165
 
163
166
  exception = StandardError.new
@@ -167,7 +170,7 @@ class ExceptionNotifierTest < ActiveSupport::TestCase
167
170
  refute ExceptionNotifier.notify_exception(exception)
168
171
  end
169
172
 
170
- test "should send notification if send_notification? is true" do
173
+ test 'should send notification if send_notification? is true' do
171
174
  ExceptionNotifier.error_grouping = true
172
175
 
173
176
  exception = StandardError.new