標準出力される内容をテストする内容を調べたところ、素晴らしいエントリーを見つけたので忘れないようにメモ pochi's weblog # -*- coding: utf-8 -*- require "rspec" class Target def some_method(msg) print msg end end # this method is written by wycats 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 "Object#capture"