From: Disha Tamhane Date: 2007-05-21T23:08:55+09:00 Subject: Re: Need some help.. ------=_Part_103445_8872200.1179756533755 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hey Gregory, Thanks for your response. Following is the code snippet that i am trying to test : basedir = ARGV[0] if (ARGV[0]) contains = Dir.new(basedir).entries for file in contains if (file != "." && file !="..") tokens = file.split("-"); model = tokens[0] tokens1 = tokens[2].split(".xm") dealer = tokens1[0] puts model + "," + dealer + "," + basedir + "/" + file getallocprsr = GetAllocationsParser.new getallocprsr.parsefile(basedir + "/" + file) sql = "UPDATE Validations set getAlloc = " + getallocprsr.allocation.to_s sql = sql + " where DealerName like '" + dealer + "' and Vehicleline like '" + model + "'" puts sql db.updateQuery(sql) end end else puts "Usage :" puts "" puts "$> ruby a.rb " puts "" puts "basedir : This is the base directory where the getAllocations responses" puts " can be found" puts "" end db.close Thanks, Disha On 5/21/07, Gregory Brown wrote: > > On 5/21/07, Disha Tamhane wrote: > > Hi, > > > > I have a script in one file say "a.rb". > > I have another file "tc_a.rb" which is a test case for "a.rb" > > I have called a specific script in "a.rb" by using the system() command > from > > "tc_a.rb" > > > > Now when i am using rcov to get the code coverage, although an if -else > > block in "a.rb" is getting executed, rcov doesn't seem to recognise > it... it > > still shows the block as not covered...May be because it is getting > called > > through the system command > > > > This particular if-else block is an independent one i.e. not present in > any > > method in "a.rb" > > > > I need to get this block covered... > > > > Can someone suggest a solution? > > Are you doing something like, taking arguments > > e.g: > > ARGV[0].do_something > > and you want to test this? > > if that's the case, split it up into a library / script combo, and > make the functions testable > > #--------- > > def do_it(arg) > arg.do_something > end > > if __FILE__ == $PROGRAM_NAME > do_it(ARGV[0]) > end > > #------ > > Now you can test the do_it method by just requiring the file. > if you do this cleanly enough, there won't be much left to test in your > script. > > ------=_Part_103445_8872200.1179756533755--