exception_notification 4.6.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.rdoc +16 -0
- data/CONTRIBUTING.md +23 -51
- data/Gemfile +1 -1
- data/Gemfile.lock +27 -33
- data/README.md +65 -31
- data/Rakefile +14 -7
- data/exception_notification.gemspec +27 -30
- data/gemfiles/pinned_dependencies.gemfile +8 -0
- data/gemfiles/rails7_1.gemfile +5 -0
- data/gemfiles/rails7_2.gemfile +5 -0
- data/gemfiles/rails8_0.gemfile +5 -0
- data/lib/exception_notification/rack.rb +4 -4
- data/lib/exception_notification/rails.rb +2 -2
- data/lib/exception_notification/rake.rb +3 -7
- data/lib/exception_notification/resque.rb +2 -2
- data/lib/exception_notification/sidekiq.rb +8 -23
- data/lib/exception_notification/version.rb +1 -1
- data/lib/exception_notification.rb +3 -3
- data/lib/exception_notifier/datadog_notifier.rb +26 -26
- data/lib/exception_notifier/email_notifier.rb +34 -30
- data/lib/exception_notifier/google_chat_notifier.rb +9 -9
- data/lib/exception_notifier/hipchat_notifier.rb +12 -12
- data/lib/exception_notifier/irc_notifier.rb +6 -6
- data/lib/exception_notifier/mattermost_notifier.rb +13 -13
- data/lib/exception_notifier/modules/error_grouping.rb +5 -5
- data/lib/exception_notifier/modules/formatter.rb +12 -12
- data/lib/exception_notifier/notifier.rb +3 -3
- data/lib/exception_notifier/slack_notifier.rb +16 -16
- data/lib/exception_notifier/sns_notifier.rb +9 -9
- data/lib/exception_notifier/teams_notifier.rb +61 -57
- data/lib/exception_notifier/webhook_notifier.rb +3 -3
- data/lib/exception_notifier.rb +27 -26
- data/lib/generators/exception_notification/install_generator.rb +7 -7
- data/lib/generators/exception_notification/templates/exception_notification.rb.erb +26 -27
- data/test/exception_notification/rack_test.rb +14 -14
- data/test/exception_notification/rake_test.rb +13 -13
- data/test/exception_notification/resque_test.rb +14 -14
- data/test/exception_notifier/datadog_notifier_test.rb +47 -46
- data/test/exception_notifier/email_notifier_test.rb +89 -98
- data/test/exception_notifier/google_chat_notifier_test.rb +77 -77
- data/test/exception_notifier/hipchat_notifier_test.rb +76 -74
- data/test/exception_notifier/irc_notifier_test.rb +26 -26
- data/test/exception_notifier/mattermost_notifier_test.rb +77 -77
- data/test/exception_notifier/modules/error_grouping_test.rb +39 -39
- data/test/exception_notifier/modules/formatter_test.rb +51 -49
- data/test/exception_notifier/sidekiq_test.rb +17 -10
- data/test/exception_notifier/slack_notifier_test.rb +66 -67
- data/test/exception_notifier/sns_notifier_test.rb +73 -70
- data/test/exception_notifier/teams_notifier_test.rb +33 -33
- data/test/exception_notifier/webhook_notifier_test.rb +34 -34
- data/test/exception_notifier_test.rb +51 -41
- data/test/test_helper.rb +8 -11
- metadata +45 -85
- data/Appraisals +0 -9
- data/gemfiles/rails5_2.gemfile +0 -7
- data/gemfiles/rails6_0.gemfile +0 -7
- data/gemfiles/rails6_1.gemfile +0 -7
- data/gemfiles/rails7_0.gemfile +0 -7
@@ -1,53 +1,54 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "test_helper"
|
4
|
+
require "action_mailer"
|
5
|
+
require "action_controller"
|
6
6
|
|
7
7
|
class EmailNotifierTest < ActiveSupport::TestCase
|
8
8
|
setup do
|
9
|
-
Time.stubs(:current).returns(
|
9
|
+
Time.stubs(:current).returns("Sat, 20 Apr 2013 20:58:55 UTC +00:00")
|
10
10
|
|
11
|
-
@exception = ZeroDivisionError.new(
|
12
|
-
@exception.set_backtrace([
|
11
|
+
@exception = ZeroDivisionError.new("divided by 0")
|
12
|
+
@exception.set_backtrace(["test/exception_notifier/email_notifier_test.rb:20"])
|
13
13
|
|
14
14
|
@email_notifier = ExceptionNotifier::EmailNotifier.new(
|
15
|
-
email_prefix:
|
15
|
+
email_prefix: "[Dummy ERROR] ",
|
16
16
|
sender_address: %("Dummy Notifier" <dummynotifier@example.com>),
|
17
17
|
exception_recipients: %w[dummyexceptions@example.com],
|
18
|
-
email_headers: {
|
18
|
+
email_headers: {"X-Custom-Header" => "foobar"},
|
19
19
|
sections: %w[new_section request session environment backtrace],
|
20
20
|
background_sections: %w[new_bkg_section backtrace data],
|
21
21
|
pre_callback: proc { |_opts, _notifier, _backtrace, _message, _message_opts| @pre_callback_called = true },
|
22
22
|
post_callback: proc { |_opts, _notifier, _backtrace, _message, _message_opts| @post_callback_called = true },
|
23
23
|
smtp_settings: {
|
24
|
-
user_name:
|
25
|
-
password:
|
24
|
+
user_name: "Dummy user_name",
|
25
|
+
password: "Dummy password"
|
26
26
|
}
|
27
27
|
)
|
28
28
|
|
29
29
|
@mail = @email_notifier.call(
|
30
30
|
@exception,
|
31
|
-
data: {
|
31
|
+
data: {job: "DivideWorkerJob", payload: "1/0", message: "My Custom Message"}
|
32
32
|
)
|
33
33
|
end
|
34
34
|
|
35
|
-
test
|
35
|
+
test "should call pre/post_callback if specified" do
|
36
36
|
assert @pre_callback_called
|
37
37
|
assert @post_callback_called
|
38
38
|
end
|
39
39
|
|
40
|
-
test
|
40
|
+
test "sends mail with correct content" do
|
41
41
|
assert_equal %("Dummy Notifier" <dummynotifier@example.com>), @mail[:from].value
|
42
42
|
assert_equal %w[dummyexceptions@example.com], @mail.to
|
43
43
|
assert_equal '[Dummy ERROR] (ZeroDivisionError) "divided by 0"', @mail.subject
|
44
|
-
assert_equal
|
45
|
-
assert_equal
|
44
|
+
assert_equal "foobar", @mail["X-Custom-Header"].value
|
45
|
+
assert_equal "text/plain; charset=UTF-8", @mail.content_type
|
46
46
|
assert_equal [], @mail.attachments
|
47
|
-
assert_equal
|
48
|
-
assert_equal
|
47
|
+
assert_equal "Dummy user_name", @mail.delivery_method.settings[:user_name]
|
48
|
+
assert_equal "Dummy password", @mail.delivery_method.settings[:password]
|
49
49
|
|
50
|
-
|
50
|
+
# standard:disable Lint/LiteralInInterpolation
|
51
|
+
body = <<~BODY
|
51
52
|
A ZeroDivisionError occurred in background at Sat, 20 Apr 2013 20:58:55 UTC +00:00 :
|
52
53
|
|
53
54
|
divided by 0
|
@@ -69,23 +70,24 @@ class EmailNotifierTest < ActiveSupport::TestCase
|
|
69
70
|
Data:
|
70
71
|
-------------------------------
|
71
72
|
|
72
|
-
* data: {:
|
73
|
+
* data: #{{job: "DivideWorkerJob", payload: "1/0", message: "My Custom Message"}}
|
73
74
|
|
74
75
|
|
75
76
|
BODY
|
77
|
+
# standard:enable Lint/LiteralInInterpolation
|
76
78
|
|
77
79
|
assert_equal body, @mail.decode_body
|
78
80
|
end
|
79
81
|
|
80
|
-
test
|
81
|
-
assert_equal
|
82
|
-
|
82
|
+
test "should normalize multiple digits into one N" do
|
83
|
+
assert_equal "N foo N bar N baz N",
|
84
|
+
ExceptionNotifier::EmailNotifier.normalize_digits("1 foo 12 bar 123 baz 1234")
|
83
85
|
end
|
84
86
|
|
85
87
|
test "mail should prefix exception class with 'an' instead of 'a' when it starts with a vowel" do
|
86
88
|
begin
|
87
89
|
raise ArgumentError
|
88
|
-
rescue
|
90
|
+
rescue => e
|
89
91
|
@vowel_exception = e
|
90
92
|
@vowel_mail = @email_notifier.call(@vowel_exception)
|
91
93
|
end
|
@@ -93,55 +95,55 @@ class EmailNotifierTest < ActiveSupport::TestCase
|
|
93
95
|
assert_includes @vowel_mail.encoded, "An ArgumentError occurred in background at #{Time.current}"
|
94
96
|
end
|
95
97
|
|
96
|
-
test
|
98
|
+
test "should not send notification if one of ignored exceptions" do
|
97
99
|
begin
|
98
100
|
raise AbstractController::ActionNotFound
|
99
|
-
rescue
|
101
|
+
rescue => e
|
100
102
|
@ignored_exception = e
|
101
103
|
unless ExceptionNotifier.ignored_exceptions.include?(@ignored_exception.class.name)
|
102
104
|
ignored_mail = @email_notifier.call(@ignored_exception)
|
103
105
|
end
|
104
106
|
end
|
105
107
|
|
106
|
-
assert_equal @ignored_exception.class.inspect,
|
108
|
+
assert_equal @ignored_exception.class.inspect, "AbstractController::ActionNotFound"
|
107
109
|
assert_nil ignored_mail
|
108
110
|
end
|
109
111
|
|
110
|
-
test
|
112
|
+
test "should encode environment strings" do
|
111
113
|
email_notifier = ExceptionNotifier::EmailNotifier.new(
|
112
|
-
sender_address:
|
114
|
+
sender_address: "<dummynotifier@example.com>",
|
113
115
|
exception_recipients: %w[dummyexceptions@example.com]
|
114
116
|
)
|
115
117
|
|
116
118
|
mail = email_notifier.call(
|
117
119
|
@exception,
|
118
120
|
env: {
|
119
|
-
|
120
|
-
|
121
|
-
|
121
|
+
"REQUEST_METHOD" => "GET",
|
122
|
+
"rack.input" => "",
|
123
|
+
"invalid_encoding" => "R\xC3\xA9sum\xC3\xA9".dup.force_encoding(Encoding::ASCII)
|
122
124
|
}
|
123
125
|
)
|
124
126
|
|
125
127
|
assert_match(/invalid_encoding\s+: R__sum__/, mail.encoded)
|
126
128
|
end
|
127
129
|
|
128
|
-
test
|
130
|
+
test "should send email using ActionMailer" do
|
129
131
|
ActionMailer::Base.deliveries.clear
|
130
132
|
@email_notifier.call(@exception)
|
131
133
|
assert_equal 1, ActionMailer::Base.deliveries.count
|
132
134
|
end
|
133
135
|
|
134
|
-
test
|
136
|
+
test "should be able to specify ActionMailer::MessageDelivery method" do
|
135
137
|
ActionMailer::Base.deliveries.clear
|
136
138
|
|
137
|
-
deliver_with = if ActionMailer.version < Gem::Version.new(
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
139
|
+
deliver_with = if ActionMailer.version < Gem::Version.new("4.2")
|
140
|
+
:deliver
|
141
|
+
else
|
142
|
+
:deliver_now
|
143
|
+
end
|
142
144
|
|
143
145
|
email_notifier = ExceptionNotifier::EmailNotifier.new(
|
144
|
-
email_prefix:
|
146
|
+
email_prefix: "[Dummy ERROR] ",
|
145
147
|
sender_address: %("Dummy Notifier" <dummynotifier@example.com>),
|
146
148
|
exception_recipients: %w[dummyexceptions@example.com],
|
147
149
|
deliver_with: deliver_with
|
@@ -152,10 +154,10 @@ class EmailNotifierTest < ActiveSupport::TestCase
|
|
152
154
|
assert_equal 1, ActionMailer::Base.deliveries.count
|
153
155
|
end
|
154
156
|
|
155
|
-
test
|
157
|
+
test "should lazily evaluate exception_recipients" do
|
156
158
|
exception_recipients = %w[first@example.com second@example.com]
|
157
159
|
email_notifier = ExceptionNotifier::EmailNotifier.new(
|
158
|
-
email_prefix:
|
160
|
+
email_prefix: "[Dummy ERROR] ",
|
159
161
|
sender_address: %("Dummy Notifier" <dummynotifier@example.com>),
|
160
162
|
exception_recipients: -> { [exception_recipients.shift] },
|
161
163
|
delivery_method: :test
|
@@ -167,19 +169,19 @@ class EmailNotifierTest < ActiveSupport::TestCase
|
|
167
169
|
assert_equal %w[second@example.com], mail.to
|
168
170
|
end
|
169
171
|
|
170
|
-
test
|
172
|
+
test "should prepend accumulated_errors_count in email subject if accumulated_errors_count larger than 1" do
|
171
173
|
email_notifier = ExceptionNotifier::EmailNotifier.new(
|
172
|
-
email_prefix:
|
174
|
+
email_prefix: "[Dummy ERROR] ",
|
173
175
|
sender_address: %("Dummy Notifier" <dummynotifier@example.com>),
|
174
176
|
exception_recipients: %w[dummyexceptions@example.com],
|
175
177
|
delivery_method: :test
|
176
178
|
)
|
177
179
|
|
178
180
|
mail = email_notifier.call(@exception, accumulated_errors_count: 3)
|
179
|
-
assert mail.subject.start_with?(
|
181
|
+
assert mail.subject.start_with?("[Dummy ERROR] (3 times) (ZeroDivisionError)")
|
180
182
|
end
|
181
183
|
|
182
|
-
test
|
184
|
+
test "should not include exception message in subject when verbose_subject: false" do
|
183
185
|
email_notifier = ExceptionNotifier::EmailNotifier.new(
|
184
186
|
sender_address: %("Dummy Notifier" <dummynotifier@example.com>),
|
185
187
|
exception_recipients: %w[dummyexceptions@example.com],
|
@@ -188,10 +190,10 @@ class EmailNotifierTest < ActiveSupport::TestCase
|
|
188
190
|
|
189
191
|
mail = email_notifier.call(@exception)
|
190
192
|
|
191
|
-
assert_equal
|
193
|
+
assert_equal "[ERROR] (ZeroDivisionError)", mail.subject
|
192
194
|
end
|
193
195
|
|
194
|
-
test
|
196
|
+
test "should send html email when selected html format" do
|
195
197
|
email_notifier = ExceptionNotifier::EmailNotifier.new(
|
196
198
|
sender_address: %("Dummy Notifier" <dummynotifier@example.com>),
|
197
199
|
exception_recipients: %w[dummyexceptions@example.com],
|
@@ -206,20 +208,21 @@ end
|
|
206
208
|
|
207
209
|
class EmailNotifierWithEnvTest < ActiveSupport::TestCase
|
208
210
|
class HomeController < ActionController::Metal
|
209
|
-
def index
|
211
|
+
def index
|
212
|
+
end
|
210
213
|
end
|
211
214
|
|
212
215
|
setup do
|
213
|
-
Time.stubs(:current).returns(
|
216
|
+
Time.stubs(:current).returns("Sat, 20 Apr 2013 20:58:55 UTC +00:00")
|
214
217
|
|
215
|
-
@exception = ZeroDivisionError.new(
|
216
|
-
@exception.set_backtrace([
|
218
|
+
@exception = ZeroDivisionError.new("divided by 0")
|
219
|
+
@exception.set_backtrace(["test/exception_notifier/email_notifier_test.rb:20"])
|
217
220
|
|
218
221
|
@email_notifier = ExceptionNotifier::EmailNotifier.new(
|
219
|
-
email_prefix:
|
222
|
+
email_prefix: "[Dummy ERROR] ",
|
220
223
|
sender_address: %("Dummy Notifier" <dummynotifier@example.com>),
|
221
224
|
exception_recipients: %w[dummyexceptions@example.com],
|
222
|
-
email_headers: {
|
225
|
+
email_headers: {"X-Custom-Header" => "foobar"},
|
223
226
|
sections: %w[new_section request session environment backtrace],
|
224
227
|
background_sections: %w[new_bkg_section backtrace data],
|
225
228
|
pre_callback:
|
@@ -232,29 +235,32 @@ class EmailNotifierWithEnvTest < ActiveSupport::TestCase
|
|
232
235
|
@controller.process(:index)
|
233
236
|
|
234
237
|
@test_env = Rack::MockRequest.env_for(
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
params
|
238
|
+
"/",
|
239
|
+
"HTTP_HOST" => "test.address",
|
240
|
+
"REMOTE_ADDR" => "127.0.0.1",
|
241
|
+
"HTTP_USER_AGENT" => "Rails Testing",
|
242
|
+
"action_dispatch.parameter_filter" => ["secret"],
|
243
|
+
"HTTPS" => "on",
|
244
|
+
"action_controller.instance" => @controller,
|
245
|
+
"rack.session.options" => {},
|
246
|
+
:params => {id: "foo", secret: "secret"}
|
244
247
|
)
|
245
248
|
|
246
|
-
@mail = @email_notifier.call(@exception, env: @test_env, data: {
|
249
|
+
@mail = @email_notifier.call(@exception, env: @test_env, data: {message: "My Custom Message"})
|
247
250
|
end
|
248
251
|
|
249
|
-
test
|
252
|
+
test "sends mail with correct content" do
|
250
253
|
assert_equal %("Dummy Notifier" <dummynotifier@example.com>), @mail[:from].value
|
251
254
|
assert_equal %w[dummyexceptions@example.com], @mail.to
|
252
255
|
assert_equal '[Dummy ERROR] home#index (ZeroDivisionError) "divided by 0"', @mail.subject
|
253
|
-
assert_equal
|
254
|
-
assert_equal
|
256
|
+
assert_equal "foobar", @mail["X-Custom-Header"].value
|
257
|
+
assert_equal "text/plain; charset=UTF-8", @mail.content_type
|
255
258
|
assert_equal [], @mail.attachments
|
256
259
|
|
257
|
-
|
260
|
+
body_fragments = []
|
261
|
+
|
262
|
+
# standard:disable Lint/LiteralInInterpolation
|
263
|
+
body_fragments << <<~BODY
|
258
264
|
A ZeroDivisionError occurred in home#index:
|
259
265
|
|
260
266
|
divided by 0
|
@@ -274,14 +280,14 @@ class EmailNotifierWithEnvTest < ActiveSupport::TestCase
|
|
274
280
|
* URL : https://test.address/?id=foo&secret=secret
|
275
281
|
* HTTP Method: GET
|
276
282
|
* IP address : 127.0.0.1
|
277
|
-
* Parameters : {
|
283
|
+
* Parameters : #{{"id" => "foo", "secret" => "[FILTERED]"}}
|
278
284
|
* Timestamp : Sat, 20 Apr 2013 20:58:55 UTC +00:00
|
279
285
|
* Server : #{Socket.gethostname}
|
280
286
|
BODY
|
281
287
|
|
282
|
-
|
288
|
+
body_fragments << " * Rails root : #{Rails.root}\n" if defined?(Rails) && Rails.respond_to?(:root)
|
283
289
|
|
284
|
-
|
290
|
+
body_fragments << <<~BODY
|
285
291
|
* Process: #{Process.pid}
|
286
292
|
|
287
293
|
-------------------------------
|
@@ -295,30 +301,13 @@ class EmailNotifierWithEnvTest < ActiveSupport::TestCase
|
|
295
301
|
Environment:
|
296
302
|
-------------------------------
|
297
303
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
* REMOTE_ADDR : 127.0.0.1
|
304
|
-
* REQUEST_METHOD : GET
|
305
|
-
* SCRIPT_NAME :
|
306
|
-
* SERVER_NAME : example.org
|
307
|
-
* SERVER_PORT : 80
|
308
|
-
* SERVER_PROTOCOL : HTTP/1.1
|
309
|
-
* action_controller.instance : #{@controller}
|
310
|
-
* action_dispatch.parameter_filter : [\"secret\"]
|
311
|
-
* action_dispatch.request.parameters : {"id"=>"foo", "secret"=>"[FILTERED]"}
|
312
|
-
* action_dispatch.request.path_parameters : {}
|
313
|
-
* action_dispatch.request.query_parameters : {"id"=>"foo", "secret"=>"[FILTERED]"}
|
314
|
-
* action_dispatch.request.request_parameters: {}
|
315
|
-
* rack.errors : #{@test_env['rack.errors']}
|
316
|
-
* rack.request.form_hash : {}
|
317
|
-
* rack.request.form_input :
|
318
|
-
* rack.session : #{@test_env['rack.session']}
|
319
|
-
* rack.session.options : #{@test_env['rack.session.options']}
|
320
|
-
* rack.url_scheme : http
|
304
|
+
BODY
|
305
|
+
|
306
|
+
body_fragments << "* action_controller.instance"
|
307
|
+
body_fragments << "* rack.errors"
|
308
|
+
body_fragments << "[FILTERED]"
|
321
309
|
|
310
|
+
body_fragments << <<~BODY
|
322
311
|
-------------------------------
|
323
312
|
Backtrace:
|
324
313
|
-------------------------------
|
@@ -329,15 +318,17 @@ class EmailNotifierWithEnvTest < ActiveSupport::TestCase
|
|
329
318
|
Data:
|
330
319
|
-------------------------------
|
331
320
|
|
332
|
-
* data: {:
|
321
|
+
* data: #{{message: "My Custom Message"}}
|
333
322
|
|
334
323
|
|
335
324
|
BODY
|
336
|
-
|
337
|
-
|
325
|
+
# standard:enable Lint/LiteralInInterpolation
|
326
|
+
body_fragments.each do |fragment|
|
327
|
+
assert_includes @mail.decode_body, fragment
|
328
|
+
end
|
338
329
|
end
|
339
330
|
|
340
|
-
test
|
331
|
+
test "should not include controller and action names in subject" do
|
341
332
|
email_notifier = ExceptionNotifier::EmailNotifier.new(
|
342
333
|
sender_address: %("Dummy Notifier" <dummynotifier@example.com>),
|
343
334
|
exception_recipients: %w[dummyexceptions@example.com],
|
@@ -346,6 +337,6 @@ class EmailNotifierWithEnvTest < ActiveSupport::TestCase
|
|
346
337
|
|
347
338
|
mail = email_notifier.call(@exception, env: @test_env)
|
348
339
|
|
349
|
-
assert_equal
|
340
|
+
assert_equal "[ERROR] (ZeroDivisionError) \"divided by 0\"", mail.subject
|
350
341
|
end
|
351
342
|
end
|
@@ -1,130 +1,130 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "test_helper"
|
4
|
+
require "rack"
|
5
|
+
require "httparty"
|
6
|
+
require "timecop"
|
7
|
+
require "json"
|
8
8
|
|
9
9
|
class GoogleChatNotifierTest < ActiveSupport::TestCase
|
10
|
-
URL =
|
10
|
+
URL = "http://localhost:8000"
|
11
11
|
|
12
12
|
def setup
|
13
|
-
Timecop.freeze(
|
13
|
+
Timecop.freeze("2018-12-09 12:07:16 UTC")
|
14
14
|
end
|
15
15
|
|
16
16
|
def teardown
|
17
17
|
Timecop.return
|
18
18
|
end
|
19
19
|
|
20
|
-
test
|
21
|
-
HTTParty.expects(:post).with(URL, post_opts("#{header}\n#{body}"))
|
22
|
-
notifier.call ArgumentError.new(
|
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
23
|
end
|
24
24
|
|
25
|
-
test
|
25
|
+
test "shoud use errors count if accumulated_errors_count is provided" do
|
26
26
|
text = [
|
27
|
-
|
27
|
+
"",
|
28
28
|
"Application: *#{app_name}*",
|
29
|
-
|
30
|
-
|
29
|
+
"5 *ArgumentError* occurred.",
|
30
|
+
"",
|
31
31
|
body
|
32
32
|
].join("\n")
|
33
33
|
|
34
|
-
HTTParty.expects(:post).with(URL, post_opts(text))
|
34
|
+
HTTParty.expects(:post).with(URL, **post_opts(text))
|
35
35
|
|
36
|
-
notifier.call(ArgumentError.new(
|
36
|
+
notifier.call(ArgumentError.new("foo"), accumulated_errors_count: 5)
|
37
37
|
end
|
38
38
|
|
39
|
-
test
|
39
|
+
test "Message request should be formatted as hash" do
|
40
40
|
text = [
|
41
41
|
header,
|
42
42
|
body,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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"}}", # standard:disable Lint/LiteralInInterpolation:
|
50
|
+
"* timestamp : 2018-12-09 12:07:16 UTC",
|
51
|
+
"```"
|
52
52
|
].join("\n")
|
53
53
|
|
54
|
-
HTTParty.expects(:post).with(URL, post_opts(text))
|
54
|
+
HTTParty.expects(:post).with(URL, **post_opts(text))
|
55
55
|
|
56
|
-
notifier.call(ArgumentError.new(
|
56
|
+
notifier.call(ArgumentError.new("foo"), env: test_env)
|
57
57
|
end
|
58
58
|
|
59
|
-
test
|
59
|
+
test "backtrace with less than 3 lines should be displayed fully" do
|
60
60
|
text = [
|
61
61
|
header,
|
62
62
|
body,
|
63
|
-
|
63
|
+
"",
|
64
64
|
backtrace
|
65
65
|
].join("\n")
|
66
66
|
|
67
|
-
HTTParty.expects(:post).with(URL, post_opts(text))
|
67
|
+
HTTParty.expects(:post).with(URL, **post_opts(text))
|
68
68
|
|
69
|
-
exception = ArgumentError.new(
|
69
|
+
exception = ArgumentError.new("foo")
|
70
70
|
exception.set_backtrace([
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
"app/controllers/my_controller.rb:53:in `my_controller_params'",
|
72
|
+
"app/controllers/my_controller.rb:34:in `update'"
|
73
|
+
])
|
74
74
|
|
75
75
|
notifier.call(exception)
|
76
76
|
end
|
77
77
|
|
78
|
-
test
|
78
|
+
test "backtrace with more than 3 lines should display only top 3 lines" do
|
79
79
|
text = [
|
80
80
|
header,
|
81
81
|
body,
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
"",
|
83
|
+
"*Backtrace:*",
|
84
|
+
"```",
|
85
85
|
"* app/controllers/my_controller.rb:99:in `specific_function'",
|
86
86
|
"* app/controllers/my_controller.rb:70:in `specific_param'",
|
87
87
|
"* app/controllers/my_controller.rb:53:in `my_controller_params'",
|
88
|
-
|
88
|
+
"```"
|
89
89
|
].join("\n")
|
90
90
|
|
91
|
-
HTTParty.expects(:post).with(URL, post_opts(text))
|
91
|
+
HTTParty.expects(:post).with(URL, **post_opts(text))
|
92
92
|
|
93
|
-
exception = ArgumentError.new(
|
93
|
+
exception = ArgumentError.new("foo")
|
94
94
|
exception.set_backtrace([
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
100
|
|
101
101
|
notifier.call(exception)
|
102
102
|
end
|
103
103
|
|
104
|
-
test
|
104
|
+
test "Get text with backtrace and request info" do
|
105
105
|
text = [
|
106
106
|
header,
|
107
107
|
body,
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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"}}", # standard:disable Lint/LiteralInInterpolation:
|
115
|
+
"* timestamp : 2018-12-09 12:07:16 UTC",
|
116
|
+
"```",
|
117
|
+
"",
|
118
118
|
backtrace
|
119
119
|
].join("\n")
|
120
120
|
|
121
|
-
HTTParty.expects(:post).with(URL, post_opts(text))
|
121
|
+
HTTParty.expects(:post).with(URL, **post_opts(text))
|
122
122
|
|
123
|
-
exception = ArgumentError.new(
|
123
|
+
exception = ArgumentError.new("foo")
|
124
124
|
exception.set_backtrace([
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
"app/controllers/my_controller.rb:53:in `my_controller_params'",
|
126
|
+
"app/controllers/my_controller.rb:34:in `update'"
|
127
|
+
])
|
128
128
|
|
129
129
|
notifier.call(exception, env: test_env)
|
130
130
|
end
|
@@ -137,27 +137,27 @@ class GoogleChatNotifierTest < ActiveSupport::TestCase
|
|
137
137
|
|
138
138
|
def post_opts(text)
|
139
139
|
{
|
140
|
-
body: {
|
141
|
-
headers: {
|
140
|
+
body: {text: text}.to_json,
|
141
|
+
headers: {"Content-Type" => "application/json"}
|
142
142
|
}
|
143
143
|
end
|
144
144
|
|
145
145
|
def test_env
|
146
146
|
Rack::MockRequest.env_for(
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
params
|
147
|
+
"/",
|
148
|
+
"HTTP_HOST" => "test.address",
|
149
|
+
"REMOTE_ADDR" => "127.0.0.1",
|
150
|
+
"HTTP_USER_AGENT" => "Rails Testing",
|
151
|
+
:params => {id: "foo"}
|
152
152
|
)
|
153
153
|
end
|
154
154
|
|
155
155
|
def header
|
156
156
|
[
|
157
|
-
|
157
|
+
"",
|
158
158
|
"Application: *#{app_name}*",
|
159
|
-
|
160
|
-
|
159
|
+
"An *ArgumentError* occurred.",
|
160
|
+
""
|
161
161
|
].join("\n")
|
162
162
|
end
|
163
163
|
|
@@ -170,16 +170,16 @@ class GoogleChatNotifierTest < ActiveSupport::TestCase
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def app_name
|
173
|
-
|
173
|
+
"dummy" if defined?(::Rails) && ::Rails.respond_to?(:application)
|
174
174
|
end
|
175
175
|
|
176
176
|
def backtrace
|
177
177
|
[
|
178
|
-
|
179
|
-
|
178
|
+
"*Backtrace:*",
|
179
|
+
"```",
|
180
180
|
"* app/controllers/my_controller.rb:53:in `my_controller_params'",
|
181
181
|
"* app/controllers/my_controller.rb:34:in `update'",
|
182
|
-
|
182
|
+
"```"
|
183
183
|
]
|
184
184
|
end
|
185
185
|
end
|