From: Jim Weirich Date: 2006-04-06T06:09:06+09:00 Subject: Re: Rake: Making "cleanup" task Pistos Christou wrote: > I'm just getting my feet wet with Rake, at least as far as running unit > tests is concerned. > > I have some initializer and cleanup stuff that I'd like run before and > after ANY rake task (all of which are TestTasks in my case). I'm using > the dependency method to setup the initializer, which is fine, but I > don't know how to get my cleanup task to run, since rake aborts at the > first test failure. > > I basically need the rake-task equivalent of Ruby's "ensure". > > Is this possible? If so, how? :) There's no direct way to do this in Rake task, but you can always wrap your task in begin/ensure/end yourself. For example: task :test do begin ruby 'test_example.rb' ensure puts "OK" end end will always print "OK", even if the tests fail. Unfortunately, the built-in test task does not have any hooks for this, but it its not hard to roll your own in this case. -- -- Jim Weirich -- Posted via http://www.ruby-forum.com/.