guard-rails-assets/spec/support/stdout_helper.rb
2011-07-31 23:08:10 +01:00

17 lines
332 B
Ruby

require 'stringio'
module Helpers
def capture(*streams)
streams.map! { |stream| stream.to_s }
begin
result = StringIO.new
streams.each { |stream| eval "$#{stream} = result" }
yield
ensure
streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
end
result.string
end
end