From: Robert Klemme Date: 2008-03-29T01:30:04+09:00 Subject: Re: boolean and logging On 28.03.2008 15:58, testautomated6@googlemail.com wrote: > Hi, > > I use Ruby and Watir > > I have a method: > > def does_the_html_include(target) > puts "HTML text of #{target} is being verified" > if target.kind_of? String > return $browser.text.include?(target) > elsif target.kind_of? Regexp > return $browser.text.match(target) > end > end > > > I wrap this up in a logger > > def test_results(result, *msg) > #make true explicit, everything else I am seeing as a failure > if result == true This is a very bad idea, as only false and nil are false. Your code above will especially break with the test because the regexp match will either return nil or a MatchData object - which both will make "result == true" false. > test_status = @test.add_element 'teststatus' > test_status.text = 'PASS' > else > fail = @test.add_element 'teststatus' > fail.text = 'FAIL' > fail_msg = @test.add_element 'failmessage' > fail_msg.text = msg > end > end > > > However, when I don't want HTML text to appear, eg: an error. I want > to do something better than this > > boolean = does_the_html_include('You appear to have an active > account') > $test.test_results(!boolean, 'already have registered account') I am not sure what exactly it is that you want to improve. Do you dislike the local variable? def test_results(msg) if yield # test ok else # not ok end end test_results "foo" { does_the_html_include('You appear to have an active account') } Cheers robert