From: Daniel Berger Date: 2009-02-27T01:38:28+09:00 Subject: Re: Rake post test task On Thu, Feb 19, 2009 at 1:34 PM, Tim Pease wrote: > > 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. Interestingly, I discovered that the Rake::Task.execute approach you suggested broke with Rake 0.8.1. It worked fine after I upgraded to 0.8.3. Don't ask me how I forgot to upgrade Rake on this particular system, but there you go. Regards, Dan