Created
May 24, 2011 12:49
-
-
Save parndt/988650 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def capture_stdout(stdin_str = '') | |
begin | |
require 'stringio' | |
$o_stdin, $o_stdout, $o_stderr = $stdin, $stdout, $stderr | |
$stdin, $stdout, $stderr = StringIO.new(stdin_str), StringIO.new, StringIO.new | |
yield | |
{:stdout => $stdout.string, :stderr => $stderr.string} | |
ensure | |
$stdin, $stdout, $stderr = $o_stdin, $o_stdout, $o_stderr | |
end | |
end |
Looks like they're from the same place then http://rails-bestpractices.com/questions/1-test-stdin-stdout-in-rspec ;-)
Whoaaa!!! :P
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I sualy use this snippet: https://gist.github.com/988657