I solved this by directing my output to a StringIO object instead of STDOUT:
> output = StringIO.new#<StringIO:0x007fcb28629030>> output.puts('hi')nil> output.string"hi\n"
STDOUT accepts strings, it does not provide strings. You can write to it, but cannot read from it.
STDOUT
STDOUT.write("hello") # => helloSTDOUT.read # => IOError: not opened for reading