0

I would like a way to take an error generated within a specific test method inside a Test::Unit::TestCase and turn it into a failure with a more friendly generic message. I keep thinking this should be possible with some inheritance but I can't quite get my head around it.

class CalenderTest001 < Test::Unit::TestCase
  def testZoneCal001
    Fixture.reset
    $driver = Selenium::WebDriver.for :firefox
    $driver.get "http://myTestSite.com/"
    $driver.find_element(:id, "IDthrowsAnError").click
  end
end

The effect I would like is to have the entire thing wrapped in a begin rescue end block with the rescue block looking something like this.

rescue Selenium::WebDriver::Error::NoSuchElementError => e
  #mark this test as a failure not an error
Zach
  • 885
  • 2
  • 8
  • 27

1 Answers1

0

You can use the assert_nothing_raised construct:

def testZoneCal001
  assert_nothing_raised "Something went wrong!" do
    Fixture.reset
    $driver = Selenium::WebDriver.for :firefox
    $driver.get "http://myTestSite.com/"
    $driver.find_element(:id, "IDthrowsAnError").click
  end
end
Yossi
  • 11,778
  • 2
  • 53
  • 66
  • I would like to make the test case and the test report more readable to people who didn't write the test. I would need to catch that specific error, and it would help if I didn't actually have to wrap every single test in a do end block. It seems like there should be a way to DRY this out. – Zach Sep 17 '13 at 21:05