From: Ryan Davis Date: 2009-02-19T14:06:07+09:00 Subject: Re: Rake post test task On Feb 18, 2009, at 07:15 , Daniel Berger wrote: > How do I run a task after the fact with Rake? > > For example, I have a test task for a C extension. It looks something > like this: > > Rake::TestTask.new('test') do |test| > task :test => [:build] > test.libs << 'ext' > test.warning = true > test.verbose = true > end > > That works fine, but I'd like it to run the "clean" task after it's > finished. > > And no, simply sticking "task :test => [:clean]" at the bottom of the > test task doesn't work. task :test => :clean DOES work, just _before_ the fact, not after. to do after you attach another task to the same name: task :test do after end One problem with Tim's suggestion: > task :test do > Rake.application[:clean].execute > end is that it won't run if that dependency has already been met, so: % rake clean test won't run it after your test. You might prefer to do: > task :test do > sh "rake clean" > end instead. ---- that said... why are you cleaning afterwards? I can imagine a number of situations where that will screw you up. You probably DO want to put :clean (pre) dependencies on a number of your tasks like packaging and stuff, but having it after your test could introduce some hiccups. if it is a lengthy build/link, it'll also slow down code/test cycles.