rspec_trunk_flaky_tests 0.12.9.pre.beta.3 → 0.12.10.pre.beta.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/lib/trunk_spec_helper.rb +62 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31ac5aa79b061a1f1af8239b22e9baead37dff94a469fe2eb13f33b173a7f931
|
|
4
|
+
data.tar.gz: 9df0653ebc1fc390fe1c4802c627666a2127127eae238b2c52b665ec154fb380
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 102b6bc119fffc72fb6f7d10b3f43810acce7c1dd0a65037f54e0de5809cecfe144d90d712b3359022141c32c7cc3c7eb2b02d5a64e6ecf7ede9bc6c61c724d9
|
|
7
|
+
data.tar.gz: 0bda2265f59be9846ebe42fb327661a92ca12cf4444fe3c8ae46eb57abe1725636bc2a23c7f92ee7f8aa95b2ea05069ecdf4f508a9e7d534c7876b0c1e165910
|
data/lib/trunk_spec_helper.rb
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
# DISABLE_RSPEC_TRUNK_FLAKY_TESTS - Set to 'true' to completely disable Trunk
|
|
31
31
|
#
|
|
32
32
|
require 'rspec/core'
|
|
33
|
+
require 'rspec/core/formatters/exception_presenter'
|
|
33
34
|
require 'time'
|
|
34
35
|
require 'rspec_trunk_flaky_tests'
|
|
35
36
|
|
|
@@ -186,10 +187,64 @@ module RSpec
|
|
|
186
187
|
end
|
|
187
188
|
end
|
|
188
189
|
|
|
189
|
-
|
|
190
|
+
# PlainColorizer is a no-op colorizer passed to RSpec's ExceptionPresenter so the
|
|
191
|
+
# formatted output is plain text suitable for storage and the web UI.
|
|
192
|
+
module PlainColorizer
|
|
193
|
+
module_function
|
|
194
|
+
|
|
195
|
+
def wrap(text, _code_or_symbol)
|
|
196
|
+
text
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Defer to RSpec's own ExceptionPresenter so the failure_message field matches
|
|
201
|
+
# what users see in their RSpec console output (Failure/Error: <source line>,
|
|
202
|
+
# the exception class and message, and any "Caused by:" chain).
|
|
203
|
+
def format_exception_message(exception, example)
|
|
204
|
+
return '' unless exception
|
|
205
|
+
|
|
206
|
+
presenter = RSpec::Core::Formatters::ExceptionPresenter.new(exception, example)
|
|
207
|
+
presenter.fully_formatted(nil, PlainColorizer)
|
|
208
|
+
rescue StandardError
|
|
209
|
+
legacy_format_exception_message(exception)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# trunk-ignore(rubocop/Metrics/MethodLength)
|
|
213
|
+
def format_exception_backtrace(exception, example)
|
|
214
|
+
return '' unless exception
|
|
215
|
+
|
|
216
|
+
lines = exception_backtrace_lines(exception, example)
|
|
217
|
+
|
|
218
|
+
cause = exception.cause
|
|
219
|
+
depth = 0
|
|
220
|
+
while cause && depth < 10
|
|
221
|
+
lines << ''
|
|
222
|
+
lines << "Caused by: #{cause.class}: #{cause.message}"
|
|
223
|
+
lines.concat(exception_backtrace_lines(cause, example))
|
|
224
|
+
cause = cause.cause
|
|
225
|
+
depth += 1
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
result = lines.join("\n")
|
|
229
|
+
# The exception presenter may choke on MultipleExceptionError, such as errors in before
|
|
230
|
+
# and after hooks, so we fall back to the legacy formatter
|
|
231
|
+
return legacy_format_exception_backtrace(exception) if result.strip.empty?
|
|
232
|
+
|
|
233
|
+
result
|
|
234
|
+
rescue StandardError
|
|
235
|
+
legacy_format_exception_backtrace(exception)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def exception_backtrace_lines(exception, example)
|
|
239
|
+
presenter = RSpec::Core::Formatters::ExceptionPresenter.new(exception, example)
|
|
240
|
+
Array(presenter.formatted_backtrace)
|
|
241
|
+
rescue StandardError
|
|
242
|
+
Array(exception.backtrace)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def legacy_format_exception_message(exception)
|
|
190
246
|
case exception
|
|
191
247
|
when RSpec::Core::MultipleExceptionError
|
|
192
|
-
# MultipleExceptionError contains multiple exceptions in @exceptions array
|
|
193
248
|
messages = exception.all_exceptions.map { |e| "#{e.class}: #{e.message}" }
|
|
194
249
|
"#{exception.class}: #{messages.join(' | ')}"
|
|
195
250
|
else
|
|
@@ -198,18 +253,16 @@ def format_exception_message(exception)
|
|
|
198
253
|
end
|
|
199
254
|
|
|
200
255
|
# trunk-ignore(rubocop/Metrics/MethodLength)
|
|
201
|
-
def
|
|
256
|
+
def legacy_format_exception_backtrace(exception)
|
|
202
257
|
case exception
|
|
203
258
|
when RSpec::Core::MultipleExceptionError
|
|
204
|
-
|
|
205
|
-
backtraces = exception.all_exceptions.map do |e|
|
|
259
|
+
exception.all_exceptions.map do |e|
|
|
206
260
|
if e.backtrace && !e.backtrace.empty?
|
|
207
261
|
"#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
|
|
208
262
|
else
|
|
209
263
|
"#{e.class}: #{e.message}"
|
|
210
264
|
end
|
|
211
|
-
end
|
|
212
|
-
backtraces.join("\n\n")
|
|
265
|
+
end.join("\n\n")
|
|
213
266
|
else
|
|
214
267
|
exception.backtrace&.join("\n") || ''
|
|
215
268
|
end
|
|
@@ -256,8 +309,8 @@ class TrunkAnalyticsListener
|
|
|
256
309
|
failure_message = ''
|
|
257
310
|
backtrace = ''
|
|
258
311
|
if exception
|
|
259
|
-
failure_message = format_exception_message(exception)
|
|
260
|
-
backtrace = format_exception_backtrace(exception)
|
|
312
|
+
failure_message = format_exception_message(exception, example).strip
|
|
313
|
+
backtrace = format_exception_backtrace(exception, example).strip
|
|
261
314
|
end
|
|
262
315
|
failure_message = failure_message[0...MAX_TEXT_FIELD_SIZE] if failure_message.length > MAX_TEXT_FIELD_SIZE
|
|
263
316
|
backtrace = backtrace[0...MAX_TEXT_FIELD_SIZE] if backtrace.length > MAX_TEXT_FIELD_SIZE
|