Skip to content

Commit

Permalink
Delay tempfile loading.
Browse files Browse the repository at this point in the history
(See comment for explanation about why we do this).
  • Loading branch information
myronmarston committed Feb 17, 2015
1 parent abf9555 commit 8fa0535
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lib/rspec/matchers/built_in/output.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'stringio'
require 'tempfile'

module RSpec
module Matchers
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 2 additions & 4 deletions spec/rspec/expectations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8fa0535

Please sign in to comment.