exception_notification 4.2.0 → 4.4.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +106 -789
- 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 +34 -27
- 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 +75 -32
- 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 +19 -16
- data/lib/generators/exception_notification/install_generator.rb +11 -5
- data/lib/generators/exception_notification/templates/{exception_notification.rb → exception_notification.rb.erb} +14 -12
- 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 +66 -39
- data/test/exception_notifier/datadog_notifier_test.rb +153 -0
- data/test/exception_notifier/email_notifier_test.rb +301 -145
- data/test/exception_notifier/google_chat_notifier_test.rb +185 -0
- data/test/exception_notifier/hipchat_notifier_test.rb +112 -65
- 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 -6
- data/test/exception_notifier/slack_notifier_test.rb +109 -59
- 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 +68 -38
- 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 -38
- 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,32 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
|
-
require '
|
4
|
+
require 'rack'
|
3
5
|
|
4
|
-
|
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
|
-
|
13
|
+
class HipchatNotifierTest < ActiveSupport::TestCase
|
14
|
+
test 'should send hipchat notification if properly configured' do
|
7
15
|
options = {
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
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,
|
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
|
20
|
-
pre_callback_called
|
27
|
+
test 'should call pre/post_callback if specified' do
|
28
|
+
pre_callback_called = 0
|
29
|
+
post_callback_called = 0
|
21
30
|
options = {
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
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
|
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
|
48
|
+
test 'should send hipchat notification without backtrace info if properly configured' do
|
38
49
|
options = {
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
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,
|
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
|
61
|
+
test 'should allow custom from value if set' do
|
51
62
|
options = {
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
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,
|
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
|
74
|
+
test 'should not send hipchat notification if badly configured' do
|
64
75
|
wrong_params = {
|
65
|
-
:
|
66
|
-
:
|
76
|
+
api_token: 'bad_token',
|
77
|
+
room_name: 'test_room'
|
67
78
|
}
|
68
79
|
|
69
|
-
HipChat::Client.stubs(:new).with('bad_token',
|
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
|
76
|
-
wrong_params
|
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,
|
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
|
85
|
-
wrong_params
|
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',
|
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
|
104
|
+
test 'should send hipchat notification with message_template' do
|
94
105
|
options = {
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
98
|
-
:
|
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
|
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
|
120
|
+
test 'should send hipchat notification exclude accumulated errors count' do
|
108
121
|
options = {
|
109
|
-
:
|
110
|
-
:
|
111
|
-
:
|
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,
|
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
|
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
|
-
:
|
126
|
-
:
|
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',
|
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
|
185
|
+
test 'should allow server_url value (for a self-hosted HipChat Server) if set' do
|
136
186
|
options = {
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
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',
|
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
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
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
|