From: Eric Boucher Date: 2006-09-11T00:24:26+09:00 Subject: Re: Unit test an output with puts Thanks everybody and thanks to Eric, this is exactly what I needed. On Saturday, September 09, 2006, at 8:51 AM, Eric Hodel wrote: >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 > > > -- Posted with http://DevLists.com. Sign up and save your mailbox.