Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
fixup! Dynamically def method depending on features
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Jan 25, 2024
1 parent 53e09e4 commit a1f5420
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions lib/rspec/core/formatters/exception_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,38 @@ def formatted_backtrace(exception=@exception)
formatted_cause(exception)
end

def formatted_cause(exception)
return [] unless RSpec::Support::RubyFeatures.supports_exception_cause?

last_cause = final_exception(exception, [exception])
cause = []

if exception.cause
cause << '------------------'
cause << '--- Caused by: ---'
cause << "#{exception_class_name(last_cause)}:" unless exception_class_name(last_cause) =~ /RSpec/

encoded_string(exception_message_string(last_cause)).split("\n").each do |line|
cause << " #{line}"
end
if RSpec::Support::RubyFeatures.supports_exception_cause?
def formatted_cause(exception)
last_cause = final_exception(exception, [exception])
cause = []

if exception.cause
cause << '------------------'
cause << '--- Caused by: ---'
cause << "#{exception_class_name(last_cause)}:" unless exception_class_name(last_cause) =~ /RSpec/

encoded_string(exception_message_string(last_cause)).split("\n").each do |line|
cause << " #{line}"
end

unless last_cause.backtrace.nil? || last_cause.backtrace.empty?
lines = backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata)
lines = [lines[0]] unless RSpec.configuration.full_cause_backtrace
unless last_cause.backtrace.nil? || last_cause.backtrace.empty?
lines = backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata)
lines = [lines[0]] unless RSpec.configuration.full_cause_backtrace

lines.each do |line|
cause << (" #{line}")
lines.each do |line|
cause << (" #{line}")
end
end
end
end

cause
cause
end
else
# :nocov:
def formatted_cause(_)
[]
end
# :nocov:
end

def colorized_formatted_backtrace(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
Expand Down

0 comments on commit a1f5420

Please sign in to comment.