From: "Jon A. Lambert" Date: 2005-05-07T09:51:48+09:00 Subject: Re: Typo-checking instead of static typing Ben Giddings wrote: > On Friday 06 May 2005 15:09, Ryan Leavengood wrote: >> Absolutely. In fact, this should be the norm. When you consider edge >> cases and a good sampling of non-edge cases, the unit test can >> quickly outgrow the code being tested. >> >> It may seem like a lot of work, but that work continues to pay off >> everytime you run the tests, especially after code changes or >> refactorings. > > Ok, so in this case, what would the unit tests be? > > Ben This one is rather tricky. I assume your do_something is part of a Foo class. I then do a hack to mock up puts to put it in a global So your tests might look like this: require 'test/unit' require 'Foo' class Foo def puts(x) $x << x.to_s << "\n" end end class TestFoo < Test::Unit::TestCase def setup @f = Foo.new $x = "" end def test_do_something_0 @f.do_something(0) assert_equal("",$x) end def test_do_something_3 @f.do_something(3) assert_equal("0\n1\n2\n",$x) end def test_do_something_501 @f.do_something(501) assert_equal("Whoa, 501 is too many times! I can't do that!\n",$x) end def test_do_something_nil @f.do_something(nil) assert_equal("",$x) end end There may be an easier way. *shrug* -- J. Lambert