Skip to content

Instantly share code, notes, and snippets.

@timlinquist
Created December 22, 2010 00:44
Show Gist options
  • Save timlinquist/750899 to your computer and use it in GitHub Desktop.
Save timlinquist/750899 to your computer and use it in GitHub Desktop.
Ripped from John Nunemaker's whois gem
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