Search code examples
rubyunit-testingjruby

Is it possible to catch exceptions in ruby thrown over an entire class


I have test classes that inherit a class that inherits Test::Unit::TestCase. I overwrote the assertions so that I get output to a junit style test report for use in bamboo and jenkins. This works fine.

Now I want to catch exceptions if they occur throughout the test classes from setup, through multiple testcases and onto teardown. Outside putting in begin/resucue/end blocks in all the methods is there an easier way to do this?


Solution

  • there is but you need to dig (and understand some of the) Test::Unit internals. what you're trying to achieve is probably easiest done by patching/replacing the Test::Unit::TestCase#run method with your own. be aware that this might break between versions so be sure to make patching "smart".