Skip to content

Instantly share code, notes, and snippets.

@parndt
Created May 24, 2011 12:49
Show Gist options
  • Save parndt/988650 to your computer and use it in GitHub Desktop.
Save parndt/988650 to your computer and use it in GitHub Desktop.
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
@LeipeLeon
Copy link

I sualy use this snippet: https://gist.github.com/988657

@parndt
Copy link
Author

parndt commented May 24, 2011

Looks like they're from the same place then http://rails-bestpractices.com/questions/1-test-stdin-stdout-in-rspec ;-)

@LeipeLeon
Copy link

Whoaaa!!! :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment