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

Commit 4355f3d

Browse files
committed
Memoize exception_lines in ExceptionPresenter
The method failure_lines uses exception_lines 3 times, which uses exception.message. In some situation, exception.message can be slow (when inspect is called on a big object for example). Without caching, this delay which can become considerable will be amplified by 3x.
1 parent 24e5b7b commit 4355f3d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/rspec/core/formatters/exception_presenter.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,14 @@ def failure_slash_error_lines
175175
end
176176

177177
def exception_lines
178-
lines = []
179-
lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/
180-
encoded_string(exception.message.to_s).split("\n").each do |line|
181-
lines << (line.empty? ? line : " #{line}")
178+
@exception_lines ||= begin
179+
lines = []
180+
lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/
181+
encoded_string(exception.message.to_s).split("\n").each do |line|
182+
lines << (line.empty? ? line : " #{line}")
183+
end
184+
lines
182185
end
183-
lines
184186
end
185187

186188
def extra_failure_lines

0 commit comments

Comments
 (0)