module GeneratorSpec::GeneratorExampleGroup::InstanceMethods
def capture(stream)
stream # => "Cool\n"
stream = capture(:stdout){ puts "Cool" }
Captures the given stream and returns it:
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