Commit d09b9de1 authored by Mark Lapierre's avatar Mark Lapierre

Make the RSpec JSON formatter more like JUnit

Include the error and stacktrace as they're presented by the JUnit
RSpec formatter (which is also more similar to the RSpec failure
output we're used to)

This will also help fix the problem of info in the job logs missing
from testcase issue comments
parent 5086bcd9
......@@ -12,19 +12,21 @@ module QA
# implementation so that it's not included.
end
def stop(notification)
def stop(example_notification)
# Based on https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/formatters/json_formatter.rb#L35
# But modified to include full details of multiple exceptions
@output_hash[:examples] = notification.examples.map do |example|
format_example(example).tap do |hash|
e = example.exception
# But modified to include full details of multiple exceptions and to provide output similar to
# https://github.com/sj26/rspec_junit_formatter
@output_hash[:examples] = example_notification.notifications.map do |notification|
format_example(notification.example).tap do |hash|
e = notification.example.exception
if e
exceptions = e.respond_to?(:all_exceptions) ? e.all_exceptions : [e]
hash[:exceptions] = exceptions.map do |exception|
{
class: exception.class.name,
message: exception.message,
backtrace: exception.backtrace
message_lines: strip_ansi_codes(notification.message_lines),
backtrace: notification.formatted_backtrace
}
end
end
......@@ -60,6 +62,12 @@ module QA
metadata[:shared_group_inclusion_backtrace].last.formatted_inclusion_location.split(':')
end
end
def strip_ansi_codes(strings)
# The code below is from https://github.com/piotrmurach/pastel/blob/master/lib/pastel/color.rb
modified = Array(strings).map { |string| string.dup.gsub(/\x1b\[{1,2}[0-9;:?]*m/m, '') }
modified.size == 1 ? modified[0] : modified
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment