exception_handling 2.5.0.pre.1 → 2.6.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 +24 -8
- data/.rspec +3 -0
- data/CHANGELOG.md +22 -2
- data/Gemfile +4 -4
- data/Gemfile.lock +30 -20
- data/Rakefile +7 -6
- data/lib/exception_handling.rb +8 -2
- data/lib/exception_handling/exception_info.rb +4 -5
- data/lib/exception_handling/log_stub_error.rb +2 -1
- data/lib/exception_handling/version.rb +1 -1
- data/{test → spec}/helpers/controller_helpers.rb +0 -0
- 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} +57 -42
- 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} +118 -99
- data/{test/unit/exception_handling/honeybadger_callbacks_test.rb → spec/unit/exception_handling/honeybadger_callbacks_spec.rb} +20 -20
- data/{test/unit/exception_handling/log_error_stub_test.rb → spec/unit/exception_handling/log_error_stub_spec.rb} +38 -22
- data/{test/unit/exception_handling/mailer_test.rb → spec/unit/exception_handling/mailer_spec.rb} +17 -17
- data/spec/unit/exception_handling/methods_spec.rb +84 -0
- data/spec/unit/exception_handling/sensu_spec.rb +51 -0
- data/spec/unit/exception_handling_spec.rb +1226 -0
- metadata +34 -31
- 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/methods_test.rb +0 -84
- data/test/unit/exception_handling/sensu_test.rb +0 -52
- data/test/unit/exception_handling_test.rb +0 -1137
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e775cff5b73e955140fcc3a5492564e565567e8de147424da3602b83ad2e3b55
|
4
|
+
data.tar.gz: 35fa446e469e356ae600c5b24860ec8ff73dda25a72df59d5954be0748aac6bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3486a507210596be078ae1953105859d9d2e556b5794f9e1b01bbee21b34e6cd04be115429548a02cce1c6fec80ea680f990ba8b83d07c9594fed5c7de712d5
|
7
|
+
data.tar.gz: e19c845b8d8332f5118c0668c4520cabf00bf88c94117111ee2801d5320f2af2cc620224d79e3dc2e4daef62c4c7cb4115e3cc010cf56e8292cf9dcfef49f974
|
data/.gitignore
CHANGED
data/.jenkins/Jenkinsfile
CHANGED
@@ -36,42 +36,58 @@ pipeline {
|
|
36
36
|
stage('Appraisals') {
|
37
37
|
parallel {
|
38
38
|
stage('Current') {
|
39
|
+
environment {
|
40
|
+
JUNIT_OUTPUT = 'spec/reports/current'
|
41
|
+
}
|
42
|
+
|
39
43
|
steps {
|
40
|
-
sh
|
44
|
+
sh "bundle exec rspec --format RspecJunitFormatter --out ${JUNIT_OUTPUT}/rspec.xml"
|
41
45
|
}
|
42
46
|
|
43
47
|
post {
|
44
|
-
always { junit
|
48
|
+
always { junit "${JUNIT_OUTPUT}/*.xml" }
|
45
49
|
}
|
46
50
|
}
|
47
51
|
|
48
52
|
stage('Rails 4') {
|
53
|
+
environment {
|
54
|
+
JUNIT_OUTPUT = 'spec/reports/rails-4'
|
55
|
+
}
|
56
|
+
|
49
57
|
steps {
|
50
|
-
sh
|
58
|
+
sh "bundle exec appraisal rails-4 rspec --format RspecJunitFormatter --out ${JUNIT_OUTPUT}/rspec.xml"
|
51
59
|
}
|
52
60
|
|
53
61
|
post {
|
54
|
-
always { junit
|
62
|
+
always { junit "${JUNIT_OUTPUT}/*.xml" }
|
55
63
|
}
|
56
64
|
}
|
57
65
|
|
58
66
|
stage('Rails 5') {
|
67
|
+
environment {
|
68
|
+
JUNIT_OUTPUT = 'spec/reports/rails-5'
|
69
|
+
}
|
70
|
+
|
59
71
|
steps {
|
60
|
-
sh
|
72
|
+
sh "bundle exec appraisal rails-5 rspec --format RspecJunitFormatter --out ${JUNIT_OUTPUT}/rspec.xml"
|
61
73
|
}
|
62
74
|
|
63
75
|
post {
|
64
|
-
always { junit
|
76
|
+
always { junit "${JUNIT_OUTPUT}/*.xml" }
|
65
77
|
}
|
66
78
|
}
|
67
79
|
|
68
80
|
stage('Rails 6') {
|
81
|
+
environment {
|
82
|
+
JUNIT_OUTPUT = 'spec/reports/rails-6'
|
83
|
+
}
|
84
|
+
|
69
85
|
steps {
|
70
|
-
sh
|
86
|
+
sh "bundle exec appraisal rails-6 rspec --format RspecJunitFormatter --out ${JUNIT_OUTPUT}/rspec.xml"
|
71
87
|
}
|
72
88
|
|
73
89
|
post {
|
74
|
-
always { junit
|
90
|
+
always { junit "${JUNIT_OUTPUT}/*.xml" }
|
75
91
|
}
|
76
92
|
}
|
77
93
|
}
|
data/.rspec
ADDED
data/CHANGELOG.md
CHANGED
@@ -4,11 +4,28 @@ 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.6.1] - 2020-10-14
|
8
|
+
### Fixed
|
9
|
+
- Fixed honeybadger_context_data to always merge `current_context_for_thread`, even if `log_context:` is passed as `nil`.
|
10
|
+
|
11
|
+
## [2.6.0] - 2020-08-26
|
12
|
+
### Changed
|
13
|
+
- Calling `log_warning` will now log with Severity::WARNING rather than FATAL.
|
14
|
+
- Reordered the logging to put the exception class next to the message.
|
15
|
+
|
16
|
+
## [2.5.0] - 2020-08-19
|
8
17
|
### Added
|
9
18
|
- The `**log_context` passed to `log_error`/`log_warning`/`log_info` is now
|
10
19
|
passed into `Honeybadger.notify()`, in `context: { log_context: ... }`.
|
11
20
|
|
21
|
+
### Fixed
|
22
|
+
- Silenced test warning noise by no longer running ruby -w.
|
23
|
+
- Renamed a constant to ALLOWLIST.
|
24
|
+
|
25
|
+
## [2.4.4] - 2020-08-10
|
26
|
+
### Fixed
|
27
|
+
- `ExceptionHandling.logger = nil` no longer displays an "implicit extend" deprecation warning.
|
28
|
+
|
12
29
|
## [2.4.3] - 2020-05-14
|
13
30
|
### Deprecated
|
14
31
|
- In `ExceptionHandling.logger=`, implicit `logger.extend ContextualLogger::LoggerMixin` is now deprecated.
|
@@ -29,7 +46,10 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
|
|
29
46
|
### Changed
|
30
47
|
- No longer depends on hobo_support. Uses invoca-utils 0.3 instead.
|
31
48
|
|
32
|
-
[2.
|
49
|
+
[2.6.1]: https://github.com/Invoca/exception_handling/compare/v2.6.0...v2.6.1
|
50
|
+
[2.6.0]: https://github.com/Invoca/exception_handling/compare/v2.5.0...v2.6.0
|
51
|
+
[2.5.0]: https://github.com/Invoca/exception_handling/compare/v2.4.4...v2.5.0
|
52
|
+
[2.4.4]: https://github.com/Invoca/exception_handling/compare/v2.4.3...v2.4.4
|
33
53
|
[2.4.3]: https://github.com/Invoca/exception_handling/compare/v2.4.2...v2.4.3
|
34
54
|
[2.4.2]: https://github.com/Invoca/exception_handling/compare/v2.4.1...v2.4.2
|
35
55
|
[2.4.1]: https://github.com/Invoca/exception_handling/compare/v2.4.0...v2.4.1
|
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"
|
11
9
|
gem 'pry'
|
10
|
+
gem 'pry-byebug'
|
12
11
|
gem 'rake'
|
13
|
-
gem '
|
12
|
+
gem 'rspec'
|
13
|
+
gem 'rspec_junit_formatter'
|
14
14
|
gem 'rubocop'
|
15
|
-
gem '
|
15
|
+
gem 'test-unit'
|
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.6.1)
|
12
12
|
actionmailer (>= 4.2, < 7.0)
|
13
13
|
actionpack (>= 4.2, < 7.0)
|
14
14
|
activesupport (>= 4.2, < 7.0)
|
@@ -46,19 +46,20 @@ 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)
|
50
49
|
appraisal (2.2.0)
|
51
50
|
bundler
|
52
51
|
rake
|
53
52
|
thor (>= 0.14.0)
|
54
53
|
ast (2.4.0)
|
55
54
|
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.10.0)
|
59
59
|
activesupport
|
60
60
|
json
|
61
61
|
crass (1.0.6)
|
62
|
+
diff-lcs (1.4.4)
|
62
63
|
erubis (2.7.0)
|
63
64
|
eventmachine (1.2.7)
|
64
65
|
globalid (0.4.2)
|
@@ -68,7 +69,7 @@ GEM
|
|
68
69
|
invoca-utils (0.4.1)
|
69
70
|
jaro_winkler (1.5.3)
|
70
71
|
json (2.3.1)
|
71
|
-
loofah (2.
|
72
|
+
loofah (2.7.0)
|
72
73
|
crass (~> 1.0.2)
|
73
74
|
nokogiri (>= 1.5.9)
|
74
75
|
mail (2.7.1)
|
@@ -77,19 +78,18 @@ GEM
|
|
77
78
|
mini_mime (1.0.2)
|
78
79
|
mini_portile2 (2.4.0)
|
79
80
|
minitest (5.11.3)
|
80
|
-
minitest-reporters (1.0.20)
|
81
|
-
ansi
|
82
|
-
builder
|
83
|
-
minitest (>= 5.0)
|
84
|
-
ruby-progressbar
|
85
81
|
nokogiri (1.10.10)
|
86
82
|
mini_portile2 (~> 2.4.0)
|
87
83
|
parallel (1.17.0)
|
88
84
|
parser (2.6.3.0)
|
89
85
|
ast (~> 2.4.0)
|
86
|
+
power_assert (1.2.0)
|
90
87
|
pry (0.12.2)
|
91
88
|
coderay (~> 1.1.0)
|
92
89
|
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,7 +103,21 @@ GEM
|
|
103
103
|
loofah (~> 2.3)
|
104
104
|
rainbow (3.0.0)
|
105
105
|
rake (13.0.1)
|
106
|
-
|
106
|
+
rspec (3.9.0)
|
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)
|
107
121
|
rubocop (0.74.0)
|
108
122
|
jaro_winkler (~> 1.5.1)
|
109
123
|
parallel (~> 1.10)
|
@@ -112,12 +126,8 @@ GEM
|
|
112
126
|
ruby-progressbar (~> 1.7)
|
113
127
|
unicode-display_width (>= 1.4.0, < 1.7)
|
114
128
|
ruby-progressbar (1.10.1)
|
115
|
-
|
116
|
-
|
117
|
-
shoulda-matchers (~> 3.0)
|
118
|
-
shoulda-context (1.2.2)
|
119
|
-
shoulda-matchers (3.1.3)
|
120
|
-
activesupport (>= 4.0.0)
|
129
|
+
test-unit (3.3.6)
|
130
|
+
power_assert
|
121
131
|
thor (1.0.1)
|
122
132
|
thread_safe (0.3.6)
|
123
133
|
tzinfo (1.2.5)
|
@@ -131,13 +141,13 @@ DEPENDENCIES
|
|
131
141
|
appraisal (~> 2.2)
|
132
142
|
exception_handling!
|
133
143
|
honeybadger (= 3.3.1.pre.1)!
|
134
|
-
minitest
|
135
|
-
minitest-reporters
|
136
144
|
pry
|
145
|
+
pry-byebug
|
137
146
|
rake
|
138
|
-
|
147
|
+
rspec
|
148
|
+
rspec_junit_formatter
|
139
149
|
rubocop
|
140
|
-
|
150
|
+
test-unit
|
141
151
|
|
142
152
|
BUNDLED WITH
|
143
153
|
1.17.3
|
data/Rakefile
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "bundler/gem_tasks"
|
5
4
|
require 'rake/testtask'
|
5
|
+
require "bundler/gem_tasks"
|
6
6
|
|
7
|
-
require_relative '
|
8
|
-
|
9
|
-
task default: :test
|
7
|
+
require_relative 'spec/rake_test_warning_false'
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
desc "run rspec unit tests"
|
10
|
+
begin
|
11
|
+
require 'rspec/core/rake_task'
|
12
|
+
RSpec::Core::RakeTask.new(:rspec)
|
13
13
|
end
|
14
14
|
|
15
|
+
task default: :rspec
|
data/lib/exception_handling.rb
CHANGED
@@ -57,7 +57,7 @@ module ExceptionHandling # never included
|
|
57
57
|
Deprecation3_0 = ActiveSupport::Deprecation.new('3.0', 'exception_handling')
|
58
58
|
|
59
59
|
def logger=(logger)
|
60
|
-
@logger = if logger.is_a?(ContextualLogger::LoggerMixin)
|
60
|
+
@logger = if logger.nil? || logger.is_a?(ContextualLogger::LoggerMixin)
|
61
61
|
logger
|
62
62
|
else
|
63
63
|
Deprecation3_0.deprecation_warning('implicit extend with ContextualLogger::LoggerMixin', 'extend your logger instance or include into your logger class first')
|
@@ -222,7 +222,13 @@ module ExceptionHandling # never included
|
|
222
222
|
#
|
223
223
|
def write_exception_to_log(ex, exception_context, timestamp, log_context = {})
|
224
224
|
ActiveSupport::Deprecation.silence do
|
225
|
-
|
225
|
+
log_message = "#{exception_context}\n#{ex.class}: (#{encode_utf8(ex.message.to_s)}):\n " + clean_backtrace(ex).join("\n ") + "\n\n"
|
226
|
+
|
227
|
+
if ex.is_a?(Warning)
|
228
|
+
ExceptionHandling.logger.warn("\nExceptionHandlingWarning (Warning:#{timestamp}) #{log_message}", log_context)
|
229
|
+
else
|
230
|
+
ExceptionHandling.logger.fatal("\nExceptionHandlingError (Error:#{timestamp}) #{log_message}", log_context)
|
231
|
+
end
|
226
232
|
end
|
227
233
|
end
|
228
234
|
|
@@ -57,7 +57,8 @@ module ExceptionHandling
|
|
57
57
|
@timestamp = timestamp
|
58
58
|
@controller = controller || controller_from_context(exception_context)
|
59
59
|
@data_callback = data_callback
|
60
|
-
|
60
|
+
# merge into the surrounding context just like ContextualLogger does when logging
|
61
|
+
@merged_log_context = ExceptionHandling.logger.current_context_for_thread.deep_merge(log_context || {})
|
61
62
|
end
|
62
63
|
|
63
64
|
def data
|
@@ -269,15 +270,13 @@ module ExceptionHandling
|
|
269
270
|
data = enhanced_data.dup
|
270
271
|
data[:server] = ExceptionHandling.server_name
|
271
272
|
data[:exception_context] = deep_clean_hash(@exception_context) if @exception_context.present?
|
272
|
-
data[:log_context] = @
|
273
|
+
data[:log_context] = @merged_log_context
|
273
274
|
unstringify_sections(data)
|
274
|
-
|
275
|
+
HONEYBADGER_CONTEXT_SECTIONS.each_with_object({}) do |section, context|
|
275
276
|
if data[section].present?
|
276
277
|
context[section] = data[section]
|
277
278
|
end
|
278
|
-
context
|
279
279
|
end
|
280
|
-
context_data
|
281
280
|
end
|
282
281
|
end
|
283
282
|
end
|
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
|
+
allow(exception_with_nil_message).to receive(:message).and_return(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
|
+
allow(ExceptionHandling).to receive(:send_exception_to_honeybadger).with(anything) { |exception_info| @sent_notifications << exception_info }
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Rake 11+ has a misfeature where @warning = true by default
|
4
|
+
# See https://github.com/ruby/rake/pull/97/files
|
5
|
+
# This causes all tests to be run with `ruby -w`, causing a huge number of warnings
|
6
|
+
# from gems we don't control and overwhelming our test output.
|
7
|
+
# This patch reverts that.
|
8
|
+
|
9
|
+
_ = Rake::TestTask
|
10
|
+
|
11
|
+
class Rake::TestTask
|
12
|
+
module SetWarningFalseMixin
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
self.warning = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
prepend SetWarningFalseMixin
|
20
|
+
end
|
@@ -1,17 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
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)])
|
3
|
+
require 'rspec'
|
4
|
+
require 'rspec/mocks'
|
5
|
+
require 'rspec_junit_formatter'
|
15
6
|
|
16
7
|
require 'pry'
|
17
8
|
require 'honeybadger'
|
@@ -20,8 +11,6 @@ require 'contextual_logger'
|
|
20
11
|
require 'exception_handling'
|
21
12
|
require 'exception_handling/testing'
|
22
13
|
|
23
|
-
ActiveSupport::TestCase.test_order = :sorted
|
24
|
-
|
25
14
|
class LoggerStub
|
26
15
|
include ContextualLogger::LoggerMixin
|
27
16
|
attr_accessor :logged, :level
|
@@ -33,16 +22,20 @@ class LoggerStub
|
|
33
22
|
clear
|
34
23
|
end
|
35
24
|
|
25
|
+
def debug(message, log_context = {})
|
26
|
+
logged << { message: message, context: log_context, severity: 'DEBUG' }
|
27
|
+
end
|
28
|
+
|
36
29
|
def info(message, log_context = {})
|
37
|
-
logged << { message: message, context: log_context }
|
30
|
+
logged << { message: message, context: log_context, severity: 'INFO' }
|
38
31
|
end
|
39
32
|
|
40
33
|
def warn(message, log_context = {})
|
41
|
-
logged << { message: message, context: log_context }
|
34
|
+
logged << { message: message, context: log_context, severity: 'WARN' }
|
42
35
|
end
|
43
36
|
|
44
37
|
def fatal(message, log_context = {})
|
45
|
-
logged << { message: message, context: log_context }
|
38
|
+
logged << { message: message, context: log_context, severity: 'FATAL' }
|
46
39
|
end
|
47
40
|
|
48
41
|
def clear
|
@@ -83,27 +76,17 @@ end
|
|
83
76
|
|
84
77
|
ActionMailer::Base.delivery_method = :test
|
85
78
|
|
86
|
-
_ = ActiveSupport
|
87
|
-
_ = ActiveSupport::TestCase
|
88
79
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
raise "Uh-oh! constant_overrides left over: #{@@constant_overrides.inspect}"
|
95
|
-
end
|
80
|
+
module TestHelper
|
81
|
+
@constant_overrides = []
|
82
|
+
class << self
|
83
|
+
attr_accessor :constant_overrides
|
84
|
+
end
|
96
85
|
|
97
|
-
unless defined?(Rails) && defined?(Rails.env)
|
98
|
-
module ::Rails
|
99
|
-
class << self
|
100
|
-
attr_writer :env
|
101
86
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
87
|
+
def setup_constant_overrides
|
88
|
+
unless TestHelper.constant_overrides.nil? || TestHelper.constant_overrides.empty?
|
89
|
+
raise "Uh-oh! constant_overrides left over: #{TestHelper.constant_overrides.inspect}"
|
107
90
|
end
|
108
91
|
|
109
92
|
Time.now_override = nil
|
@@ -123,8 +106,8 @@ class ActiveSupport::TestCase
|
|
123
106
|
ExceptionHandling.sensu_prefix = ""
|
124
107
|
end
|
125
108
|
|
126
|
-
|
127
|
-
|
109
|
+
def teardown_constant_overrides
|
110
|
+
TestHelper.constant_overrides&.reverse&.each do |parent_module, k, v|
|
128
111
|
ExceptionHandling.ensure_safe "constant cleanup #{k.inspect}, #{parent_module}(#{parent_module.class})::#{v.inspect}(#{v.class})" do
|
129
112
|
silence_warnings do
|
130
113
|
if v == :never_defined
|
@@ -135,7 +118,7 @@ class ActiveSupport::TestCase
|
|
135
118
|
end
|
136
119
|
end
|
137
120
|
end
|
138
|
-
|
121
|
+
TestHelper.constant_overrides = []
|
139
122
|
end
|
140
123
|
|
141
124
|
def set_test_const(const_name, value)
|
@@ -155,7 +138,7 @@ class ActiveSupport::TestCase
|
|
155
138
|
end
|
156
139
|
end
|
157
140
|
|
158
|
-
|
141
|
+
TestHelper.constant_overrides << [final_parent_module, final_const_name, original_value]
|
159
142
|
|
160
143
|
silence_warnings { final_parent_module.const_set(final_const_name, value) }
|
161
144
|
end
|
@@ -167,15 +150,15 @@ class ActiveSupport::TestCase
|
|
167
150
|
else
|
168
151
|
original_count = 0
|
169
152
|
end
|
170
|
-
|
153
|
+
expect(ActionMailer::Base.deliveries.size - original_count).to eq(expected), "wrong number of emails#{': ' + message.to_s if message}"
|
171
154
|
end
|
172
155
|
end
|
173
156
|
|
174
157
|
def assert_equal_with_diff(arg1, arg2, msg = '')
|
175
158
|
if arg1 == arg2
|
176
|
-
|
159
|
+
expect(true).to be_truthy # To keep the assertion count accurate
|
177
160
|
else
|
178
|
-
|
161
|
+
expect(arg1).to eq(arg2), "#{msg}\n#{Diff.compare(arg1, arg2)}"
|
179
162
|
end
|
180
163
|
end
|
181
164
|
|
@@ -206,3 +189,35 @@ class Time
|
|
206
189
|
end
|
207
190
|
end
|
208
191
|
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
|