From: Saynatkari Date: 2005-05-07T06:16:46+09:00 Subject: Re: Typo-checking instead of static typing Le 6/5/2005, "Ben Giddings" a �crit: >On Wednesday 04 May 2005 15:36, Joost Diepenmaat wrote: >> On Thu, May 05, 2005 at 03:49:30AM +0900, Ben Giddings wrote: >> [ snip ] >> >> > def do_something(foo) >> > if foo > 500 >> > puts "Whoa, #{fo} is too many times! I can't do that!" >> > else >> > foo.times { |i| puts i } >> > end >> > end >> > >> > do_something(ARGV[0]) >> >> Use a code coverage tool to run over your unit tests, and fix your >> tests to go to 100% coverage. That's what I usually try to do in Perl >anyway. >> >> Pointers to coverage tools for ruby anyone? > >I sent an email reply to this, but nobody followed up, but I'm really >interested to hear the answer. I have a feeling I am answering to the wrong person, but: Did you try Ryan Davis' zentest[1]? It automatically generates tests for an existing codebase and should even take into account any existing tests. I have not used it extensively but it might be a good starting point? >The suggestion here was to write unit tests to make sure that the line with >the typo is caught ("Whoa, #{fo} ..." instead of "Whoa, #{foo} ...") > >My question is this. If the "Ruby Way" to find this bug is by unit tests, >what suite of tests would be recommended for this snippet of code? Keep >in mind, that the original code is only 8 lines long. > >Is it realistic to expect that someone would write more than 8 lines of >unit tests? > >Ben E [1] http://www.zenspider.com/ZSS/Products/ZenTest/ -- template void quack(duck& d) { d.quack(); }