From: kwa@... (makotz) Date: 2003-03-26T09:45:21+09:00 Subject: [Q] changing a stream of 'print' method to a string Hi, I have a question. How to change a stream of 'print' to a string? Is it able? Background: I want to test my program which print data to standard output. And I have no good idea to test output data. ---------------------------------------- ## ## main.rb ## def print_list(list) list.each_with_index do |item, index| print "#{index+1}: #{item}\n" end end ---------------------------------------- ---------------------------------------- ## ## test program ## require 'main' require 'runit/testcase' require 'runit/cui/testrunner' class MainTest < RUNIT::TestCase def test_print_list list = [10, 20, 30] print_list(list) # <== how to test? end end testcases = MainTest.test_cases() RUNIT::CUI::TestRunner.run(testcases) ---------------------------------------- If I could change a stream of print to a string, I would write it like the following: ---------------------------------------- ...(snip)... def test_print_list list = [10, 20, 30] expected = <