exception_handling 3.0.pre.1 → 3.0.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/workflows/pipeline.yml +36 -0
  4. data/.gitignore +3 -0
  5. data/.rspec +3 -0
  6. data/.ruby-version +1 -1
  7. data/.tool-versions +1 -0
  8. data/Appraisals +13 -0
  9. data/CHANGELOG.md +150 -0
  10. data/Gemfile +10 -16
  11. data/Gemfile.lock +65 -128
  12. data/README.md +51 -19
  13. data/Rakefile +8 -11
  14. data/exception_handling.gemspec +11 -13
  15. data/gemfiles/rails_5.gemfile +16 -0
  16. data/gemfiles/rails_6.gemfile +16 -0
  17. data/gemfiles/rails_7.gemfile +16 -0
  18. data/lib/exception_handling/escalate_callback.rb +19 -0
  19. data/lib/exception_handling/exception_info.rb +15 -11
  20. data/lib/exception_handling/log_stub_error.rb +2 -1
  21. data/lib/exception_handling/logging_methods.rb +21 -0
  22. data/lib/exception_handling/testing.rb +9 -12
  23. data/lib/exception_handling/version.rb +1 -1
  24. data/lib/exception_handling.rb +83 -173
  25. data/{test → spec}/helpers/exception_helpers.rb +2 -2
  26. data/spec/rake_test_warning_false.rb +20 -0
  27. data/{test/test_helper.rb → spec/spec_helper.rb} +63 -66
  28. data/spec/unit/exception_handling/escalate_callback_spec.rb +81 -0
  29. data/spec/unit/exception_handling/exception_catalog_spec.rb +85 -0
  30. data/spec/unit/exception_handling/exception_description_spec.rb +82 -0
  31. data/{test/unit/exception_handling/exception_info_test.rb → spec/unit/exception_handling/exception_info_spec.rb} +170 -114
  32. data/{test/unit/exception_handling/log_error_stub_test.rb → spec/unit/exception_handling/log_error_stub_spec.rb} +38 -22
  33. data/spec/unit/exception_handling/logging_methods_spec.rb +38 -0
  34. data/spec/unit/exception_handling_spec.rb +1063 -0
  35. metadata +60 -89
  36. data/lib/exception_handling/honeybadger_callbacks.rb +0 -59
  37. data/lib/exception_handling/mailer.rb +0 -70
  38. data/lib/exception_handling/methods.rb +0 -101
  39. data/lib/exception_handling/sensu.rb +0 -28
  40. data/semaphore_ci/setup.sh +0 -3
  41. data/test/unit/exception_handling/exception_catalog_test.rb +0 -85
  42. data/test/unit/exception_handling/exception_description_test.rb +0 -82
  43. data/test/unit/exception_handling/honeybadger_callbacks_test.rb +0 -122
  44. data/test/unit/exception_handling/mailer_test.rb +0 -98
  45. data/test/unit/exception_handling/methods_test.rb +0 -84
  46. data/test/unit/exception_handling/sensu_test.rb +0 -52
  47. data/test/unit/exception_handling_test.rb +0 -1109
  48. data/views/exception_handling/mailer/escalate_custom.html.erb +0 -17
  49. data/views/exception_handling/mailer/escalation_notification.html.erb +0 -17
  50. data/views/exception_handling/mailer/log_parser_exception_notification.html.erb +0 -82
  51. /data/{test → spec}/helpers/controller_helpers.rb +0 -0
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../test_helper', __dir__)
3
+ require File.expand_path('../../spec_helper', __dir__)
4
4
 
5
5
  module ExceptionHandling
6
- class LogErrorStubTest < ActiveSupport::TestCase
6
+ describe LogErrorStub do
7
7
 
8
8
  include LogErrorStub
9
9
 
10
10
  context "while running tests" do
11
- setup do
11
+ before do
12
12
  setup_log_error_stub
13
13
  end
14
14
 
15
- teardown do
15
+ after do
16
16
  teardown_log_error_stub
17
17
  end
18
18
 
19
- should "raise an error when log_error and log_warning are called" do
19
+ it "raise an error when log_error and log_warning are called" do
20
20
  begin
21
21
  ExceptionHandling.log_error("Something happened")
22
22
  flunk
23
23
  rescue Exception => ex # LogErrorStub::UnexpectedExceptionLogged => ex
24
- assert ex.to_s.starts_with?("StandardError: Something happened"), ex.to_s
24
+ expect(ex.to_s.starts_with?("StandardError: Something happened")).to be_truthy
25
25
  end
26
26
 
27
27
  begin
@@ -31,16 +31,16 @@ module ExceptionHandling
31
31
  begin
32
32
  ExceptionHandling.log_error(ex)
33
33
  rescue LogErrorStub::UnexpectedExceptionLogged => ex
34
- assert ex.to_s.starts_with?("RaisedError: This should raise"), ex.to_s
34
+ expect(ex.to_s.starts_with?("RaisedError: This should raise")).to be_truthy
35
35
  end
36
36
  end
37
37
  end
38
38
 
39
- should "allow for the regex specification of an expected exception to be ignored" do
39
+ it "allow for the regex specification of an expected exception to be ignored" do
40
40
  exception_pattern = /StandardError: This is a test error/
41
- assert_nil exception_whitelist # test that exception expectations are cleared
41
+ expect(exception_whitelist).to be_nil # test that exception expectations are cleared
42
42
  expects_exception(exception_pattern)
43
- assert_equal exception_pattern, exception_whitelist[0][0]
43
+ expect(exception_whitelist[0][0]).to eq(exception_pattern)
44
44
  begin
45
45
  ExceptionHandling.log_error("This is a test error")
46
46
  rescue StandardError
@@ -48,11 +48,11 @@ module ExceptionHandling
48
48
  end
49
49
  end
50
50
 
51
- should "allow for the string specification of an expected exception to be ignored" do
51
+ it "allow for the string specification of an expected exception to be ignored" do
52
52
  exception_pattern = "StandardError: This is a test error"
53
- assert_nil exception_whitelist # test that exception expectations are cleared
53
+ expect(exception_whitelist).to be_nil # test that exception expectations are cleared
54
54
  expects_exception(exception_pattern)
55
- assert_equal exception_pattern, exception_whitelist[0][0]
55
+ expect(exception_whitelist[0][0]).to eq(exception_pattern)
56
56
  begin
57
57
  ExceptionHandling.log_error("This is a test error")
58
58
  rescue StandardError
@@ -60,9 +60,9 @@ module ExceptionHandling
60
60
  end
61
61
  end
62
62
 
63
- should "allow multiple errors to be ignored" do
63
+ it "allow multiple errors to be ignored" do
64
64
  class IgnoredError < StandardError; end
65
- assert_nil exception_whitelist # test that exception expectations are cleared
65
+ expect(exception_whitelist).to be_nil # test that exception expectations are cleared
66
66
  expects_exception(/StandardError: This is a test error/)
67
67
  expects_exception(/IgnoredError: This should be ignored/)
68
68
  ExceptionHandling.log_error("This is a test error")
@@ -73,7 +73,7 @@ module ExceptionHandling
73
73
  end
74
74
  end
75
75
 
76
- should "expect exception twice if declared twice" do
76
+ it "expect exception twice if declared twice" do
77
77
  expects_exception(/StandardError: ERROR: I love lamp/)
78
78
  expects_exception(/StandardError: ERROR: I love lamp/)
79
79
  ExceptionHandling.log_error("ERROR: I love lamp")
@@ -82,23 +82,39 @@ module ExceptionHandling
82
82
  end
83
83
 
84
84
  context "teardown_log_error_stub" do
85
- should "support MiniTest framework for adding a failure" do
85
+ before do
86
+ RSpec.configure do |config|
87
+ config.mock_with :rspec do |mocks|
88
+ mocks.verify_partial_doubles = false
89
+ end
90
+ end
91
+ end
92
+
93
+ after do
94
+ RSpec.configure do |config|
95
+ config.mock_with :rspec do |mocks|
96
+ mocks.verify_partial_doubles = true
97
+ end
98
+ end
99
+ end
100
+
101
+ it "support MiniTest framework for adding a failure" do
86
102
  expects_exception(/foo/)
87
103
 
88
- mock(self).is_mini_test?.returns { true }
104
+ expect(self).to receive(:is_mini_test?) { true }
89
105
 
90
- mock(self).flunk("log_error expected 1 times with pattern: 'foo' found 0")
106
+ expect(self).to receive(:flunk).with("log_error expected 1 times with pattern: 'foo' found 0")
91
107
  teardown_log_error_stub
92
108
 
93
109
  self.exception_whitelist = nil
94
110
  end
95
111
 
96
- should "support Test::Unit framework for adding a failure" do
112
+ it "support Test::Unit framework for adding a failure" do
97
113
  expects_exception(/foo/)
98
114
 
99
- mock(self).is_mini_test?.returns { false }
115
+ expect(self).to receive(:is_mini_test?) { false }
100
116
 
101
- mock(self).add_failure("log_error expected 1 times with pattern: 'foo' found 0")
117
+ expect(self).to receive(:add_failure).with("log_error expected 1 times with pattern: 'foo' found 0")
102
118
  teardown_log_error_stub
103
119
 
104
120
  self.exception_whitelist = nil
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../spec_helper', __dir__)
4
+
5
+ require_relative '../../helpers/exception_helpers'
6
+
7
+ require "exception_handling/testing"
8
+
9
+ module ExceptionHandling
10
+ describe LoggingMethods do
11
+ include ExceptionHelpers
12
+
13
+ def dont_stub_log_error
14
+ true
15
+ end
16
+
17
+ context "ExceptionHandling::LoggingMethods" do
18
+ before do
19
+ @controller = Testing::LoggingMethodsControllerStub.new
20
+ ExceptionHandling.stub_handler = nil
21
+ end
22
+
23
+ context "#log_warning" do
24
+ it "be available to the controller" do
25
+ klass = Class.new
26
+ klass.include ExceptionHandling::LoggingMethods
27
+ instance = klass.new
28
+ expect(instance.methods.include?(:log_warning)).to eq(true)
29
+ end
30
+
31
+ it "call ExceptionHandling#log_warning" do
32
+ expect(ExceptionHandling).to receive(:log_warning).with("Hi mom")
33
+ @controller.send(:log_warning, "Hi mom")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end