exception_handling 3.0.pre.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/workflows/pipeline.yml +36 -0
- data/.gitignore +3 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -1
- data/.tool-versions +1 -0
- data/Appraisals +13 -0
- data/CHANGELOG.md +150 -0
- data/Gemfile +10 -16
- data/Gemfile.lock +65 -128
- data/README.md +51 -19
- data/Rakefile +8 -11
- data/exception_handling.gemspec +11 -13
- data/gemfiles/rails_5.gemfile +16 -0
- data/gemfiles/rails_6.gemfile +16 -0
- data/gemfiles/rails_7.gemfile +16 -0
- data/lib/exception_handling/escalate_callback.rb +19 -0
- data/lib/exception_handling/exception_info.rb +15 -11
- data/lib/exception_handling/log_stub_error.rb +2 -1
- data/lib/exception_handling/logging_methods.rb +21 -0
- data/lib/exception_handling/testing.rb +9 -12
- data/lib/exception_handling/version.rb +1 -1
- data/lib/exception_handling.rb +83 -173
- data/{test → spec}/helpers/exception_helpers.rb +2 -2
- data/spec/rake_test_warning_false.rb +20 -0
- data/{test/test_helper.rb → spec/spec_helper.rb} +63 -66
- data/spec/unit/exception_handling/escalate_callback_spec.rb +81 -0
- data/spec/unit/exception_handling/exception_catalog_spec.rb +85 -0
- data/spec/unit/exception_handling/exception_description_spec.rb +82 -0
- data/{test/unit/exception_handling/exception_info_test.rb → spec/unit/exception_handling/exception_info_spec.rb} +170 -114
- data/{test/unit/exception_handling/log_error_stub_test.rb → spec/unit/exception_handling/log_error_stub_spec.rb} +38 -22
- data/spec/unit/exception_handling/logging_methods_spec.rb +38 -0
- data/spec/unit/exception_handling_spec.rb +1063 -0
- metadata +62 -91
- data/lib/exception_handling/honeybadger_callbacks.rb +0 -59
- data/lib/exception_handling/mailer.rb +0 -70
- data/lib/exception_handling/methods.rb +0 -101
- data/lib/exception_handling/sensu.rb +0 -28
- data/semaphore_ci/setup.sh +0 -3
- data/test/unit/exception_handling/exception_catalog_test.rb +0 -85
- data/test/unit/exception_handling/exception_description_test.rb +0 -82
- data/test/unit/exception_handling/honeybadger_callbacks_test.rb +0 -122
- data/test/unit/exception_handling/mailer_test.rb +0 -98
- data/test/unit/exception_handling/methods_test.rb +0 -84
- data/test/unit/exception_handling/sensu_test.rb +0 -52
- data/test/unit/exception_handling_test.rb +0 -1109
- data/views/exception_handling/mailer/escalate_custom.html.erb +0 -17
- data/views/exception_handling/mailer/escalation_notification.html.erb +0 -17
- data/views/exception_handling/mailer/log_parser_exception_notification.html.erb +0 -82
- /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('../../
|
3
|
+
require File.expand_path('../../spec_helper', __dir__)
|
4
4
|
|
5
5
|
module ExceptionHandling
|
6
|
-
|
6
|
+
describe LogErrorStub do
|
7
7
|
|
8
8
|
include LogErrorStub
|
9
9
|
|
10
10
|
context "while running tests" do
|
11
|
-
|
11
|
+
before do
|
12
12
|
setup_log_error_stub
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
after do
|
16
16
|
teardown_log_error_stub
|
17
17
|
end
|
18
18
|
|
19
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
41
|
+
expect(exception_whitelist).to be_nil # test that exception expectations are cleared
|
42
42
|
expects_exception(exception_pattern)
|
43
|
-
|
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
|
-
|
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
|
-
|
53
|
+
expect(exception_whitelist).to be_nil # test that exception expectations are cleared
|
54
54
|
expects_exception(exception_pattern)
|
55
|
-
|
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
|
-
|
63
|
+
it "allow multiple errors to be ignored" do
|
64
64
|
class IgnoredError < StandardError; end
|
65
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
104
|
+
expect(self).to receive(:is_mini_test?) { true }
|
89
105
|
|
90
|
-
|
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
|
-
|
112
|
+
it "support Test::Unit framework for adding a failure" do
|
97
113
|
expects_exception(/foo/)
|
98
114
|
|
99
|
-
|
115
|
+
expect(self).to receive(:is_mini_test?) { false }
|
100
116
|
|
101
|
-
|
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
|