Created
December 22, 2010 00:44
-
-
Save timlinquist/750899 to your computer and use it in GitHub Desktop.
Ripped from John Nunemaker's whois gem
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 Helpers | |
module Output | |
def assert_output(expected, &block) | |
keep_stdout do |stdout| | |
block.call | |
if expected.is_a?(Regexp) | |
assert_match expected, stdout.string | |
else | |
assert_equal expected.to_s, stdout.string | |
end | |
end | |
end | |
def keep_stdout(&block) | |
begin | |
orig_stream, $stdout = $stdout, StringIO.new | |
block.call($stdout) | |
ensure | |
s, $stdout = $stdout.string, orig_stream | |
s | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment