From: Gregory Brown Date: 2007-05-21T23:49:37+09:00 Subject: Re: Need some help.. On 5/21/07, Disha Tamhane wrote: > Thanks Gregory.... Guess this will work now... > > But just to check.. will it not work if it is not enclosed in a method? > > Is there an alternative way? Usually you will want to structure your code so it is most easily testable. For example, if you were using system() because you wanted to test the output to the screen, you can still test that. Here's a small example def hello(out=STDOUT) out.puts "Hello World" end If you were to call that, just as hello(), it'd print to the screen. But say you wanted to test it, you could use StringIO. #------ require "stringio" require "test/unit" class HelloTest < Test::Unit::TestCase def test_hello out = StringIO.new hello(out) out.rewind assert_equal "Hello World\n", out.read end end #---- In general, this makes your code more well organized and easier to work with. If you want to do good testing, it pretty much means you'll need to structure your code so it can be tested :)