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

Commit 53e09e4

Browse files
davidtaylorhqpirj
authored andcommitted
Reduce indentation of Core::Formatters#formatted_cause
Moves the `supports_exception_cause?` check inside the method, so that overall indentation can be reduced by one step, and thereby satisfy Rubocop.
1 parent baf3b95 commit 53e09e4

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

lib/rspec/core/formatters/exception_presenter.rb

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

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
44+
def formatted_cause(exception)
45+
return [] unless RSpec::Support::RubyFeatures.supports_exception_cause?
5746

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
47+
last_cause = final_exception(exception, [exception])
48+
cause = []
6149

62-
lines.each do |line|
63-
cause << (" #{line}")
64-
end
65-
end
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}"
6657
end
6758

68-
cause
69-
end
70-
else
71-
# :nocov:
72-
def formatted_cause(_)
73-
[]
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
62+
63+
lines.each do |line|
64+
cause << (" #{line}")
65+
end
66+
end
7467
end
75-
# :nocov:
68+
69+
cause
7670
end
7771

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

0 commit comments

Comments
 (0)