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

Commit

Permalink
Load exception presentation sub-system lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinakayama committed Oct 23, 2015
1 parent 5c3ea5a commit be71fe5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/rspec/core/formatters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module RSpec::Core::Formatters
autoload :ProfileFormatter, 'rspec/core/formatters/profile_formatter'
autoload :JsonFormatter, 'rspec/core/formatters/json_formatter'
autoload :BisectFormatter, 'rspec/core/formatters/bisect_formatter'
autoload :ExceptionPresenter, 'rspec/core/formatters/exception_presenter'

# Register the formatter class
# @param formatter_class [Class] formatter class to register
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/formatters/exception_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
RSpec::Support.require_rspec_core "formatters/snippet_extractor"
RSpec::Support.require_rspec_support "encoded_string"

module RSpec
Expand Down Expand Up @@ -203,7 +204,6 @@ def read_failed_lines

file_path, line_number = matching_line.match(/(.+?):(\d+)(|:\d+)/)[1..2]
max_line_count = RSpec.configuration.max_displayed_failure_line_count
RSpec::Support.require_rspec_core "formatters/snippet_extractor"
SnippetExtractor.extract_expression_lines_at(file_path, line_number.to_i, max_line_count)
rescue SnippetExtractor::NoSuchFileError
["Unable to find #{file_path} to read failed line"]
Expand Down
5 changes: 0 additions & 5 deletions spec/rspec/core/formatters/exception_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,6 @@ def read_failed_lines
context "when backtrace will generate a security error" do
let(:exception) { instance_double(Exception, :backtrace => [ "#{__FILE__}:#{__LINE__}"]) }

before do
# We lazily require SnippetExtractor but requiring it in $SAFE 3 environment raises error.
RSpec::Support.require_rspec_core "formatters/snippet_extractor"
end

it "is handled gracefully" do
with_safe_set_to_level_that_triggers_security_errors do
expect { read_failed_lines }.not_to raise_error
Expand Down

0 comments on commit be71fe5

Please sign in to comment.