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

Commit a1f5420

Browse files
committed
fixup! Dynamically def method depending on features
1 parent 53e09e4 commit a1f5420

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

lib/rspec/core/formatters/exception_presenter.rb

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,38 @@ def formatted_backtrace(exception=@exception)
4141
formatted_cause(exception)
4242
end
4343

44-
def formatted_cause(exception)
45-
return [] unless RSpec::Support::RubyFeatures.supports_exception_cause?
46-
47-
last_cause = final_exception(exception, [exception])
48-
cause = []
49-
50-
if exception.cause
51-
cause << '------------------'
52-
cause << '--- Caused by: ---'
53-
cause << "#{exception_class_name(last_cause)}:" unless exception_class_name(last_cause) =~ /RSpec/
54-
55-
encoded_string(exception_message_string(last_cause)).split("\n").each do |line|
56-
cause << " #{line}"
57-
end
44+
if RSpec::Support::RubyFeatures.supports_exception_cause?
45+
def formatted_cause(exception)
46+
last_cause = final_exception(exception, [exception])
47+
cause = []
48+
49+
if exception.cause
50+
cause << '------------------'
51+
cause << '--- Caused by: ---'
52+
cause << "#{exception_class_name(last_cause)}:" unless exception_class_name(last_cause) =~ /RSpec/
53+
54+
encoded_string(exception_message_string(last_cause)).split("\n").each do |line|
55+
cause << " #{line}"
56+
end
5857

59-
unless last_cause.backtrace.nil? || last_cause.backtrace.empty?
60-
lines = backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata)
61-
lines = [lines[0]] unless RSpec.configuration.full_cause_backtrace
58+
unless last_cause.backtrace.nil? || last_cause.backtrace.empty?
59+
lines = backtrace_formatter.format_backtrace(last_cause.backtrace, example.metadata)
60+
lines = [lines[0]] unless RSpec.configuration.full_cause_backtrace
6261

63-
lines.each do |line|
64-
cause << (" #{line}")
62+
lines.each do |line|
63+
cause << (" #{line}")
64+
end
6565
end
6666
end
67-
end
6867

69-
cause
68+
cause
69+
end
70+
else
71+
# :nocov:
72+
def formatted_cause(_)
73+
[]
74+
end
75+
# :nocov:
7076
end
7177

7278
def colorized_formatted_backtrace(colorizer=::RSpec::Core::Formatters::ConsoleCodes)

0 commit comments

Comments
 (0)