test/helper.rb in cri-2.0a3 vs test/helper.rb in cri-2.0b1

- old
+ new

@@ -2,25 +2,43 @@ require 'stringio' class Cri::TestCase < MiniTest::Unit::TestCase - def capture_io_while(&block) - $orig_stdout = $stdout - $orig_stderr = $stderr + def setup + @orig_io = capture_io + end - $stdout = StringIO.new - $stderr = StringIO.new + def teardown + uncapture_io(*@orig_io) + end + def capture_io_while(&block) + orig_io = capture_io block.call - [ $stdout.string, $stderr.string ] ensure - $stdout = $orig_stdout - $stderr = $orig_stderr + uncapture_io(*orig_io) end def lines(string) string.scan(/^.*\n/).map { |s| s.chomp } + end + +private + + def capture_io + orig_stdout = $stdout + orig_stderr = $stderr + + $stdout = StringIO.new + $stderr = StringIO.new + + [ orig_stdout, orig_stderr ] + end + + def uncapture_io(orig_stdout, orig_stderr) + $stdout = orig_stdout + $stderr = orig_stderr end end