Created
April 18, 2016 06:06
-
-
Save kshimi/b9cd5ea0e0934b2038bfc3abc674c4fc to your computer and use it in GitHub Desktop.
Test with STDIO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
class TestMyClass < Minitest::Test | |
def setup | |
@orig_stdin = $stdin | |
@in = StringIO.new | |
$stdin = @in | |
end | |
def teardown | |
$stdin = @orig_stdin | |
end | |
def test_5 | |
@in << <<'EOS' | |
5 | |
EOS | |
@in.rewind | |
out, err = capture_io do | |
load("sample.rb") | |
end | |
assert_equal "5\n", out | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment