From: dblack@... Date: 2006-09-22T19:57:02+09:00 Subject: Re: Continue code run after assert exception Hi -- On Fri, 22 Sep 2006, aidy wrote: > I am iterating through a collection and using Test::Unit assertations > on each object > > begin > search.each {|@x| > assert($ie.contains_text(@x)) } > rescue => e > puts "#{@x} does not exist in HTML" > end > > However, the problem is that if the first assertation is false, an > exception is thrown and my loop terminates. I would like to continue > the loop after an exception is thrown. I have tried 'retry', but I find > myself in an infinite loop. You can put the begin/rescue/end inside your loop, like this: [1,2,3].each do |x| begin raise unless x == 2 rescue puts "No! #{x}" end end Also, you might find the asserts_raises method useful. It lets you predict that something will raise an exception. It probably wouldn't be a good fit with the loop structure you're using, but you could isolate some exception-raising tests and test them that way. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org