exception_handling 2.13.0 → 3.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -3
  3. data/.ruby-version +1 -1
  4. data/Gemfile +16 -16
  5. data/Gemfile.lock +114 -110
  6. data/README.md +3 -7
  7. data/Rakefile +11 -8
  8. data/exception_handling.gemspec +10 -12
  9. data/lib/exception_handling/exception_info.rb +10 -13
  10. data/lib/exception_handling/honeybadger_callbacks.rb +59 -0
  11. data/lib/exception_handling/log_stub_error.rb +1 -2
  12. data/lib/exception_handling/methods.rb +53 -6
  13. data/lib/exception_handling/testing.rb +10 -20
  14. data/lib/exception_handling/version.rb +1 -1
  15. data/lib/exception_handling.rb +33 -68
  16. data/semaphore_ci/setup.sh +3 -0
  17. data/{spec → test}/helpers/controller_helpers.rb +0 -0
  18. data/{spec → test}/helpers/exception_helpers.rb +2 -2
  19. data/{spec/spec_helper.rb → test/test_helper.rb} +42 -63
  20. data/test/unit/exception_handling/exception_catalog_test.rb +85 -0
  21. data/test/unit/exception_handling/exception_description_test.rb +82 -0
  22. data/{spec/unit/exception_handling/exception_info_spec.rb → test/unit/exception_handling/exception_info_test.rb} +114 -153
  23. data/test/unit/exception_handling/honeybadger_callbacks_test.rb +122 -0
  24. data/{spec/unit/exception_handling/log_error_stub_spec.rb → test/unit/exception_handling/log_error_stub_test.rb} +22 -38
  25. data/{spec/unit/exception_handling/mailer_spec.rb → test/unit/exception_handling/mailer_test.rb} +18 -17
  26. data/test/unit/exception_handling/methods_test.rb +84 -0
  27. data/test/unit/exception_handling/sensu_test.rb +52 -0
  28. data/test/unit/exception_handling_test.rb +1109 -0
  29. metadata +60 -115
  30. data/.github/workflows/pipeline.yml +0 -33
  31. data/.rspec +0 -3
  32. data/Appraisals +0 -13
  33. data/CHANGELOG.md +0 -119
  34. data/gemfiles/rails_5.gemfile +0 -18
  35. data/gemfiles/rails_6.gemfile +0 -18
  36. data/lib/exception_handling/escalate_callback.rb +0 -19
  37. data/lib/exception_handling/logging_methods.rb +0 -27
  38. data/spec/rake_test_warning_false.rb +0 -20
  39. data/spec/unit/exception_handling/escalate_callback_spec.rb +0 -81
  40. data/spec/unit/exception_handling/exception_catalog_spec.rb +0 -85
  41. data/spec/unit/exception_handling/exception_description_spec.rb +0 -82
  42. data/spec/unit/exception_handling/logging_methods_spec.rb +0 -38
  43. data/spec/unit/exception_handling/methods_spec.rb +0 -105
  44. data/spec/unit/exception_handling/sensu_spec.rb +0 -51
  45. data/spec/unit/exception_handling_spec.rb +0 -1303
@@ -1,58 +1,58 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../spec_helper', __dir__)
3
+ require File.expand_path('../../test_helper', __dir__)
4
4
  require_test_helper 'controller_helpers'
5
5
  require_test_helper 'exception_helpers'
6
6
 
7
7
  module ExceptionHandling
8
- describe ExceptionInfo do
8
+ class ExceptionInfoTest < ActiveSupport::TestCase
9
9
  include ControllerHelpers
10
10
  include ExceptionHelpers
11
11
 
12
12
  context "initialize" do
13
- before do
13
+ setup do
14
14
  @exception = StandardError.new("something went wrong")
15
15
  @timestamp = Time.now
16
16
  @controller = Object.new
17
17
  end
18
18
 
19
19
  context "controller_from_context" do
20
- it "extract controller from context when not specified explicitly" do
20
+ should "extract controller from context when not specified explicitly" do
21
21
  exception_context = {
22
22
  "action_controller.instance" => @controller
23
23
  }
24
24
  exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp)
25
- expect(exception_info.controller).to eq(@controller)
25
+ assert_equal @controller, exception_info.controller
26
26
  end
27
27
 
28
- it "prefer the explicit controller over the one from context" do
28
+ should "prefer the explicit controller over the one from context" do
29
29
  exception_context = {
30
30
  "action_controller.instance" => Object.new
31
31
  }
32
- exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp, controller: @controller)
33
- expect(exception_info.controller).to eq(@controller)
34
- expect(exception_info.controller).not_to eq(exception_context["action_controller.instance"])
32
+ exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp, @controller)
33
+ assert_equal @controller, exception_info.controller
34
+ assert_not_equal exception_context["action_controller.instance"], exception_info.controller
35
35
  end
36
36
 
37
- it "leave controller unset when not included in the context hash" do
37
+ should "leave controller unset when not included in the context hash" do
38
38
  exception_info = ExceptionInfo.new(@exception, {}, @timestamp)
39
- expect(exception_info.controller).to be_nil
39
+ assert_nil exception_info.controller
40
40
  end
41
41
 
42
- it "leave controller unset when context is not in hash format" do
42
+ should "leave controller unset when context is not in hash format" do
43
43
  exception_info = ExceptionInfo.new(@exception, "string context", @timestamp)
44
- expect(exception_info.controller).to be_nil
44
+ assert_nil exception_info.controller
45
45
  end
46
46
  end
47
47
  end
48
48
 
49
49
  context "data" do
50
- before do
50
+ setup do
51
51
  @exception = StandardError.new("something went wrong")
52
52
  @timestamp = Time.now
53
53
  end
54
54
 
55
- it "return a hash with exception specific data including context hash" do
55
+ should "return a hash with exception specific data including context hash" do
56
56
  exception_context = {
57
57
  "rack.session" => {
58
58
  user_id: 23,
@@ -73,17 +73,17 @@ module ExceptionHandling
73
73
  }
74
74
  }
75
75
 
76
- expect(exception_info.data).to eq(expected_data)
76
+ assert_equal_with_diff expected_data, exception_info.data
77
77
  end
78
78
 
79
- it "generate exception data appropriately if exception message is nil" do
79
+ should "generate exception data appropriately if exception message is nil" do
80
80
  exception_info = ExceptionInfo.new(exception_with_nil_message, "custom context data", @timestamp)
81
81
  exception_data = exception_info.data
82
- expect(exception_data["error_string"]).to eq("RuntimeError: ")
83
- expect(exception_data["error"]).to eq("RuntimeError: : custom context data")
82
+ assert_equal "RuntimeError: ", exception_data["error_string"]
83
+ assert_equal "RuntimeError: : custom context data", exception_data["error"]
84
84
  end
85
85
 
86
- it "return a hash with exception specific data including context string" do
86
+ should "return a hash with exception specific data including context string" do
87
87
  exception_context = "custom context data"
88
88
  exception_info = ExceptionInfo.new(@exception, exception_context, @timestamp)
89
89
  expected_data = {
@@ -96,20 +96,21 @@ module ExceptionHandling
96
96
  "message" => "custom context data"
97
97
  }
98
98
  }
99
- expect(exception_info.data).to eq(expected_data)
99
+
100
+ assert_equal_with_diff expected_data, exception_info.data
100
101
  end
101
102
 
102
- it "not include enhanced data from controller or custom data callback" do
103
+ should "not include enhanced data from controller or custom data callback" do
103
104
  env = { server: "fe98" }
104
105
  parameters = { advertiser_id: 435 }
105
106
  session = { username: "jsmith" }
106
107
  request_uri = "host/path"
107
108
  controller = create_dummy_controller(env, parameters, session, request_uri)
108
109
  data_callback = ->(data) { data[:custom_section] = "value" }
109
- exception_info = ExceptionInfo.new(@exception, "custom context data", @timestamp, controller: controller, data_callback: data_callback)
110
+ exception_info = ExceptionInfo.new(@exception, "custom context data", @timestamp, controller, data_callback)
110
111
 
111
- expect(exception_info).to_not receive(:extract_and_merge_controller_data)
112
- expect(exception_info).to_not receive(:customize_from_data_callback)
112
+ dont_allow(exception_info).extract_and_merge_controller_data
113
+ dont_allow(exception_info).customize_from_data_callback
113
114
  expected_data = {
114
115
  "error_class" => "StandardError",
115
116
  "error_string" => "StandardError: something went wrong",
@@ -121,12 +122,12 @@ module ExceptionHandling
121
122
  }
122
123
  }
123
124
 
124
- expect(exception_info.data).to eq(expected_data)
125
+ assert_equal_with_diff expected_data, exception_info.data
125
126
  end
126
127
  end
127
128
 
128
129
  context "enhanced_data" do
129
- before do
130
+ setup do
130
131
  @exception = StandardError.new("something went wrong")
131
132
  @timestamp = Time.now
132
133
  @exception_context = {
@@ -144,13 +145,13 @@ module ExceptionHandling
144
145
  @data_callback = ->(data) { data[:custom_section] = "check this out" }
145
146
  end
146
147
 
147
- it "not return a mutable object for the session" do
148
+ should "not return a mutable object for the session" do
148
149
  exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
149
150
  exception_info.enhanced_data["session"]["hello"] = "world"
150
- expect(@controller.session["hello"]).to be_nil
151
+ assert_nil @controller.session["hello"]
151
152
  end
152
153
 
153
- it "return a hash with generic exception attributes as well as context data" do
154
+ should "return a hash with generic exception attributes as well as context data" do
154
155
  exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
155
156
  expected_data = {
156
157
  "error_class" => "StandardError",
@@ -163,20 +164,20 @@ module ExceptionHandling
163
164
  "location" => { "file" => "<no backtrace>", "line" => nil }
164
165
  }
165
166
 
166
- expect(prepare_data(exception_info.enhanced_data)).to eq(expected_data)
167
+ assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
167
168
  end
168
169
 
169
- it "generate exception data appropriately if exception message is nil" do
170
+ should "generate exception data appropriately if exception message is nil" do
170
171
  exception_with_nil_message = RuntimeError.new(nil)
171
- allow(exception_with_nil_message).to receive(:message).and_return(nil)
172
+ stub(exception_with_nil_message).message { nil }
172
173
  exception_info = ExceptionInfo.new(exception_with_nil_message, @exception_context, @timestamp)
173
174
  exception_data = exception_info.enhanced_data
174
- expect(exception_data["error_string"]).to eq("RuntimeError: ")
175
- expect(exception_data["error"]).to eq("RuntimeError: ")
175
+ assert_equal "RuntimeError: ", exception_data["error_string"]
176
+ assert_equal "RuntimeError: ", exception_data["error"]
176
177
  end
177
178
 
178
- it "include controller data when available" do
179
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: @controller)
179
+ should "include controller data when available" do
180
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, @controller)
180
181
  expected_data = {
181
182
  "error_class" => "StandardError",
182
183
  "error_string" => "StandardError: something went wrong",
@@ -193,10 +194,10 @@ module ExceptionHandling
193
194
  "location" => { "controller" => "dummy", "action" => "fail", "file" => "<no backtrace>", "line" => nil }
194
195
  }
195
196
 
196
- expect(prepare_data(exception_info.enhanced_data)).to eq(expected_data)
197
+ assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
197
198
  end
198
199
 
199
- it "extract controller from rack specific exception context when not provided explicitly" do
200
+ should "extract controller from rack specific exception context when not provided explicitly" do
200
201
  @exception_context["action_controller.instance"] = @controller
201
202
  exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
202
203
  expected_data = {
@@ -215,11 +216,11 @@ module ExceptionHandling
215
216
  "location" => { "controller" => "dummy", "action" => "fail", "file" => "<no backtrace>", "line" => nil }
216
217
  }
217
218
 
218
- expect(prepare_data(exception_info.enhanced_data)).to eq(expected_data)
219
+ assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
219
220
  end
220
221
 
221
- it "add to_s attribute to specific sections that have their content in hash format" do
222
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: @controller)
222
+ should "add to_s attribute to specific sections that have their content in hash format" do
223
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, @controller)
223
224
  expected_data = {
224
225
  "error_class" => "StandardError",
225
226
  "error_string" => "StandardError: something went wrong",
@@ -244,13 +245,13 @@ module ExceptionHandling
244
245
  "location" => { "controller" => "dummy", "action" => "fail", "file" => "<no backtrace>", "line" => nil }
245
246
  }
246
247
 
247
- expect(exception_info.enhanced_data).to eq(expected_data)
248
+ assert_equal_with_diff expected_data, exception_info.enhanced_data
248
249
  end
249
250
 
250
- it "filter out sensitive parameters like passwords" do
251
+ should "filter out sensitive parameters like passwords" do
251
252
  @controller.request.parameters[:password] = "super_secret"
252
253
  @controller.request.parameters[:user] = { "password" => "also super secret", "password_confirmation" => "also super secret" }
253
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: @controller)
254
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, @controller)
254
255
  expected_params = {
255
256
  "password" => "[FILTERED]",
256
257
  "advertiser_id" => 435, "controller" => "dummy",
@@ -260,11 +261,11 @@ module ExceptionHandling
260
261
  "password_confirmation" => "[FILTERED]"
261
262
  }
262
263
  }
263
- expect(exception_info.enhanced_data["request"]["params"]).to eq(expected_params)
264
+ assert_equal_with_diff expected_params, exception_info.enhanced_data["request"]["params"]
264
265
  end
265
266
 
266
- it "include the changes from the custom data callback" do
267
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: nil, data_callback: @data_callback)
267
+ should "include the changes from the custom data callback" do
268
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, nil, @data_callback)
268
269
  expected_data = {
269
270
  "error_class" => "StandardError",
270
271
  "error_string" => "StandardError: something went wrong",
@@ -277,11 +278,11 @@ module ExceptionHandling
277
278
  "location" => { "file" => "<no backtrace>", "line" => nil }
278
279
  }
279
280
 
280
- expect(prepare_data(exception_info.enhanced_data)).to eq(expected_data)
281
+ assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
281
282
  end
282
283
 
283
- it "apply the custom_data_hook results" do
284
- allow(ExceptionHandling).to receive(:custom_data_hook).and_return(->(data) { data[:custom_hook] = "changes from custom hook" })
284
+ should "apply the custom_data_hook results" do
285
+ stub(ExceptionHandling).custom_data_hook { ->(data) { data[:custom_hook] = "changes from custom hook" } }
285
286
  exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
286
287
  expected_data = {
287
288
  "error_class" => "StandardError",
@@ -295,61 +296,61 @@ module ExceptionHandling
295
296
  "location" => { "file" => "<no backtrace>", "line" => nil }
296
297
  }
297
298
 
298
- expect(prepare_data(exception_info.enhanced_data)).to eq(expected_data)
299
+ assert_equal_with_diff expected_data, prepare_data(exception_info.enhanced_data)
299
300
  end
300
301
 
301
- it "log info if the custom data hook results in a nil message exception" do
302
+ should "log info if the custom data hook results in a nil message exception" do
302
303
  ExceptionHandling.custom_data_hook = ->(_data) do
303
304
  raise_exception_with_nil_message
304
305
  end
305
306
  log_info_messages = []
306
- allow(ExceptionHandling.logger).to receive(:info).with(any_args) do |message, _|
307
+ stub(ExceptionHandling.logger).info.with_any_args do |message, _|
307
308
  log_info_messages << message
308
309
  end
309
310
 
310
311
  exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
311
312
  exception_info.enhanced_data
312
- expect(log_info_messages.find { |message| message =~ /Unable to execute custom custom_data_hook callback/ }).to be_truthy
313
+ assert log_info_messages.find { |message| message =~ /Unable to execute custom custom_data_hook callback/ }
313
314
  ExceptionHandling.custom_data_hook = nil
314
315
  end
315
316
  end
316
317
 
317
318
  context "exception_description" do
318
- it "return the exception description from the global exception filter list" do
319
+ should "return the exception description from the global exception filter list" do
319
320
  exception = StandardError.new("No route matches")
320
321
  exception_info = ExceptionInfo.new(exception, {}, Time.now)
321
322
  description = exception_info.exception_description
322
- expect(description).to_not be_nil
323
- expect(description.filter_name).to eq(:NoRoute)
323
+ assert_not_nil description
324
+ assert_equal :NoRoute, description.filter_name
324
325
  end
325
326
 
326
- it "find the description when filter criteria includes section in hash format" do
327
+ should "find the description when filter criteria includes section in hash format" do
327
328
  env = { server: "fe98" }
328
329
  parameters = { advertiser_id: 435, controller: "sessions", action: "fail" }
329
330
  session = { username: "jsmith", id: "session_key" }
330
331
  request_uri = "host/path"
331
332
  controller = create_dummy_controller(env, parameters, session, request_uri)
332
333
  exception = StandardError.new("Request to click domain rejected")
333
- exception_info = ExceptionInfo.new(exception, nil, Time.now, controller: controller)
334
- expect(exception_info.enhanced_data[:request].is_a?(Hash)).to eq(true)
334
+ exception_info = ExceptionInfo.new(exception, {}, Time.now, controller)
335
+ assert_equal true, exception_info.enhanced_data[:request].is_a?(Hash)
335
336
  description = exception_info.exception_description
336
- expect(description).to_not be_nil
337
- expect(description.filter_name).to eq(:"Click Request Rejected")
337
+ assert_not_nil description
338
+ assert_equal :"Click Request Rejected", description.filter_name
338
339
  end
339
340
 
340
- it "return same description object for related errors (avoid reloading exception catalog from disk)" do
341
+ should "return same description object for related errors (avoid reloading exception catalog from disk)" do
341
342
  exception = StandardError.new("No route matches")
342
- exception_info = ExceptionInfo.new(exception, nil, Time.now)
343
+ exception_info = ExceptionInfo.new(exception, {}, Time.now)
343
344
  description = exception_info.exception_description
344
345
 
345
346
  repeat_ex = StandardError.new("No route matches 2")
346
- repeat_ex_info = ExceptionInfo.new(repeat_ex, nil, Time.now)
347
- expect(repeat_ex_info.exception_description.object_id).to eq(description.object_id)
347
+ repeat_ex_info = ExceptionInfo.new(repeat_ex, {}, Time.now)
348
+ assert_equal description.object_id, repeat_ex_info.exception_description.object_id
348
349
  end
349
350
  end
350
351
 
351
352
  context "controller_name" do
352
- before do
353
+ setup do
353
354
  @exception = StandardError.new('something went wrong')
354
355
  @timestamp = Time.now
355
356
  @exception_context = {
@@ -361,113 +362,73 @@ module ExceptionHandling
361
362
  }
362
363
  end
363
364
 
364
- it "returns honeybadger_grouping from the log context" do
365
- allow(ExceptionHandling.logger).to receive(:current_context_for_thread).and_return({ honeybadger_grouping: 'Group 1' })
366
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
367
-
368
- expect(exception_info.controller_name).to eq('Group 1')
369
- end
370
-
371
- it "returns honeybadger_grouping from log context even if controller is defined" do
372
- allow(ExceptionHandling.logger).to receive(:current_context_for_thread).and_return({ honeybadger_grouping: 'Group 1' })
373
-
374
- env = { server: 'fe98' }
375
- parameters = { controller: 'some_controller' }
376
- session = { username: 'smith' }
377
- request_uri = "host/path"
378
- controller = create_dummy_controller(env, parameters, session, request_uri)
379
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: controller)
380
-
381
- expect(exception_info.controller_name).to eq('Group 1')
382
- end
383
-
384
- it "return controller_name when controller is present" do
365
+ should "return controller_name when controller is present" do
385
366
  env = { server: 'fe98' }
386
367
  parameters = { controller: 'some_controller' }
387
368
  session = { username: 'smith' }
388
369
  request_uri = "host/path"
389
370
  controller = create_dummy_controller(env, parameters, session, request_uri)
390
- exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller: controller)
371
+ exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp, controller)
391
372
 
392
- expect(exception_info.controller_name).to eq('some_controller')
373
+ assert_equal 'some_controller', exception_info.controller_name
393
374
  end
394
375
 
395
- it "return an empty string when controller is not present" do
376
+ should "return an empty string when controller is not present" do
396
377
  exception_info = ExceptionInfo.new(@exception, @exception_context, @timestamp)
397
378
 
398
- expect(exception_info.controller_name).to eq('')
379
+ assert_equal '', exception_info.controller_name
399
380
  end
400
381
  end
401
382
 
402
383
  context "send_to_honeybadger?" do
403
- it "be enabled when Honeybadger is defined and exception is not in the filter list" do
404
- allow(ExceptionHandling).to receive(:honeybadger_defined?).and_return(true)
384
+ should "be enabled when Honeybadger is defined and exception is not in the filter list" do
385
+ stub(ExceptionHandling).honeybadger_defined? { true }
405
386
  exception = StandardError.new("something went wrong")
406
- exception_info = ExceptionInfo.new(exception, nil, Time.now)
407
- expect(exception_info.exception_description).to be_nil
408
- expect(exception_info.send_to_honeybadger?).to eq(true)
387
+ exception_info = ExceptionInfo.new(exception, {}, Time.now)
388
+ assert_nil exception_info.exception_description
389
+ assert_equal true, exception_info.send_to_honeybadger?
409
390
  end
410
391
 
411
- it "be enabled when Honeybadger is defined and exception is on the filter list with the flag turned on" do
412
- allow(ExceptionHandling).to receive(:honeybadger_defined?).and_return(true)
392
+ should "be enabled when Honeybadger is defined and exception is on the filter list with the flag turned on" do
393
+ stub(ExceptionHandling).honeybadger_defined? { true }
413
394
  exception = StandardError.new("No route matches")
414
- exception_info = ExceptionInfo.new(exception, nil, Time.now)
415
- expect(exception_info.exception_description).to_not be_nil
416
- expect(exception_info.exception_description.send_to_honeybadger).to eq(true)
417
- expect(exception_info.send_to_honeybadger?).to eq(true)
395
+ exception_info = ExceptionInfo.new(exception, {}, Time.now)
396
+ assert_not_nil exception_info.exception_description
397
+ assert_equal true, exception_info.exception_description.send_to_honeybadger
398
+ assert_equal true, exception_info.send_to_honeybadger?
418
399
  end
419
400
 
420
- it "be disabled when Honeybadger is defined and exception is on the filter list with the flag turned off" do
421
- allow(ExceptionHandling).to receive(:honeybadger_defined?).and_return(true)
401
+ should "be disabled when Honeybadger is defined and exception is on the filter list with the flag turned off" do
402
+ stub(ExceptionHandling).honeybadger_defined? { true }
422
403
  exception = StandardError.new("No route matches")
423
- exception_info = ExceptionInfo.new(exception, nil, Time.now)
424
- expect(exception_info.exception_description).to_not be_nil
425
- allow(exception_info.exception_description).to receive(:send_to_honeybadger).and_return(false)
426
- expect(exception_info.send_to_honeybadger?).to eq(false)
404
+ exception_info = ExceptionInfo.new(exception, {}, Time.now)
405
+ assert_not_nil exception_info.exception_description
406
+ stub(exception_info.exception_description).send_to_honeybadger { false }
407
+ assert_equal false, exception_info.send_to_honeybadger?
427
408
  end
428
409
 
429
- it "be disabled when Honeybadger is not defined" do
430
- allow(ExceptionHandling).to receive(:honeybadger_defined?).and_return(false)
410
+ should "be disabled when Honeybadger is not defined" do
411
+ stub(ExceptionHandling).honeybadger_defined? { false }
431
412
  exception = StandardError.new("something went wrong")
432
- exception_info = ExceptionInfo.new(exception, nil, Time.now)
433
- expect(exception_info.exception_description).to be_nil
434
- expect(exception_info.send_to_honeybadger?).to eq(false)
413
+ exception_info = ExceptionInfo.new(exception, {}, Time.now)
414
+ assert_nil exception_info.exception_description
415
+ assert_equal false, exception_info.send_to_honeybadger?
435
416
  end
436
417
  end
437
418
 
438
419
  context "honeybadger_context_data" do
439
- before do
440
- allow(ExceptionHandling.logger).to receive(:current_context_for_thread).and_return({ cuid: 'ABCD' })
441
- end
442
-
443
- it "include thread_context when log_context: is nil" do
444
- exception_with_nil_message = RuntimeError.new(nil)
445
- allow(exception_with_nil_message).to receive(:message).and_return(nil)
446
- exception_info = ExceptionInfo.new(exception_with_nil_message, @exception_context, @timestamp)
447
- honeybadger_context_data = exception_info.honeybadger_context_data
448
- expect(honeybadger_context_data[:log_context]).to eq({ "cuid" => 'ABCD' })
449
- end
450
-
451
- it "include thread context merged with log_context:" do
452
- exception_with_nil_message = RuntimeError.new(nil)
453
- allow(exception_with_nil_message).to receive(:message).and_return(nil)
454
- exception_info = ExceptionInfo.new(exception_with_nil_message, @exception_context, @timestamp, log_context: { url: 'http://example.com' })
455
- honeybadger_context_data = exception_info.honeybadger_context_data
456
- expect(honeybadger_context_data[:log_context]).to eq({ "cuid" => 'ABCD', "url" => 'http://example.com' })
457
- end
458
-
459
- it "return the error details and relevant context data to be used as honeybadger notification context while filtering sensitive data" do
420
+ should "return the error details and relevant context data to be used as honeybadger notification context while filtering sensitive data" do
460
421
  env = { server: "fe98" }
461
422
  parameters = { advertiser_id: 435 }
462
423
  session = { username: "jsmith" }
463
424
  request_uri = "host/path"
464
425
  controller = create_dummy_controller(env, parameters, session, request_uri)
465
- allow(ExceptionHandling).to receive(:server_name).and_return("invoca_fe98")
426
+ stub(ExceptionHandling).server_name { "invoca_fe98" }
466
427
 
467
428
  exception = StandardError.new("Some Exception")
468
429
  exception.set_backtrace([
469
- "spec/unit/exception_handling_test.rb:847:in `exception_1'",
470
- "spec/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
430
+ "test/unit/exception_handling_test.rb:847:in `exception_1'",
431
+ "test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
471
432
  ])
472
433
  exception_context = { "SERVER_NAME" => "exceptional.com" }
473
434
  data_callback = ->(data) do
@@ -477,7 +438,7 @@ module ExceptionHandling
477
438
  data[:other_section] = "This should not be included in the response"
478
439
  end
479
440
  timestamp = Time.now
480
- exception_info = ExceptionInfo.new(exception, exception_context, timestamp, controller: controller, data_callback: data_callback)
441
+ exception_info = ExceptionInfo.new(exception, exception_context, timestamp, controller, data_callback)
481
442
 
482
443
  expected_data = {
483
444
  timestamp: timestamp,
@@ -485,6 +446,7 @@ module ExceptionHandling
485
446
  exception_context: { "SERVER_NAME" => "exceptional.com" },
486
447
  server: "invoca_fe98",
487
448
  scm_revision: "5b24eac37aaa91f5784901e9aabcead36fd9df82",
449
+ notes: "this is used by a test",
488
450
  user_details: { "username" => "jsmith" },
489
451
  request: {
490
452
  "params" => { "advertiser_id" => 435 },
@@ -499,30 +461,28 @@ module ExceptionHandling
499
461
  "SERVER_NAME" => "exceptional.com"
500
462
  },
501
463
  backtrace: [
502
- "spec/unit/exception_handling_test.rb:847:in `exception_1'",
503
- "spec/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
464
+ "test/unit/exception_handling_test.rb:847:in `exception_1'",
465
+ "test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
504
466
  ],
505
- event_response: "Event successfully received",
506
- log_context: { "cuid" => "ABCD" },
507
- notes: "this is used by a test"
467
+ event_response: "Event successfully received"
508
468
  }
509
- expect(exception_info.honeybadger_context_data).to eq(expected_data)
469
+ assert_equal_with_diff expected_data, exception_info.honeybadger_context_data
510
470
  end
511
471
 
512
472
  [['Hash', { 'cookie' => 'cookie_context' }],
513
473
  ['String', 'Entering Error State'],
514
474
  ['Array', ['Error1', 'Error2']]].each do |klass, value|
515
- it "extract context from exception_context when it is a #{klass}" do
475
+ should "extract context from exception_context when it is a #{klass}" do
516
476
  exception = StandardError.new("Exception")
517
477
  exception_context = value
518
478
  exception_info = ExceptionInfo.new(exception, exception_context, Time.now)
519
479
 
520
- expect(value.class.name).to eq(klass)
521
- expect(exception_info.honeybadger_context_data[:exception_context]).to eq(value)
480
+ assert_equal klass, value.class.name
481
+ assert_equal value, exception_info.honeybadger_context_data[:exception_context]
522
482
  end
523
483
  end
524
484
 
525
- it "filter out sensitive data from exception context such as [password, password_confirmation, oauth_token]" do
485
+ should "filter out sensitive data from exception context such as [password, password_confirmation, oauth_token]" do
526
486
  sensitive_data = {
527
487
  "password" => "super_secret",
528
488
  "password_confirmation" => "super_secret_confirmation",
@@ -557,14 +517,15 @@ module ExceptionHandling
557
517
  }
558
518
  }.merge(expected_sensitive_data)
559
519
 
560
- expect(exception_info.honeybadger_context_data[:exception_context]).to eq(expected_exception_context)
520
+ assert_equal_with_diff expected_exception_context, exception_info.honeybadger_context_data[:exception_context]
561
521
  end
562
522
 
563
- it "omit context if exception_context is empty" do
523
+ should "omit context if exception_context is empty" do
564
524
  exception = StandardError.new("Exception")
565
525
  exception_context = ""
566
526
  exception_info = ExceptionInfo.new(exception, exception_context, Time.now)
567
- expect(exception_info.honeybadger_context_data[:exception_context]).to be_nil
527
+
528
+ assert_nil exception_info.honeybadger_context_data[:exception_context]
568
529
  end
569
530
  end
570
531