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

Commit bf35a38

Browse files
committed
Load exception presentation sub-system lazily
1 parent b98c638 commit bf35a38

File tree

3 files changed

+2
-6
lines changed

3 files changed

+2
-6
lines changed

lib/rspec/core/formatters.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ module RSpec::Core::Formatters
7373
autoload :ProfileFormatter, 'rspec/core/formatters/profile_formatter'
7474
autoload :JsonFormatter, 'rspec/core/formatters/json_formatter'
7575
autoload :BisectFormatter, 'rspec/core/formatters/bisect_formatter'
76+
autoload :ExceptionPresenter, 'rspec/core/formatters/exception_presenter'
7677

7778
# Register the formatter class
7879
# @param formatter_class [Class] formatter class to register

lib/rspec/core/formatters/exception_presenter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: utf-8
2+
RSpec::Support.require_rspec_core "formatters/snippet_extractor"
23
RSpec::Support.require_rspec_support "encoded_string"
34

45
module RSpec
@@ -203,7 +204,6 @@ def read_failed_lines
203204

204205
file_path, line_number = matching_line.match(/(.+?):(\d+)(|:\d+)/)[1..2]
205206
max_line_count = RSpec.configuration.max_displayed_failure_line_count
206-
RSpec::Support.require_rspec_core "formatters/snippet_extractor"
207207
SnippetExtractor.extract_expression_lines_at(file_path, line_number.to_i, max_line_count)
208208
rescue SnippetExtractor::NoSuchFileError
209209
["Unable to find #{file_path} to read failed line"]

spec/rspec/core/formatters/exception_presenter_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,6 @@ def read_failed_lines
404404
context "when backtrace will generate a security error" do
405405
let(:exception) { instance_double(Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"]) }
406406

407-
before do
408-
# We lazily require SnippetExtractor but requiring it in $SAFE 3 environment raises error.
409-
RSpec::Support.require_rspec_core "formatters/snippet_extractor"
410-
end
411-
412407
it "is handled gracefully" do
413408
with_safe_set_to_level_that_triggers_security_errors do
414409
expect { read_failed_lines }.not_to raise_error

0 commit comments

Comments
 (0)