exception_notification 4.2.0 → 4.4.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 (134) hide show
  1. checksums.yaml +5 -5
  2. data/Appraisals +4 -3
  3. data/CHANGELOG.rdoc +57 -1
  4. data/CONTRIBUTING.md +21 -2
  5. data/Gemfile +3 -1
  6. data/README.md +106 -789
  7. data/Rakefile +4 -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 +56 -0
  21. data/examples/sinatra/Gemfile +8 -6
  22. data/examples/sinatra/config.ru +3 -1
  23. data/examples/sinatra/sinatra_app.rb +19 -11
  24. data/exception_notification.gemspec +30 -23
  25. data/gemfiles/rails4_0.gemfile +1 -2
  26. data/gemfiles/rails4_1.gemfile +1 -2
  27. data/gemfiles/rails4_2.gemfile +1 -2
  28. data/gemfiles/rails5_0.gemfile +1 -2
  29. data/gemfiles/rails5_1.gemfile +7 -0
  30. data/gemfiles/rails5_2.gemfile +7 -0
  31. data/gemfiles/rails6_0.gemfile +7 -0
  32. data/lib/exception_notification.rb +3 -0
  33. data/lib/exception_notification/rack.rb +34 -27
  34. data/lib/exception_notification/rails.rb +3 -0
  35. data/lib/exception_notification/resque.rb +10 -10
  36. data/lib/exception_notification/sidekiq.rb +10 -12
  37. data/lib/exception_notification/version.rb +5 -0
  38. data/lib/exception_notifier.rb +79 -11
  39. data/lib/exception_notifier/base_notifier.rb +10 -5
  40. data/lib/exception_notifier/campfire_notifier.rb +14 -9
  41. data/lib/exception_notifier/datadog_notifier.rb +156 -0
  42. data/lib/exception_notifier/email_notifier.rb +78 -87
  43. data/lib/exception_notifier/google_chat_notifier.rb +44 -0
  44. data/lib/exception_notifier/hipchat_notifier.rb +16 -10
  45. data/lib/exception_notifier/irc_notifier.rb +38 -31
  46. data/lib/exception_notifier/mattermost_notifier.rb +54 -131
  47. data/lib/exception_notifier/modules/backtrace_cleaner.rb +2 -2
  48. data/lib/exception_notifier/modules/error_grouping.rb +87 -0
  49. data/lib/exception_notifier/modules/formatter.rb +121 -0
  50. data/lib/exception_notifier/notifier.rb +9 -6
  51. data/lib/exception_notifier/slack_notifier.rb +75 -32
  52. data/lib/exception_notifier/sns_notifier.rb +86 -0
  53. data/lib/exception_notifier/teams_notifier.rb +200 -0
  54. data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +1 -1
  55. data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +1 -1
  56. data/lib/exception_notifier/views/exception_notifier/_request.text.erb +1 -1
  57. data/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb +9 -9
  58. data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +2 -4
  59. data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +2 -2
  60. data/lib/exception_notifier/webhook_notifier.rb +19 -16
  61. data/lib/generators/exception_notification/install_generator.rb +11 -5
  62. data/lib/generators/exception_notification/templates/{exception_notification.rb → exception_notification.rb.erb} +14 -12
  63. data/test/exception_notification/rack_test.rb +90 -4
  64. data/test/exception_notification/resque_test.rb +54 -0
  65. data/test/exception_notifier/campfire_notifier_test.rb +66 -39
  66. data/test/exception_notifier/datadog_notifier_test.rb +153 -0
  67. data/test/exception_notifier/email_notifier_test.rb +301 -145
  68. data/test/exception_notifier/google_chat_notifier_test.rb +185 -0
  69. data/test/exception_notifier/hipchat_notifier_test.rb +112 -65
  70. data/test/exception_notifier/irc_notifier_test.rb +48 -30
  71. data/test/exception_notifier/mattermost_notifier_test.rb +218 -55
  72. data/test/exception_notifier/modules/error_grouping_test.rb +167 -0
  73. data/test/exception_notifier/modules/formatter_test.rb +152 -0
  74. data/test/exception_notifier/sidekiq_test.rb +9 -6
  75. data/test/exception_notifier/slack_notifier_test.rb +109 -59
  76. data/test/exception_notifier/sns_notifier_test.rb +123 -0
  77. data/test/exception_notifier/teams_notifier_test.rb +92 -0
  78. data/test/exception_notifier/webhook_notifier_test.rb +68 -38
  79. data/test/exception_notifier_test.rb +220 -37
  80. data/test/support/exception_notifier_helper.rb +14 -0
  81. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.html.erb +0 -0
  82. data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.text.erb +0 -0
  83. data/test/{dummy/app → support}/views/exception_notifier/_new_section.html.erb +0 -0
  84. data/test/{dummy/app → support}/views/exception_notifier/_new_section.text.erb +0 -0
  85. data/test/test_helper.rb +14 -13
  86. metadata +154 -162
  87. data/test/dummy/.gitignore +0 -4
  88. data/test/dummy/Rakefile +0 -7
  89. data/test/dummy/app/controllers/application_controller.rb +0 -3
  90. data/test/dummy/app/controllers/posts_controller.rb +0 -30
  91. data/test/dummy/app/helpers/application_helper.rb +0 -2
  92. data/test/dummy/app/helpers/posts_helper.rb +0 -2
  93. data/test/dummy/app/models/post.rb +0 -2
  94. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  95. data/test/dummy/app/views/posts/_form.html.erb +0 -0
  96. data/test/dummy/app/views/posts/new.html.erb +0 -0
  97. data/test/dummy/app/views/posts/show.html.erb +0 -0
  98. data/test/dummy/config.ru +0 -4
  99. data/test/dummy/config/application.rb +0 -42
  100. data/test/dummy/config/boot.rb +0 -6
  101. data/test/dummy/config/database.yml +0 -22
  102. data/test/dummy/config/environment.rb +0 -17
  103. data/test/dummy/config/environments/development.rb +0 -25
  104. data/test/dummy/config/environments/production.rb +0 -50
  105. data/test/dummy/config/environments/test.rb +0 -38
  106. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  107. data/test/dummy/config/initializers/inflections.rb +0 -10
  108. data/test/dummy/config/initializers/mime_types.rb +0 -5
  109. data/test/dummy/config/initializers/secret_token.rb +0 -8
  110. data/test/dummy/config/initializers/session_store.rb +0 -8
  111. data/test/dummy/config/locales/en.yml +0 -5
  112. data/test/dummy/config/routes.rb +0 -3
  113. data/test/dummy/db/migrate/20110729022608_create_posts.rb +0 -15
  114. data/test/dummy/db/schema.rb +0 -24
  115. data/test/dummy/db/seeds.rb +0 -7
  116. data/test/dummy/lib/tasks/.gitkeep +0 -0
  117. data/test/dummy/public/404.html +0 -26
  118. data/test/dummy/public/422.html +0 -26
  119. data/test/dummy/public/500.html +0 -26
  120. data/test/dummy/public/favicon.ico +0 -0
  121. data/test/dummy/public/images/rails.png +0 -0
  122. data/test/dummy/public/index.html +0 -239
  123. data/test/dummy/public/javascripts/application.js +0 -2
  124. data/test/dummy/public/javascripts/controls.js +0 -965
  125. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  126. data/test/dummy/public/javascripts/effects.js +0 -1123
  127. data/test/dummy/public/javascripts/prototype.js +0 -6001
  128. data/test/dummy/public/javascripts/rails.js +0 -191
  129. data/test/dummy/public/robots.txt +0 -5
  130. data/test/dummy/public/stylesheets/.gitkeep +0 -0
  131. data/test/dummy/public/stylesheets/scaffold.css +0 -56
  132. data/test/dummy/script/rails +0 -6
  133. data/test/dummy/test/functional/posts_controller_test.rb +0 -218
  134. data/test/dummy/test/test_helper.rb +0 -7
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ require 'rack'
5
+ require 'httparty'
6
+ require 'timecop'
7
+ require 'json'
8
+
9
+ class GoogleChatNotifierTest < ActiveSupport::TestCase
10
+ URL = 'http://localhost:8000'
11
+
12
+ def setup
13
+ Timecop.freeze('2018-12-09 12:07:16 UTC')
14
+ end
15
+
16
+ def teardown
17
+ Timecop.return
18
+ end
19
+
20
+ test 'should send notification if properly configured' do
21
+ HTTParty.expects(:post).with(URL, post_opts("#{header}\n#{body}"))
22
+ notifier.call ArgumentError.new('foo')
23
+ end
24
+
25
+ test 'shoud use errors count if accumulated_errors_count is provided' do
26
+ text = [
27
+ '',
28
+ "Application: *#{app_name}*",
29
+ '5 *ArgumentError* occurred.',
30
+ '',
31
+ body
32
+ ].join("\n")
33
+
34
+ HTTParty.expects(:post).with(URL, post_opts(text))
35
+
36
+ notifier.call(ArgumentError.new('foo'), accumulated_errors_count: 5)
37
+ end
38
+
39
+ test 'Message request should be formatted as hash' do
40
+ text = [
41
+ header,
42
+ body,
43
+ '',
44
+ '*Request:*',
45
+ '```',
46
+ '* url : http://test.address/?id=foo',
47
+ '* http_method : GET',
48
+ '* ip_address : 127.0.0.1',
49
+ '* parameters : {"id"=>"foo"}',
50
+ '* timestamp : 2018-12-09 12:07:16 UTC',
51
+ '```'
52
+ ].join("\n")
53
+
54
+ HTTParty.expects(:post).with(URL, post_opts(text))
55
+
56
+ notifier.call(ArgumentError.new('foo'), env: test_env)
57
+ end
58
+
59
+ test 'backtrace with less than 3 lines should be displayed fully' do
60
+ text = [
61
+ header,
62
+ body,
63
+ '',
64
+ backtrace
65
+ ].join("\n")
66
+
67
+ HTTParty.expects(:post).with(URL, post_opts(text))
68
+
69
+ exception = ArgumentError.new('foo')
70
+ exception.set_backtrace([
71
+ "app/controllers/my_controller.rb:53:in `my_controller_params'",
72
+ "app/controllers/my_controller.rb:34:in `update'"
73
+ ])
74
+
75
+ notifier.call(exception)
76
+ end
77
+
78
+ test 'backtrace with more than 3 lines should display only top 3 lines' do
79
+ text = [
80
+ header,
81
+ body,
82
+ '',
83
+ '*Backtrace:*',
84
+ '```',
85
+ "* app/controllers/my_controller.rb:99:in `specific_function'",
86
+ "* app/controllers/my_controller.rb:70:in `specific_param'",
87
+ "* app/controllers/my_controller.rb:53:in `my_controller_params'",
88
+ '```'
89
+ ].join("\n")
90
+
91
+ HTTParty.expects(:post).with(URL, post_opts(text))
92
+
93
+ exception = ArgumentError.new('foo')
94
+ exception.set_backtrace([
95
+ "app/controllers/my_controller.rb:99:in `specific_function'",
96
+ "app/controllers/my_controller.rb:70:in `specific_param'",
97
+ "app/controllers/my_controller.rb:53:in `my_controller_params'",
98
+ "app/controllers/my_controller.rb:34:in `update'"
99
+ ])
100
+
101
+ notifier.call(exception)
102
+ end
103
+
104
+ test 'Get text with backtrace and request info' do
105
+ text = [
106
+ header,
107
+ body,
108
+ '',
109
+ '*Request:*',
110
+ '```',
111
+ '* url : http://test.address/?id=foo',
112
+ '* http_method : GET',
113
+ '* ip_address : 127.0.0.1',
114
+ '* parameters : {"id"=>"foo"}',
115
+ '* timestamp : 2018-12-09 12:07:16 UTC',
116
+ '```',
117
+ '',
118
+ backtrace
119
+ ].join("\n")
120
+
121
+ HTTParty.expects(:post).with(URL, post_opts(text))
122
+
123
+ exception = ArgumentError.new('foo')
124
+ exception.set_backtrace([
125
+ "app/controllers/my_controller.rb:53:in `my_controller_params'",
126
+ "app/controllers/my_controller.rb:34:in `update'"
127
+ ])
128
+
129
+ notifier.call(exception, env: test_env)
130
+ end
131
+
132
+ private
133
+
134
+ def notifier
135
+ ExceptionNotifier::GoogleChatNotifier.new(webhook_url: URL)
136
+ end
137
+
138
+ def post_opts(text)
139
+ {
140
+ body: { text: text }.to_json,
141
+ headers: { 'Content-Type' => 'application/json' }
142
+ }
143
+ end
144
+
145
+ def test_env
146
+ Rack::MockRequest.env_for(
147
+ '/',
148
+ 'HTTP_HOST' => 'test.address',
149
+ 'REMOTE_ADDR' => '127.0.0.1',
150
+ 'HTTP_USER_AGENT' => 'Rails Testing',
151
+ params: { id: 'foo' }
152
+ )
153
+ end
154
+
155
+ def header
156
+ [
157
+ '',
158
+ "Application: *#{app_name}*",
159
+ 'An *ArgumentError* occurred.',
160
+ ''
161
+ ].join("\n")
162
+ end
163
+
164
+ def body
165
+ if defined?(::Rails) && ::Rails.respond_to?(:env)
166
+ "⚠️ Error occurred in test ⚠️\n*foo*"
167
+ else
168
+ "⚠️ Error occurred ⚠️\n*foo*"
169
+ end
170
+ end
171
+
172
+ def app_name
173
+ 'dummy' if defined?(::Rails) && ::Rails.respond_to?(:application)
174
+ end
175
+
176
+ def backtrace
177
+ [
178
+ '*Backtrace:*',
179
+ '```',
180
+ "* app/controllers/my_controller.rb:53:in `my_controller_params'",
181
+ "* app/controllers/my_controller.rb:34:in `update'",
182
+ '```'
183
+ ]
184
+ end
185
+ end
@@ -1,32 +1,43 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
- require 'hipchat'
4
+ require 'rack'
3
5
 
4
- class HipchatNotifierTest < ActiveSupport::TestCase
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
5
12
 
6
- test "should send hipchat notification if properly configured" do
13
+ class HipchatNotifierTest < ActiveSupport::TestCase
14
+ test 'should send hipchat notification if properly configured' do
7
15
  options = {
8
- :api_token => 'good_token',
9
- :room_name => 'room_name',
10
- :color => 'yellow',
16
+ api_token: 'good_token',
17
+ room_name: 'room_name',
18
+ color: 'yellow'
11
19
  }
12
20
 
13
- HipChat::Room.any_instance.expects(:send).with('Exception', fake_body, { :color => 'yellow' })
21
+ HipChat::Room.any_instance.expects(:send).with('Exception', fake_body, color: 'yellow')
14
22
 
15
23
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
16
24
  hipchat.call(fake_exception)
17
25
  end
18
26
 
19
- test "should call pre/post_callback if specified" do
20
- pre_callback_called, post_callback_called = 0,0
27
+ test 'should call pre/post_callback if specified' do
28
+ pre_callback_called = 0
29
+ post_callback_called = 0
21
30
  options = {
22
- :api_token => 'good_token',
23
- :room_name => 'room_name',
24
- :color => 'yellow',
25
- :pre_callback => proc { |*| pre_callback_called += 1},
26
- :post_callback => proc { |*| post_callback_called += 1}
31
+ api_token: 'good_token',
32
+ room_name: 'room_name',
33
+ color: 'yellow',
34
+ pre_callback: proc { |*| pre_callback_called += 1 },
35
+ post_callback: proc { |*| post_callback_called += 1 }
27
36
  }
28
37
 
29
- HipChat::Room.any_instance.expects(:send).with('Exception', fake_body, { :color => 'yellow' }.merge(options.except(:api_token, :room_name)))
38
+ HipChat::Room.any_instance
39
+ .expects(:send)
40
+ .with('Exception', fake_body, { color: 'yellow' }.merge(options.except(:api_token, :room_name)))
30
41
 
31
42
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
32
43
  hipchat.call(fake_exception)
@@ -34,112 +45,152 @@ class HipchatNotifierTest < ActiveSupport::TestCase
34
45
  assert_equal(1, post_callback_called)
35
46
  end
36
47
 
37
- test "should send hipchat notification without backtrace info if properly configured" do
48
+ test 'should send hipchat notification without backtrace info if properly configured' do
38
49
  options = {
39
- :api_token => 'good_token',
40
- :room_name => 'room_name',
41
- :color => 'yellow',
50
+ api_token: 'good_token',
51
+ room_name: 'room_name',
52
+ color: 'yellow'
42
53
  }
43
54
 
44
- HipChat::Room.any_instance.expects(:send).with('Exception', fake_body_without_backtrace, { :color => 'yellow' })
55
+ HipChat::Room.any_instance.expects(:send).with('Exception', fake_body_without_backtrace, color: 'yellow')
45
56
 
46
57
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
47
58
  hipchat.call(fake_exception_without_backtrace)
48
59
  end
49
60
 
50
- test "should allow custom from value if set" do
61
+ test 'should allow custom from value if set' do
51
62
  options = {
52
- :api_token => 'good_token',
53
- :room_name => 'room_name',
54
- :from => 'TrollFace',
63
+ api_token: 'good_token',
64
+ room_name: 'room_name',
65
+ from: 'TrollFace'
55
66
  }
56
67
 
57
- HipChat::Room.any_instance.expects(:send).with('TrollFace', fake_body, { :color => 'red' })
68
+ HipChat::Room.any_instance.expects(:send).with('TrollFace', fake_body, color: 'red')
58
69
 
59
70
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
60
71
  hipchat.call(fake_exception)
61
72
  end
62
73
 
63
- test "should not send hipchat notification if badly configured" do
74
+ test 'should not send hipchat notification if badly configured' do
64
75
  wrong_params = {
65
- :api_token => 'bad_token',
66
- :room_name => 'test_room'
76
+ api_token: 'bad_token',
77
+ room_name: 'test_room'
67
78
  }
68
79
 
69
- HipChat::Client.stubs(:new).with('bad_token', {:api_version => 'v1'}).returns(nil)
80
+ HipChat::Client.stubs(:new).with('bad_token', api_version: 'v1').returns(nil)
70
81
 
71
82
  hipchat = ExceptionNotifier::HipchatNotifier.new(wrong_params)
72
83
  assert_nil hipchat.room
73
84
  end
74
85
 
75
- test "should not send hipchat notification if api_key is missing" do
76
- wrong_params = {:room_name => 'test_room'}
86
+ test 'should not send hipchat notification if api_key is missing' do
87
+ wrong_params = { room_name: 'test_room' }
77
88
 
78
- HipChat::Client.stubs(:new).with(nil, {:api_version => 'v1'}).returns(nil)
89
+ HipChat::Client.stubs(:new).with(nil, api_version: 'v1').returns(nil)
79
90
 
80
91
  hipchat = ExceptionNotifier::HipchatNotifier.new(wrong_params)
81
92
  assert_nil hipchat.room
82
93
  end
83
94
 
84
- test "should not send hipchat notification if room_name is missing" do
85
- wrong_params = {:api_token => 'good_token'}
95
+ test 'should not send hipchat notification if room_name is missing' do
96
+ wrong_params = { api_token: 'good_token' }
86
97
 
87
- HipChat::Client.stubs(:new).with('good_token', {:api_version => 'v1'}).returns({})
98
+ HipChat::Client.stubs(:new).with('good_token', api_version: 'v1').returns({})
88
99
 
89
100
  hipchat = ExceptionNotifier::HipchatNotifier.new(wrong_params)
90
101
  assert_nil hipchat.room
91
102
  end
92
103
 
93
- test "should send hipchat notification with message_template" do
104
+ test 'should send hipchat notification with message_template' do
94
105
  options = {
95
- :api_token => 'good_token',
96
- :room_name => 'room_name',
97
- :color => 'yellow',
98
- :message_template => ->(exception) { "This is custom message: '#{exception.message}'" }
106
+ api_token: 'good_token',
107
+ room_name: 'room_name',
108
+ color: 'yellow',
109
+ message_template: ->(exception, _) { "This is custom message: '#{exception.message}'" }
99
110
  }
100
111
 
101
- HipChat::Room.any_instance.expects(:send).with('Exception', "This is custom message: '#{fake_exception.message}'", { :color => 'yellow' })
112
+ HipChat::Room.any_instance
113
+ .expects(:send)
114
+ .with('Exception', "This is custom message: '#{fake_exception.message}'", color: 'yellow')
102
115
 
103
116
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
104
117
  hipchat.call(fake_exception)
105
118
  end
106
119
 
107
- test "should send hipchat notification with HTML-escaped meessage if using default message_template" do
120
+ test 'should send hipchat notification exclude accumulated errors count' do
108
121
  options = {
109
- :api_token => 'good_token',
110
- :room_name => 'room_name',
111
- :color => 'yellow',
122
+ api_token: 'good_token',
123
+ room_name: 'room_name',
124
+ color: 'yellow'
125
+ }
126
+
127
+ HipChat::Room.any_instance.expects(:send).with { |_, msg, _| msg.start_with?('A new exception occurred:') }
128
+ hipchat = ExceptionNotifier::HipchatNotifier.new(options)
129
+ hipchat.call(fake_exception)
130
+ end
131
+
132
+ test 'should send hipchat notification include accumulated errors count' do
133
+ options = {
134
+ api_token: 'good_token',
135
+ room_name: 'room_name',
136
+ color: 'yellow'
137
+ }
138
+
139
+ HipChat::Room.any_instance.expects(:send).with { |_, msg, _| msg.start_with?('The exception occurred 3 times:') }
140
+ hipchat = ExceptionNotifier::HipchatNotifier.new(options)
141
+ hipchat.call(fake_exception, accumulated_errors_count: 3)
142
+ end
143
+
144
+ test 'should send hipchat notification with HTML-escaped meessage if using default message_template' do
145
+ options = {
146
+ api_token: 'good_token',
147
+ room_name: 'room_name',
148
+ color: 'yellow'
112
149
  }
113
150
 
114
151
  exception = fake_exception_with_html_characters
115
152
  body = "A new exception occurred: '#{Rack::Utils.escape_html(exception.message)}' on '#{exception.backtrace.first}'"
116
153
 
117
- HipChat::Room.any_instance.expects(:send).with('Exception', body, { :color => 'yellow' })
154
+ HipChat::Room.any_instance.expects(:send).with('Exception', body, color: 'yellow')
118
155
 
119
156
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
120
157
  hipchat.call(exception)
121
158
  end
122
159
 
123
- test "should use APIv1 if api_version is not specified" do
160
+ test 'should use APIv1 if api_version is not specified' do
161
+ options = {
162
+ api_token: 'good_token',
163
+ room_name: 'room_name'
164
+ }
165
+
166
+ HipChat::Client.stubs(:new).with('good_token', api_version: 'v1').returns({})
167
+
168
+ hipchat = ExceptionNotifier::HipchatNotifier.new(options)
169
+ hipchat.call(fake_exception)
170
+ end
171
+
172
+ test 'should use APIv2 when specified' do
124
173
  options = {
125
- :api_token => 'good_token',
126
- :room_name => 'room_name',
174
+ api_token: 'good_token',
175
+ room_name: 'room_name',
176
+ api_version: 'v2'
127
177
  }
128
178
 
129
- HipChat::Client.stubs(:new).with('good_token', {:api_version => 'v1'}).returns({})
179
+ HipChat::Client.stubs(:new).with('good_token', api_version: 'v2').returns({})
130
180
 
131
181
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
132
182
  hipchat.call(fake_exception)
133
183
  end
134
184
 
135
- test "should use APIv2 when specified" do
185
+ test 'should allow server_url value (for a self-hosted HipChat Server) if set' do
136
186
  options = {
137
- :api_token => 'good_token',
138
- :room_name => 'room_name',
139
- :api_version => 'v2',
187
+ api_token: 'good_token',
188
+ room_name: 'room_name',
189
+ api_version: 'v2',
190
+ server_url: 'https://domain.com'
140
191
  }
141
192
 
142
- HipChat::Client.stubs(:new).with('good_token', {:api_version => 'v2'}).returns({})
193
+ HipChat::Client.stubs(:new).with('good_token', api_version: 'v2', server_url: 'https://domain.com').returns({})
143
194
 
144
195
  hipchat = ExceptionNotifier::HipchatNotifier.new(options)
145
196
  hipchat.call(fake_exception)
@@ -152,19 +203,15 @@ class HipchatNotifierTest < ActiveSupport::TestCase
152
203
  end
153
204
 
154
205
  def fake_exception
155
- exception = begin
156
- 5/0
157
- rescue Exception => e
158
- e
159
- end
206
+ 5 / 0
207
+ rescue StandardError => e
208
+ e
160
209
  end
161
210
 
162
211
  def fake_exception_with_html_characters
163
- exception = begin
164
- raise StandardError.new('an error with <html> characters')
165
- rescue Exception => e
166
- e
167
- end
212
+ raise StandardError, 'an error with <html> characters'
213
+ rescue StandardError => e
214
+ e
168
215
  end
169
216
 
170
217
  def fake_body_without_backtrace