From: Tim Pease Date: 2009-02-20T05:34:31+09:00 Subject: Re: Rake post test task On Feb 18, 2009, at 10:06 PM, Ryan Davis wrote: > > 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: > The Rake::Task#execute method will always run the task regardless of whether it has been run previously. You are thinking of the Rake::Task#invoke method -- this method ensures the task is only executed once. Blessings, TwP