I’m using Test::Unit::TestCase to write some unit tests. Currently, I have a setup function that moves and modifies some fixture files and folders on disk. (This is a necessary evil at the moment.) If a test crashes, the teardown method doesn’t get called, leaving files and folders in the way. The next time I run a test, it complains that such-and-such a folder already exists (Errno::EEXIST), making me have to stop and get rid of the left-over files.
How do I ensure that teardown is always run? (ensure is the same idea as finally in some other languages.)
What about making your
setup()do some cleanup so that it works even if the file still exists ?