diff --git a/lib/rspec/matchers/built_in/output.rb b/lib/rspec/matchers/built_in/output.rb index b4b168d7c..024bca0d2 100644 --- a/lib/rspec/matchers/built_in/output.rb +++ b/lib/rspec/matchers/built_in/output.rb @@ -1,5 +1,4 @@ require 'stringio' -require 'tempfile' module RSpec module Matchers @@ -172,6 +171,14 @@ def self.capture(block) # @private class CaptureStreamToTempfile < Struct.new(:name, :stream) def capture(block) + # We delay loading tempfile until it is actually needed because + # we want to minimize stdlibs loaded so that users who use a + # portion of the stdlib can't have passing specs while forgetting + # to load it themselves. `CaptureStreamToTempfile` is rarely used + # and `tempfile` pulls in a bunch of things (delegate, tmpdir, + # thread, fileutils, etc), so it's worth delaying it until this point. + require 'tempfile' + original_stream = stream.clone captured_stream = Tempfile.new(name) diff --git a/spec/rspec/expectations_spec.rb b/spec/rspec/expectations_spec.rb index f79a485fa..3ab20c1e3 100644 --- a/spec/rspec/expectations_spec.rb +++ b/spec/rspec/expectations_spec.rb @@ -9,10 +9,8 @@ 'require "rspec/expectations"' ], :allowed_loaded_feature_regexps => [ - /stringio/, /tempfile/, # Used by `output` matcher. Can't be easily avoided. - /delegate/, /tmpdir/, /thread/, # required by tempfile - /fileutils/, /etc/, # required by tmpdir - /prettyprint.rb/, /pp.rb/ # required by rspec-support + /stringio/, # Used by `output` matcher. Can't be easily avoided. + /prettyprint.rb/, /pp.rb/ # required by rspec-support ] it 'does not allow expectation failures to be caught by a bare rescue' do