Skip to content

Instantly share code, notes, and snippets.

@kshimi
Created April 18, 2016 06:06
Show Gist options
  • Save kshimi/b9cd5ea0e0934b2038bfc3abc674c4fc to your computer and use it in GitHub Desktop.
Save kshimi/b9cd5ea0e0934b2038bfc3abc674c4fc to your computer and use it in GitHub Desktop.
Test with STDIO
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