Skip to content

Instantly share code, notes, and snippets.

@martinos
Created January 28, 2013 22:56
Show Gist options
  • Save martinos/4660071 to your computer and use it in GitHub Desktop.
Save martinos/4660071 to your computer and use it in GitHub Desktop.
For testing io stdin and stdout interaction.
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