exception_handling 2.6.1 → 2.7.0.pre.1
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/.gitignore +1 -1
- data/.jenkins/Jenkinsfile +8 -24
- data/CHANGELOG.md +8 -1
- data/Gemfile +4 -4
- data/Gemfile.lock +19 -29
- data/Rakefile +6 -7
- data/lib/exception_handling/log_stub_error.rb +1 -2
- data/lib/exception_handling/logging_methods.rb +33 -0
- data/lib/exception_handling/methods.rb +6 -53
- data/lib/exception_handling/testing.rb +20 -10
- data/lib/exception_handling/version.rb +1 -1
- data/lib/exception_handling.rb +2 -2
- data/{spec → test}/helpers/controller_helpers.rb +0 -0
- data/{spec → test}/helpers/exception_helpers.rb +2 -2
- data/{spec → test}/rake_test_warning_false.rb +0 -0
- data/{spec/spec_helper.rb → test/test_helper.rb} +39 -50
- data/test/unit/exception_handling/exception_catalog_test.rb +85 -0
- data/test/unit/exception_handling/exception_description_test.rb +82 -0
- data/{spec/unit/exception_handling/exception_info_spec.rb → test/unit/exception_handling/exception_info_test.rb} +107 -105
- data/{spec/unit/exception_handling/honeybadger_callbacks_spec.rb → test/unit/exception_handling/honeybadger_callbacks_test.rb} +20 -20
- data/{spec/unit/exception_handling/log_error_stub_spec.rb → test/unit/exception_handling/log_error_stub_test.rb} +22 -38
- data/test/unit/exception_handling/logging_methods_test.rb +37 -0
- data/{spec/unit/exception_handling/mailer_spec.rb → test/unit/exception_handling/mailer_test.rb} +17 -17
- data/test/unit/exception_handling/methods_test.rb +105 -0
- data/test/unit/exception_handling/sensu_test.rb +52 -0
- data/{spec/unit/exception_handling_spec.rb → test/unit/exception_handling_test.rb} +329 -325
- metadata +36 -34
- data/.rspec +0 -3
- data/spec/unit/exception_handling/exception_catalog_spec.rb +0 -85
- data/spec/unit/exception_handling/exception_description_spec.rb +0 -82
- data/spec/unit/exception_handling/methods_spec.rb +0 -84
- data/spec/unit/exception_handling/sensu_spec.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3794611262e09346bab80e7a683f4ce1d78d6ba04b46fa15fa4bc84ac087e41e
|
4
|
+
data.tar.gz: 36f96bed7f2b3375df4730d35ee5ec96cdf70e7c07f4ba589e187c75275c1736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d1dad10749b867696c0f4dcacedcfb4af466ba792fa0c98ae307ee4bbeda10657f172fc95ff3c9b0162d1787d39c3c2a15a220fa6c6f4a7f7b10d857dad5eec
|
7
|
+
data.tar.gz: 8b28f2829a1e34787d7de51fdee4d0fe5a39356584d6d910c106edac2fe5d8ebcf0f3f5f1e9e1b7e4e7b0c36dd62035885214248072e47a7fdec7d1e4a854f94
|
data/.gitignore
CHANGED
data/.jenkins/Jenkinsfile
CHANGED
@@ -36,58 +36,42 @@ pipeline {
|
|
36
36
|
stage('Appraisals') {
|
37
37
|
parallel {
|
38
38
|
stage('Current') {
|
39
|
-
environment {
|
40
|
-
JUNIT_OUTPUT = 'spec/reports/current'
|
41
|
-
}
|
42
|
-
|
43
39
|
steps {
|
44
|
-
sh
|
40
|
+
sh 'JUNIT_OUTPUT_DIR=test/reports/current bundle exec rake'
|
45
41
|
}
|
46
42
|
|
47
43
|
post {
|
48
|
-
always { junit
|
44
|
+
always { junit '*/reports/current/*.xml' }
|
49
45
|
}
|
50
46
|
}
|
51
47
|
|
52
48
|
stage('Rails 4') {
|
53
|
-
environment {
|
54
|
-
JUNIT_OUTPUT = 'spec/reports/rails-4'
|
55
|
-
}
|
56
|
-
|
57
49
|
steps {
|
58
|
-
sh
|
50
|
+
sh 'JUNIT_OUTPUT_DIR=test/reports/rails-4 bundle exec appraisal rails-4 rake'
|
59
51
|
}
|
60
52
|
|
61
53
|
post {
|
62
|
-
always { junit
|
54
|
+
always { junit '*/reports/rails-4/*.xml' }
|
63
55
|
}
|
64
56
|
}
|
65
57
|
|
66
58
|
stage('Rails 5') {
|
67
|
-
environment {
|
68
|
-
JUNIT_OUTPUT = 'spec/reports/rails-5'
|
69
|
-
}
|
70
|
-
|
71
59
|
steps {
|
72
|
-
sh
|
60
|
+
sh 'JUNIT_OUTPUT_DIR=test/reports/rails-5 bundle exec appraisal rails-5 rake'
|
73
61
|
}
|
74
62
|
|
75
63
|
post {
|
76
|
-
always { junit
|
64
|
+
always { junit '*/reports/rails-5/*.xml' }
|
77
65
|
}
|
78
66
|
}
|
79
67
|
|
80
68
|
stage('Rails 6') {
|
81
|
-
environment {
|
82
|
-
JUNIT_OUTPUT = 'spec/reports/rails-6'
|
83
|
-
}
|
84
|
-
|
85
69
|
steps {
|
86
|
-
sh
|
70
|
+
sh 'JUNIT_OUTPUT_DIR=test/reports/rails-6 bundle exec appraisal rails-6 rake'
|
87
71
|
}
|
88
72
|
|
89
73
|
post {
|
90
|
-
always { junit
|
74
|
+
always { junit '*/reports/rails-6/*.xml' }
|
91
75
|
}
|
92
76
|
}
|
93
77
|
}
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,13 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
5
5
|
Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [2.
|
7
|
+
## [2.7.0] - Unreleased
|
8
|
+
### Added
|
9
|
+
- Added `LoggingMethods` as a replacement for `Methods` without setting controller or checking for long controller action.
|
10
|
+
### Deprecated
|
11
|
+
- Deprecated `Methods` in favor of `LoggingMethods`.
|
12
|
+
|
13
|
+
## [2.6.1] - Unreleased
|
8
14
|
### Fixed
|
9
15
|
- Fixed honeybadger_context_data to always merge `current_context_for_thread`, even if `log_context:` is passed as `nil`.
|
10
16
|
|
@@ -46,6 +52,7 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
|
|
46
52
|
### Changed
|
47
53
|
- No longer depends on hobo_support. Uses invoca-utils 0.3 instead.
|
48
54
|
|
55
|
+
[2.7.0]: https://github.com/Invoca/exception_handling/compare/v2.6.1...v2.7.0
|
49
56
|
[2.6.1]: https://github.com/Invoca/exception_handling/compare/v2.6.0...v2.6.1
|
50
57
|
[2.6.0]: https://github.com/Invoca/exception_handling/compare/v2.5.0...v2.6.0
|
51
58
|
[2.5.0]: https://github.com/Invoca/exception_handling/compare/v2.4.4...v2.5.0
|
data/Gemfile
CHANGED
@@ -6,10 +6,10 @@ gemspec
|
|
6
6
|
|
7
7
|
gem 'appraisal', '~> 2.2'
|
8
8
|
gem 'honeybadger', '3.3.1-1', git: 'git@github.com:Invoca/honeybadger-ruby', ref: 'bb5f2b8a86e4147c38a6270d39ad610fab4dd5e6'
|
9
|
+
gem "minitest"
|
10
|
+
gem "minitest-reporters"
|
9
11
|
gem 'pry'
|
10
|
-
gem 'pry-byebug'
|
11
12
|
gem 'rake'
|
12
|
-
gem '
|
13
|
-
gem 'rspec_junit_formatter'
|
13
|
+
gem 'rr'
|
14
14
|
gem 'rubocop'
|
15
|
-
gem '
|
15
|
+
gem 'shoulda'
|
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ GIT
|
|
8
8
|
PATH
|
9
9
|
remote: .
|
10
10
|
specs:
|
11
|
-
exception_handling (2.
|
11
|
+
exception_handling (2.7.0.pre.1)
|
12
12
|
actionmailer (>= 4.2, < 7.0)
|
13
13
|
actionpack (>= 4.2, < 7.0)
|
14
14
|
activesupport (>= 4.2, < 7.0)
|
@@ -46,20 +46,19 @@ GEM
|
|
46
46
|
minitest (~> 5.1)
|
47
47
|
thread_safe (~> 0.3, >= 0.3.4)
|
48
48
|
tzinfo (~> 1.1)
|
49
|
+
ansi (1.5.0)
|
49
50
|
appraisal (2.2.0)
|
50
51
|
bundler
|
51
52
|
rake
|
52
53
|
thor (>= 0.14.0)
|
53
54
|
ast (2.4.0)
|
54
55
|
builder (3.2.3)
|
55
|
-
byebug (11.1.3)
|
56
56
|
coderay (1.1.2)
|
57
57
|
concurrent-ruby (1.1.5)
|
58
|
-
contextual_logger (0.
|
58
|
+
contextual_logger (0.11.0)
|
59
59
|
activesupport
|
60
60
|
json
|
61
61
|
crass (1.0.6)
|
62
|
-
diff-lcs (1.4.4)
|
63
62
|
erubis (2.7.0)
|
64
63
|
eventmachine (1.2.7)
|
65
64
|
globalid (0.4.2)
|
@@ -78,18 +77,19 @@ GEM
|
|
78
77
|
mini_mime (1.0.2)
|
79
78
|
mini_portile2 (2.4.0)
|
80
79
|
minitest (5.11.3)
|
80
|
+
minitest-reporters (1.0.20)
|
81
|
+
ansi
|
82
|
+
builder
|
83
|
+
minitest (>= 5.0)
|
84
|
+
ruby-progressbar
|
81
85
|
nokogiri (1.10.10)
|
82
86
|
mini_portile2 (~> 2.4.0)
|
83
87
|
parallel (1.17.0)
|
84
88
|
parser (2.6.3.0)
|
85
89
|
ast (~> 2.4.0)
|
86
|
-
power_assert (1.2.0)
|
87
90
|
pry (0.12.2)
|
88
91
|
coderay (~> 1.1.0)
|
89
92
|
method_source (~> 0.9.0)
|
90
|
-
pry-byebug (3.8.0)
|
91
|
-
byebug (~> 11.0)
|
92
|
-
pry (~> 0.10)
|
93
93
|
rack (1.6.13)
|
94
94
|
rack-test (0.6.3)
|
95
95
|
rack (>= 1.0)
|
@@ -103,21 +103,7 @@ GEM
|
|
103
103
|
loofah (~> 2.3)
|
104
104
|
rainbow (3.0.0)
|
105
105
|
rake (13.0.1)
|
106
|
-
|
107
|
-
rspec-core (~> 3.9.0)
|
108
|
-
rspec-expectations (~> 3.9.0)
|
109
|
-
rspec-mocks (~> 3.9.0)
|
110
|
-
rspec-core (3.9.2)
|
111
|
-
rspec-support (~> 3.9.3)
|
112
|
-
rspec-expectations (3.9.2)
|
113
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
114
|
-
rspec-support (~> 3.9.0)
|
115
|
-
rspec-mocks (3.9.1)
|
116
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
117
|
-
rspec-support (~> 3.9.0)
|
118
|
-
rspec-support (3.9.3)
|
119
|
-
rspec_junit_formatter (0.4.1)
|
120
|
-
rspec-core (>= 2, < 4, != 2.12.0)
|
106
|
+
rr (1.2.1)
|
121
107
|
rubocop (0.74.0)
|
122
108
|
jaro_winkler (~> 1.5.1)
|
123
109
|
parallel (~> 1.10)
|
@@ -126,8 +112,12 @@ GEM
|
|
126
112
|
ruby-progressbar (~> 1.7)
|
127
113
|
unicode-display_width (>= 1.4.0, < 1.7)
|
128
114
|
ruby-progressbar (1.10.1)
|
129
|
-
|
130
|
-
|
115
|
+
shoulda (3.6.0)
|
116
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
117
|
+
shoulda-matchers (~> 3.0)
|
118
|
+
shoulda-context (1.2.2)
|
119
|
+
shoulda-matchers (3.1.3)
|
120
|
+
activesupport (>= 4.0.0)
|
131
121
|
thor (1.0.1)
|
132
122
|
thread_safe (0.3.6)
|
133
123
|
tzinfo (1.2.5)
|
@@ -141,13 +131,13 @@ DEPENDENCIES
|
|
141
131
|
appraisal (~> 2.2)
|
142
132
|
exception_handling!
|
143
133
|
honeybadger (= 3.3.1.pre.1)!
|
134
|
+
minitest
|
135
|
+
minitest-reporters
|
144
136
|
pry
|
145
|
-
pry-byebug
|
146
137
|
rake
|
147
|
-
|
148
|
-
rspec_junit_formatter
|
138
|
+
rr
|
149
139
|
rubocop
|
150
|
-
|
140
|
+
shoulda
|
151
141
|
|
152
142
|
BUNDLED WITH
|
153
143
|
1.17.3
|
data/Rakefile
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require 'rake/testtask'
|
5
4
|
require "bundler/gem_tasks"
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
require_relative 'test/rake_test_warning_false'
|
6
8
|
|
7
|
-
|
9
|
+
task default: :test
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
require 'rspec/core/rake_task'
|
12
|
-
RSpec::Core::RakeTask.new(:rspec)
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.pattern = "test/**/*_test.rb"
|
13
13
|
end
|
14
14
|
|
15
|
-
task default: :rspec
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'active_support/core_ext/module/delegation.rb'
|
5
|
+
|
6
|
+
module ExceptionHandling
|
7
|
+
module LoggingMethods # included on models and controllers
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
delegate :log_error_rack, :log_warning, :log_info, :log_debug, :escalate_error, :escalate_warning, :ensure_escalation, :alert_warning, to: ExceptionHandling
|
13
|
+
|
14
|
+
# TODO: delegate log_error as well
|
15
|
+
def log_error(exception_or_string, exception_context = '')
|
16
|
+
controller = self if respond_to?(:request) && respond_to?(:session)
|
17
|
+
ExceptionHandling.log_error(exception_or_string, exception_context, controller)
|
18
|
+
end
|
19
|
+
|
20
|
+
def ensure_safe(exception_context = "")
|
21
|
+
yield
|
22
|
+
rescue => ex
|
23
|
+
log_error ex, exception_context
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def ensure_alert(*args)
|
28
|
+
ExceptionHandling.ensure_alert(*args) do
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,65 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/concern'
|
4
|
+
require_relative 'logging_methods'
|
4
5
|
|
5
6
|
module ExceptionHandling
|
6
7
|
module Methods # included on models and controllers
|
7
8
|
extend ActiveSupport::Concern
|
9
|
+
include ExceptionHandling::LoggingMethods
|
8
10
|
|
9
11
|
protected
|
10
12
|
|
11
|
-
def log_error(exception_or_string, exception_context = '')
|
12
|
-
controller = self if respond_to?(:request) && respond_to?(:session)
|
13
|
-
ExceptionHandling.log_error(exception_or_string, exception_context, controller)
|
14
|
-
end
|
15
|
-
|
16
|
-
def log_error_rack(exception_or_string, exception_context = '', rack_filter = '')
|
17
|
-
ExceptionHandling.log_error_rack(exception_or_string, exception_context, rack_filter)
|
18
|
-
end
|
19
|
-
|
20
|
-
def log_warning(message)
|
21
|
-
ExceptionHandling.log_warning(message)
|
22
|
-
end
|
23
|
-
|
24
|
-
def log_info(message)
|
25
|
-
ExceptionHandling.logger.info(message)
|
26
|
-
end
|
27
|
-
|
28
|
-
def log_debug(message)
|
29
|
-
ExceptionHandling.logger.debug(message)
|
30
|
-
end
|
31
|
-
|
32
|
-
def ensure_safe(exception_context = "")
|
33
|
-
yield
|
34
|
-
rescue => ex
|
35
|
-
log_error ex, exception_context
|
36
|
-
nil
|
37
|
-
end
|
38
|
-
|
39
|
-
def escalate_error(exception_or_string, email_subject)
|
40
|
-
ExceptionHandling.escalate_error(exception_or_string, email_subject)
|
41
|
-
end
|
42
|
-
|
43
|
-
def escalate_warning(message, email_subject)
|
44
|
-
ExceptionHandling.escalate_warning(message, email_subject)
|
45
|
-
end
|
46
|
-
|
47
|
-
def ensure_escalation(*args)
|
48
|
-
ExceptionHandling.ensure_escalation(*args) do
|
49
|
-
yield
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def alert_warning(*args)
|
54
|
-
ExceptionHandling.alert_warning(*args)
|
55
|
-
end
|
56
|
-
|
57
|
-
def ensure_alert(*args)
|
58
|
-
ExceptionHandling.ensure_alert(*args) do
|
59
|
-
yield
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
13
|
def long_controller_action_timeout
|
64
14
|
if defined?(Rails) && Rails.respond_to?(:env) && Rails.env == 'test'
|
65
15
|
300
|
@@ -88,7 +38,10 @@ module ExceptionHandling
|
|
88
38
|
end
|
89
39
|
|
90
40
|
included do
|
91
|
-
around_filter
|
41
|
+
Deprecation3_0.deprecation_warning('ExceptionHandling::Methods', 'include LoggingMethods; in controllers, set your own around_filter to set logging context')
|
42
|
+
if respond_to? :around_filter
|
43
|
+
around_filter :set_current_controller
|
44
|
+
end
|
92
45
|
end
|
93
46
|
|
94
47
|
class_methods do
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
module ExceptionHandling
|
6
6
|
module Testing
|
7
|
-
class
|
7
|
+
class ControllerStubBase
|
8
8
|
|
9
9
|
class Request
|
10
10
|
attr_accessor :parameters, :protocol, :host, :request_uri, :env, :session_options
|
@@ -25,7 +25,7 @@ module ExceptionHandling
|
|
25
25
|
attr_accessor :around_filter_method
|
26
26
|
|
27
27
|
def around_filter(method)
|
28
|
-
|
28
|
+
self.around_filter_method = method
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -44,14 +44,6 @@ module ExceptionHandling
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def simulate_around_filter(&block)
|
48
|
-
set_current_controller(&block)
|
49
|
-
end
|
50
|
-
|
51
|
-
def controller_name
|
52
|
-
"ControllerStub"
|
53
|
-
end
|
54
|
-
|
55
47
|
def action_name
|
56
48
|
"test_action"
|
57
49
|
end
|
@@ -59,9 +51,27 @@ module ExceptionHandling
|
|
59
51
|
def complete_request_uri
|
60
52
|
"#{@request.protocol}#{@request.host}#{@request.request_uri}"
|
61
53
|
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class LoggingMethodsControllerStub < ControllerStubBase
|
57
|
+
include ExceptionHandling::LoggingMethods
|
58
|
+
|
59
|
+
def controller_name
|
60
|
+
"LoggingMethodsControllerStub"
|
61
|
+
end
|
62
|
+
end
|
62
63
|
|
64
|
+
class MethodsControllerStub < ControllerStubBase
|
63
65
|
include ExceptionHandling::Methods
|
64
66
|
set_long_controller_action_timeout 2
|
67
|
+
|
68
|
+
def simulate_around_filter(&block)
|
69
|
+
set_current_controller(&block)
|
70
|
+
end
|
71
|
+
|
72
|
+
def controller_name
|
73
|
+
"MethodsControllerStub"
|
74
|
+
end
|
65
75
|
end
|
66
76
|
end
|
67
77
|
end
|
data/lib/exception_handling.rb
CHANGED
@@ -29,6 +29,8 @@ module ExceptionHandling # never included
|
|
29
29
|
AUTHENTICATION_HEADERS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION', 'REDIRECT_X_HTTP_AUTHORIZATION'].freeze
|
30
30
|
HONEYBADGER_STATUSES = [:success, :failure, :skipped].freeze
|
31
31
|
|
32
|
+
Deprecation3_0 = ActiveSupport::Deprecation.new('3.0', 'exception_handling')
|
33
|
+
|
32
34
|
class << self
|
33
35
|
|
34
36
|
#
|
@@ -54,8 +56,6 @@ module ExceptionHandling # never included
|
|
54
56
|
@logger or raise ArgumentError, "You must assign a value to #{name}.logger"
|
55
57
|
end
|
56
58
|
|
57
|
-
Deprecation3_0 = ActiveSupport::Deprecation.new('3.0', 'exception_handling')
|
58
|
-
|
59
59
|
def logger=(logger)
|
60
60
|
@logger = if logger.nil? || logger.is_a?(ContextualLogger::LoggerMixin)
|
61
61
|
logger
|
File without changes
|
@@ -7,7 +7,7 @@ module ExceptionHelpers
|
|
7
7
|
|
8
8
|
def exception_with_nil_message
|
9
9
|
exception_with_nil_message = RuntimeError.new(nil)
|
10
|
-
|
10
|
+
stub(exception_with_nil_message).message { nil }
|
11
11
|
exception_with_nil_message
|
12
12
|
end
|
13
13
|
|
@@ -15,6 +15,6 @@ module ExceptionHelpers
|
|
15
15
|
|
16
16
|
def capture_notifications
|
17
17
|
@sent_notifications = []
|
18
|
-
|
18
|
+
stub(ExceptionHandling).send_exception_to_honeybadger(anything) { |exception_info| @sent_notifications << exception_info }
|
19
19
|
end
|
20
20
|
end
|
File without changes
|
@@ -1,8 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/time'
|
5
|
+
require 'active_support/test_case'
|
6
|
+
require 'action_mailer'
|
7
|
+
require 'action_dispatch'
|
8
|
+
require 'shoulda'
|
9
|
+
require 'rr'
|
10
|
+
require 'minitest/autorun'
|
11
|
+
require "minitest/reporters"
|
12
|
+
|
13
|
+
junit_ouptut_dir = ENV["JUNIT_OUTPUT_DIR"].presence || "test/reports"
|
14
|
+
Minitest::Reporters.use!([Minitest::Reporters::DefaultReporter.new, Minitest::Reporters::JUnitReporter.new(junit_ouptut_dir)])
|
6
15
|
|
7
16
|
require 'pry'
|
8
17
|
require 'honeybadger'
|
@@ -11,6 +20,8 @@ require 'contextual_logger'
|
|
11
20
|
require 'exception_handling'
|
12
21
|
require 'exception_handling/testing'
|
13
22
|
|
23
|
+
ActiveSupport::TestCase.test_order = :sorted
|
24
|
+
|
14
25
|
class LoggerStub
|
15
26
|
include ContextualLogger::LoggerMixin
|
16
27
|
attr_accessor :logged, :level
|
@@ -76,17 +87,27 @@ end
|
|
76
87
|
|
77
88
|
ActionMailer::Base.delivery_method = :test
|
78
89
|
|
90
|
+
_ = ActiveSupport
|
91
|
+
_ = ActiveSupport::TestCase
|
79
92
|
|
80
|
-
|
81
|
-
|
82
|
-
class << self
|
83
|
-
attr_accessor :constant_overrides
|
84
|
-
end
|
93
|
+
class ActiveSupport::TestCase
|
94
|
+
@@constant_overrides = []
|
85
95
|
|
96
|
+
setup do
|
97
|
+
unless @@constant_overrides.nil? || @@constant_overrides.empty?
|
98
|
+
raise "Uh-oh! constant_overrides left over: #{@@constant_overrides.inspect}"
|
99
|
+
end
|
86
100
|
|
87
|
-
|
88
|
-
|
89
|
-
|
101
|
+
unless defined?(Rails) && defined?(Rails.env)
|
102
|
+
module ::Rails
|
103
|
+
class << self
|
104
|
+
attr_writer :env
|
105
|
+
|
106
|
+
def env
|
107
|
+
@env ||= 'test'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
90
111
|
end
|
91
112
|
|
92
113
|
Time.now_override = nil
|
@@ -106,8 +127,8 @@ module TestHelper
|
|
106
127
|
ExceptionHandling.sensu_prefix = ""
|
107
128
|
end
|
108
129
|
|
109
|
-
|
110
|
-
|
130
|
+
teardown do
|
131
|
+
@@constant_overrides&.reverse&.each do |parent_module, k, v|
|
111
132
|
ExceptionHandling.ensure_safe "constant cleanup #{k.inspect}, #{parent_module}(#{parent_module.class})::#{v.inspect}(#{v.class})" do
|
112
133
|
silence_warnings do
|
113
134
|
if v == :never_defined
|
@@ -118,7 +139,7 @@ module TestHelper
|
|
118
139
|
end
|
119
140
|
end
|
120
141
|
end
|
121
|
-
|
142
|
+
@@constant_overrides = []
|
122
143
|
end
|
123
144
|
|
124
145
|
def set_test_const(const_name, value)
|
@@ -138,7 +159,7 @@ module TestHelper
|
|
138
159
|
end
|
139
160
|
end
|
140
161
|
|
141
|
-
|
162
|
+
@@constant_overrides << [final_parent_module, final_const_name, original_value]
|
142
163
|
|
143
164
|
silence_warnings { final_parent_module.const_set(final_const_name, value) }
|
144
165
|
end
|
@@ -150,15 +171,15 @@ module TestHelper
|
|
150
171
|
else
|
151
172
|
original_count = 0
|
152
173
|
end
|
153
|
-
|
174
|
+
assert_equal expected, ActionMailer::Base.deliveries.size - original_count, "wrong number of emails#{': ' + message.to_s if message}"
|
154
175
|
end
|
155
176
|
end
|
156
177
|
|
157
178
|
def assert_equal_with_diff(arg1, arg2, msg = '')
|
158
179
|
if arg1 == arg2
|
159
|
-
|
180
|
+
assert true # To keep the assertion count accurate
|
160
181
|
else
|
161
|
-
|
182
|
+
assert_equal arg1, arg2, "#{msg}\n#{Diff.compare(arg1, arg2)}"
|
162
183
|
end
|
163
184
|
end
|
164
185
|
|
@@ -189,35 +210,3 @@ class Time
|
|
189
210
|
end
|
190
211
|
end
|
191
212
|
end
|
192
|
-
|
193
|
-
RSpec.configure do |config|
|
194
|
-
config.add_formatter(RspecJunitFormatter, 'spec/reports/rspec.xml')
|
195
|
-
config.include TestHelper
|
196
|
-
|
197
|
-
config.before(:each) do
|
198
|
-
setup_constant_overrides
|
199
|
-
unless defined?(Rails) && defined?(Rails.env)
|
200
|
-
module Rails
|
201
|
-
class << self
|
202
|
-
attr_writer :env
|
203
|
-
|
204
|
-
def env
|
205
|
-
@env ||= 'test'
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
config.after(:each) do
|
213
|
-
teardown_constant_overrides
|
214
|
-
end
|
215
|
-
|
216
|
-
config.mock_with :rspec do |mocks|
|
217
|
-
mocks.verify_partial_doubles = true
|
218
|
-
end
|
219
|
-
|
220
|
-
config.expect_with(:rspec, :test_unit)
|
221
|
-
|
222
|
-
RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = 2_000
|
223
|
-
end
|