From: Eric Hodel Date: 2006-09-09T08:51:13+09:00 Subject: Re: Unit test an output with puts On Sep 8, 2006, at 12:29 PM, Eric Boucher wrote: > I want to be able to unit/test an output with the method 'puts'. > Here's > a small example of what I'm trying to achieve: Use util_capture from the ZenTest gem. You get two StringIO objects back from calling util_capture that hold the contents of $stdout and $stderr in the block: require 'test/unit' require 'rubygems' require 'test/zentest_assertions' class Foo def output puts "bar" end end class TestFoo < Test::Unit::TestCase def test_output out, err = util_capture do Foo.new.output end assert_equal "bar\n", out.string assert_equal "", err.string end end -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com