Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Created December 13, 2013 07:12
Show Gist options
  • Save pinzolo/7940841 to your computer and use it in GitHub Desktop.
Save pinzolo/7940841 to your computer and use it in GitHub Desktop.
コンソールに文字を出力する処理を検証する
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