1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
# frozen_string_literal: true
require 'minitest'
require 'minitest/autorun'
require 'cri'
require 'stringio'
module Cri
class TestCase < Minitest::Test
def setup
@orig_io = capture_io
end
def teardown
uncapture_io(*@orig_io)
end
def capture_io_while
orig_io = capture_io
yield
[$stdout.string, $stderr.string]
ensure
uncapture_io(*orig_io)
end
def lines(string)
string.scan(/^.*\n/).map(&: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
end
# Unexpected system exit is unexpected
::Minitest::Test::PASSTHROUGH_EXCEPTIONS.delete(SystemExit)
|