exception_notification 4.2.1 → 4.4.3
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.
- checksums.yaml +5 -5
- data/Appraisals +4 -3
- data/CHANGELOG.rdoc +57 -1
- data/CONTRIBUTING.md +21 -2
- data/Gemfile +3 -1
- data/README.md +105 -780
- data/Rakefile +4 -2
- data/docs/notifiers/campfire.md +50 -0
- data/docs/notifiers/custom.md +42 -0
- data/docs/notifiers/datadog.md +51 -0
- data/docs/notifiers/email.md +195 -0
- data/docs/notifiers/google_chat.md +31 -0
- data/docs/notifiers/hipchat.md +66 -0
- data/docs/notifiers/irc.md +97 -0
- data/docs/notifiers/mattermost.md +115 -0
- data/docs/notifiers/slack.md +161 -0
- data/docs/notifiers/sns.md +37 -0
- data/docs/notifiers/teams.md +54 -0
- data/docs/notifiers/webhook.md +60 -0
- data/examples/sample_app.rb +56 -0
- data/examples/sinatra/Gemfile +8 -6
- data/examples/sinatra/config.ru +3 -1
- data/examples/sinatra/sinatra_app.rb +19 -11
- data/exception_notification.gemspec +30 -23
- data/gemfiles/rails4_0.gemfile +1 -2
- data/gemfiles/rails4_1.gemfile +1 -2
- data/gemfiles/rails4_2.gemfile +1 -2
- data/gemfiles/rails5_0.gemfile +1 -2
- data/gemfiles/rails5_1.gemfile +7 -0
- data/gemfiles/rails5_2.gemfile +7 -0
- data/gemfiles/rails6_0.gemfile +7 -0
- data/lib/exception_notification.rb +3 -0
- data/lib/exception_notification/rack.rb +30 -23
- data/lib/exception_notification/rails.rb +3 -0
- data/lib/exception_notification/resque.rb +10 -10
- data/lib/exception_notification/sidekiq.rb +10 -12
- data/lib/exception_notification/version.rb +5 -0
- data/lib/exception_notifier.rb +79 -11
- data/lib/exception_notifier/base_notifier.rb +10 -5
- data/lib/exception_notifier/campfire_notifier.rb +14 -9
- data/lib/exception_notifier/datadog_notifier.rb +156 -0
- data/lib/exception_notifier/email_notifier.rb +78 -87
- data/lib/exception_notifier/google_chat_notifier.rb +44 -0
- data/lib/exception_notifier/hipchat_notifier.rb +16 -10
- data/lib/exception_notifier/irc_notifier.rb +38 -31
- data/lib/exception_notifier/mattermost_notifier.rb +54 -131
- data/lib/exception_notifier/modules/backtrace_cleaner.rb +2 -2
- data/lib/exception_notifier/modules/error_grouping.rb +87 -0
- data/lib/exception_notifier/modules/formatter.rb +121 -0
- data/lib/exception_notifier/notifier.rb +9 -6
- data/lib/exception_notifier/slack_notifier.rb +71 -40
- data/lib/exception_notifier/sns_notifier.rb +86 -0
- data/lib/exception_notifier/teams_notifier.rb +200 -0
- data/lib/exception_notifier/views/exception_notifier/_backtrace.html.erb +1 -1
- data/lib/exception_notifier/views/exception_notifier/_environment.text.erb +1 -1
- data/lib/exception_notifier/views/exception_notifier/_request.text.erb +1 -1
- data/lib/exception_notifier/views/exception_notifier/background_exception_notification.text.erb +9 -9
- data/lib/exception_notifier/views/exception_notifier/exception_notification.html.erb +2 -4
- data/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb +2 -2
- data/lib/exception_notifier/webhook_notifier.rb +17 -14
- data/lib/generators/exception_notification/install_generator.rb +11 -5
- data/lib/generators/exception_notification/templates/{exception_notification.rb → exception_notification.rb.erb} +13 -11
- data/test/exception_notification/rack_test.rb +90 -4
- data/test/exception_notification/resque_test.rb +54 -0
- data/test/exception_notifier/campfire_notifier_test.rb +59 -38
- data/test/exception_notifier/datadog_notifier_test.rb +153 -0
- data/test/exception_notifier/email_notifier_test.rb +279 -145
- data/test/exception_notifier/google_chat_notifier_test.rb +185 -0
- data/test/exception_notifier/hipchat_notifier_test.rb +105 -64
- data/test/exception_notifier/irc_notifier_test.rb +48 -30
- data/test/exception_notifier/mattermost_notifier_test.rb +218 -55
- data/test/exception_notifier/modules/error_grouping_test.rb +167 -0
- data/test/exception_notifier/modules/formatter_test.rb +152 -0
- data/test/exception_notifier/sidekiq_test.rb +9 -17
- data/test/exception_notifier/slack_notifier_test.rb +84 -62
- data/test/exception_notifier/sns_notifier_test.rb +123 -0
- data/test/exception_notifier/teams_notifier_test.rb +92 -0
- data/test/exception_notifier/webhook_notifier_test.rb +52 -48
- data/test/exception_notifier_test.rb +220 -37
- data/test/support/exception_notifier_helper.rb +14 -0
- data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.html.erb +0 -0
- data/test/{dummy/app → support}/views/exception_notifier/_new_bkg_section.text.erb +0 -0
- data/test/{dummy/app → support}/views/exception_notifier/_new_section.html.erb +0 -0
- data/test/{dummy/app → support}/views/exception_notifier/_new_section.text.erb +0 -0
- data/test/test_helper.rb +14 -13
- metadata +154 -162
- data/test/dummy/.gitignore +0 -4
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/controllers/posts_controller.rb +0 -30
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/helpers/posts_helper.rb +0 -2
- data/test/dummy/app/models/post.rb +0 -2
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/app/views/posts/_form.html.erb +0 -0
- data/test/dummy/app/views/posts/new.html.erb +0 -0
- data/test/dummy/app/views/posts/show.html.erb +0 -0
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -42
- data/test/dummy/config/boot.rb +0 -6
- data/test/dummy/config/database.yml +0 -22
- data/test/dummy/config/environment.rb +0 -17
- data/test/dummy/config/environments/development.rb +0 -25
- data/test/dummy/config/environments/production.rb +0 -50
- data/test/dummy/config/environments/test.rb +0 -35
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -10
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -8
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -3
- data/test/dummy/db/migrate/20110729022608_create_posts.rb +0 -15
- data/test/dummy/db/schema.rb +0 -24
- data/test/dummy/db/seeds.rb +0 -7
- data/test/dummy/lib/tasks/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/images/rails.png +0 -0
- data/test/dummy/public/index.html +0 -239
- data/test/dummy/public/javascripts/application.js +0 -2
- data/test/dummy/public/javascripts/controls.js +0 -965
- data/test/dummy/public/javascripts/dragdrop.js +0 -974
- data/test/dummy/public/javascripts/effects.js +0 -1123
- data/test/dummy/public/javascripts/prototype.js +0 -6001
- data/test/dummy/public/javascripts/rails.js +0 -191
- data/test/dummy/public/robots.txt +0 -5
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/dummy/public/stylesheets/scaffold.css +0 -56
- data/test/dummy/script/rails +0 -6
- data/test/dummy/test/functional/posts_controller_test.rb +0 -218
- 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,4 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'test_helper'
|
|
4
|
+
require 'rack'
|
|
2
5
|
|
|
3
6
|
# silence_warnings trick around require can be removed once
|
|
4
7
|
# https://github.com/hipchat/hipchat-rb/pull/174
|
|
@@ -8,31 +11,33 @@ silence_warnings do
|
|
|
8
11
|
end
|
|
9
12
|
|
|
10
13
|
class HipchatNotifierTest < ActiveSupport::TestCase
|
|
11
|
-
|
|
12
|
-
test "should send hipchat notification if properly configured" do
|
|
14
|
+
test 'should send hipchat notification if properly configured' do
|
|
13
15
|
options = {
|
|
14
|
-
:
|
|
15
|
-
:
|
|
16
|
-
:
|
|
16
|
+
api_token: 'good_token',
|
|
17
|
+
room_name: 'room_name',
|
|
18
|
+
color: 'yellow'
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
HipChat::Room.any_instance.expects(:send).with('Exception', fake_body,
|
|
21
|
+
HipChat::Room.any_instance.expects(:send).with('Exception', fake_body, color: 'yellow')
|
|
20
22
|
|
|
21
23
|
hipchat = ExceptionNotifier::HipchatNotifier.new(options)
|
|
22
24
|
hipchat.call(fake_exception)
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
test
|
|
26
|
-
pre_callback_called
|
|
27
|
+
test 'should call pre/post_callback if specified' do
|
|
28
|
+
pre_callback_called = 0
|
|
29
|
+
post_callback_called = 0
|
|
27
30
|
options = {
|
|
28
|
-
:
|
|
29
|
-
:
|
|
30
|
-
:
|
|
31
|
-
:
|
|
32
|
-
:
|
|
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 }
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
HipChat::Room.any_instance
|
|
38
|
+
HipChat::Room.any_instance
|
|
39
|
+
.expects(:send)
|
|
40
|
+
.with('Exception', fake_body, { color: 'yellow' }.merge(options.except(:api_token, :room_name)))
|
|
36
41
|
|
|
37
42
|
hipchat = ExceptionNotifier::HipchatNotifier.new(options)
|
|
38
43
|
hipchat.call(fake_exception)
|
|
@@ -40,112 +45,152 @@ class HipchatNotifierTest < ActiveSupport::TestCase
|
|
|
40
45
|
assert_equal(1, post_callback_called)
|
|
41
46
|
end
|
|
42
47
|
|
|
43
|
-
test
|
|
48
|
+
test 'should send hipchat notification without backtrace info if properly configured' do
|
|
44
49
|
options = {
|
|
45
|
-
:
|
|
46
|
-
:
|
|
47
|
-
:
|
|
50
|
+
api_token: 'good_token',
|
|
51
|
+
room_name: 'room_name',
|
|
52
|
+
color: 'yellow'
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
HipChat::Room.any_instance.expects(:send).with('Exception', fake_body_without_backtrace,
|
|
55
|
+
HipChat::Room.any_instance.expects(:send).with('Exception', fake_body_without_backtrace, color: 'yellow')
|
|
51
56
|
|
|
52
57
|
hipchat = ExceptionNotifier::HipchatNotifier.new(options)
|
|
53
58
|
hipchat.call(fake_exception_without_backtrace)
|
|
54
59
|
end
|
|
55
60
|
|
|
56
|
-
test
|
|
61
|
+
test 'should allow custom from value if set' do
|
|
57
62
|
options = {
|
|
58
|
-
:
|
|
59
|
-
:
|
|
60
|
-
:
|
|
63
|
+
api_token: 'good_token',
|
|
64
|
+
room_name: 'room_name',
|
|
65
|
+
from: 'TrollFace'
|
|
61
66
|
}
|
|
62
67
|
|
|
63
|
-
HipChat::Room.any_instance.expects(:send).with('TrollFace', fake_body,
|
|
68
|
+
HipChat::Room.any_instance.expects(:send).with('TrollFace', fake_body, color: 'red')
|
|
64
69
|
|
|
65
70
|
hipchat = ExceptionNotifier::HipchatNotifier.new(options)
|
|
66
71
|
hipchat.call(fake_exception)
|
|
67
72
|
end
|
|
68
73
|
|
|
69
|
-
test
|
|
74
|
+
test 'should not send hipchat notification if badly configured' do
|
|
70
75
|
wrong_params = {
|
|
71
|
-
:
|
|
72
|
-
:
|
|
76
|
+
api_token: 'bad_token',
|
|
77
|
+
room_name: 'test_room'
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
HipChat::Client.stubs(:new).with('bad_token',
|
|
80
|
+
HipChat::Client.stubs(:new).with('bad_token', api_version: 'v1').returns(nil)
|
|
76
81
|
|
|
77
82
|
hipchat = ExceptionNotifier::HipchatNotifier.new(wrong_params)
|
|
78
83
|
assert_nil hipchat.room
|
|
79
84
|
end
|
|
80
85
|
|
|
81
|
-
test
|
|
82
|
-
wrong_params
|
|
86
|
+
test 'should not send hipchat notification if api_key is missing' do
|
|
87
|
+
wrong_params = { room_name: 'test_room' }
|
|
83
88
|
|
|
84
|
-
HipChat::Client.stubs(:new).with(nil,
|
|
89
|
+
HipChat::Client.stubs(:new).with(nil, api_version: 'v1').returns(nil)
|
|
85
90
|
|
|
86
91
|
hipchat = ExceptionNotifier::HipchatNotifier.new(wrong_params)
|
|
87
92
|
assert_nil hipchat.room
|
|
88
93
|
end
|
|
89
94
|
|
|
90
|
-
test
|
|
91
|
-
wrong_params
|
|
95
|
+
test 'should not send hipchat notification if room_name is missing' do
|
|
96
|
+
wrong_params = { api_token: 'good_token' }
|
|
92
97
|
|
|
93
|
-
HipChat::Client.stubs(:new).with('good_token',
|
|
98
|
+
HipChat::Client.stubs(:new).with('good_token', api_version: 'v1').returns({})
|
|
94
99
|
|
|
95
100
|
hipchat = ExceptionNotifier::HipchatNotifier.new(wrong_params)
|
|
96
101
|
assert_nil hipchat.room
|
|
97
102
|
end
|
|
98
103
|
|
|
99
|
-
test
|
|
104
|
+
test 'should send hipchat notification with message_template' do
|
|
100
105
|
options = {
|
|
101
|
-
:
|
|
102
|
-
:
|
|
103
|
-
:
|
|
104
|
-
:
|
|
106
|
+
api_token: 'good_token',
|
|
107
|
+
room_name: 'room_name',
|
|
108
|
+
color: 'yellow',
|
|
109
|
+
message_template: ->(exception, _) { "This is custom message: '#{exception.message}'" }
|
|
105
110
|
}
|
|
106
111
|
|
|
107
|
-
HipChat::Room.any_instance
|
|
112
|
+
HipChat::Room.any_instance
|
|
113
|
+
.expects(:send)
|
|
114
|
+
.with('Exception', "This is custom message: '#{fake_exception.message}'", color: 'yellow')
|
|
115
|
+
|
|
116
|
+
hipchat = ExceptionNotifier::HipchatNotifier.new(options)
|
|
117
|
+
hipchat.call(fake_exception)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
test 'should send hipchat notification exclude accumulated errors count' do
|
|
121
|
+
options = {
|
|
122
|
+
api_token: 'good_token',
|
|
123
|
+
room_name: 'room_name',
|
|
124
|
+
color: 'yellow'
|
|
125
|
+
}
|
|
108
126
|
|
|
127
|
+
HipChat::Room.any_instance.expects(:send).with { |_, msg, _| msg.start_with?('A new exception occurred:') }
|
|
109
128
|
hipchat = ExceptionNotifier::HipchatNotifier.new(options)
|
|
110
129
|
hipchat.call(fake_exception)
|
|
111
130
|
end
|
|
112
131
|
|
|
113
|
-
test
|
|
132
|
+
test 'should send hipchat notification include accumulated errors count' do
|
|
114
133
|
options = {
|
|
115
|
-
:
|
|
116
|
-
:
|
|
117
|
-
:
|
|
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'
|
|
118
149
|
}
|
|
119
150
|
|
|
120
151
|
exception = fake_exception_with_html_characters
|
|
121
152
|
body = "A new exception occurred: '#{Rack::Utils.escape_html(exception.message)}' on '#{exception.backtrace.first}'"
|
|
122
153
|
|
|
123
|
-
HipChat::Room.any_instance.expects(:send).with('Exception', body,
|
|
154
|
+
HipChat::Room.any_instance.expects(:send).with('Exception', body, color: 'yellow')
|
|
124
155
|
|
|
125
156
|
hipchat = ExceptionNotifier::HipchatNotifier.new(options)
|
|
126
157
|
hipchat.call(exception)
|
|
127
158
|
end
|
|
128
159
|
|
|
129
|
-
test
|
|
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
|
|
130
173
|
options = {
|
|
131
|
-
:
|
|
132
|
-
:
|
|
174
|
+
api_token: 'good_token',
|
|
175
|
+
room_name: 'room_name',
|
|
176
|
+
api_version: 'v2'
|
|
133
177
|
}
|
|
134
178
|
|
|
135
|
-
HipChat::Client.stubs(:new).with('good_token',
|
|
179
|
+
HipChat::Client.stubs(:new).with('good_token', api_version: 'v2').returns({})
|
|
136
180
|
|
|
137
181
|
hipchat = ExceptionNotifier::HipchatNotifier.new(options)
|
|
138
182
|
hipchat.call(fake_exception)
|
|
139
183
|
end
|
|
140
184
|
|
|
141
|
-
test
|
|
185
|
+
test 'should allow server_url value (for a self-hosted HipChat Server) if set' do
|
|
142
186
|
options = {
|
|
143
|
-
:
|
|
144
|
-
:
|
|
145
|
-
:
|
|
187
|
+
api_token: 'good_token',
|
|
188
|
+
room_name: 'room_name',
|
|
189
|
+
api_version: 'v2',
|
|
190
|
+
server_url: 'https://domain.com'
|
|
146
191
|
}
|
|
147
192
|
|
|
148
|
-
HipChat::Client.stubs(:new).with('good_token',
|
|
193
|
+
HipChat::Client.stubs(:new).with('good_token', api_version: 'v2', server_url: 'https://domain.com').returns({})
|
|
149
194
|
|
|
150
195
|
hipchat = ExceptionNotifier::HipchatNotifier.new(options)
|
|
151
196
|
hipchat.call(fake_exception)
|
|
@@ -158,19 +203,15 @@ class HipchatNotifierTest < ActiveSupport::TestCase
|
|
|
158
203
|
end
|
|
159
204
|
|
|
160
205
|
def fake_exception
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
e
|
|
165
|
-
end
|
|
206
|
+
5 / 0
|
|
207
|
+
rescue StandardError => e
|
|
208
|
+
e
|
|
166
209
|
end
|
|
167
210
|
|
|
168
211
|
def fake_exception_with_html_characters
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
e
|
|
173
|
-
end
|
|
212
|
+
raise StandardError, 'an error with <html> characters'
|
|
213
|
+
rescue StandardError => e
|
|
214
|
+
e
|
|
174
215
|
end
|
|
175
216
|
|
|
176
217
|
def fake_body_without_backtrace
|