Created
December 13, 2013 07:12
-
-
Save pinzolo/7940841 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
require "stringio" | |
def capture(stream) | |
begin | |
stream = stream.to_s | |
eval "$#{stream} = StringIO.new" | |
yield | |
result = eval("$#{stream}").string | |
ensure | |
eval "$#{stream} = #{stream.upcase}" | |
end | |
result | |
end | |
describe Foo do | |
it "output should be 'bar'" do | |
output = capture(:stdout) do | |
baz # test method | |
end | |
expect(output).to eq 'bar' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment