lib/minitest/assertions.rb in spec-5.0.19 vs lib/minitest/assertions.rb in spec-5.3.3

- old
+ new

@@ -4,11 +4,11 @@ ## # Minitest Assertions. All assertion methods accept a +msg+ which is # printed if the assertion fails. # # Protocol: Nearly everything here boils up to +assert+, which - # expects to be able to increment an instance variable named + # expects to be able to increment an instance accessor named # +assertions+. This is not provided by Assertions and must be # provided by the thing including Assertions. See Minitest::Runnable # for an example. module Assertions @@ -129,10 +129,14 @@ raise Minitest::Assertion, msg end true end + def _synchronize # :nodoc: + yield + end + ## # Fails unless +obj+ is empty. def assert_empty obj, msg = nil msg = message(msg) { "Expected #{mu_pp(obj)} to be empty" } @@ -391,10 +395,12 @@ # NOTE: For efficiency, this method uses StringIO and does not # capture IO for subprocesses. Use #capture_subprocess_io for # that. def capture_io + _synchronize do + begin require 'stringio' captured_stdout, captured_stderr = StringIO.new, StringIO.new orig_stdout, orig_stderr = $stdout, $stderr @@ -404,10 +410,12 @@ return captured_stdout.string, captured_stderr.string ensure $stdout = orig_stdout $stderr = orig_stderr + end + end end ## # Captures $stdout and $stderr into strings, using Tempfile to # ensure that subprocess IO is captured as well. @@ -422,10 +430,12 @@ # # NOTE: This method is approximately 10x slower than #capture_io so # only use it when you need to test the output of a subprocess. def capture_subprocess_io + _synchronize do + begin require 'tempfile' captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err") orig_stdout, orig_stderr = $stdout.dup, $stderr.dup @@ -441,9 +451,11 @@ ensure captured_stdout.unlink captured_stderr.unlink $stdout.reopen orig_stdout $stderr.reopen orig_stderr + end + end end ## # Returns details for exception +e+