Created
January 28, 2013 22:56
-
-
Save martinos/4660071 to your computer and use it in GitHub Desktop.
For testing io stdin and stdout interaction.
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
module SpecHelper | |
def local_io(in_str) | |
old_stdin, old_stdout = $stdin, $stdout | |
$stdin = StringIO.new(in_str) | |
$stdout = StringIO.new | |
yield | |
$stdout.string | |
ensure | |
$stdin, $stdout = old_stdin, old_stdout | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment