From: Rick DeNatale Date: 2009-02-20T02:07:49+09:00 Subject: Re: Rake post test task --0016362836896445ec046348945d Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Thu, Feb 19, 2009 at 12:06 AM, 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 The after here is a placeholder for code, right? It can't be a task name since a task does not define a method which can be invoked like that, at least not with the Rake I've got installed on my maching. Unless I'm missing something this is effectively the same thing as one :test task with the code from both inside the block. It works but... > > 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. > The way I'd approach this would be to have tasks for whatever sequences of subtasks make sense, so something like: desc "clean up" task :clean do |t| puts "cleaning up" end desc "test" task :test do |t| puts "testing" end desc "test and clean up" task :test_and_cleanup => [:test, :clean] desc "clean up then test" task :cleanup_and_test => [:clean, :test] Task names could be adjusted, so if you wanted to normally clean up and then test, or test and then clean up you could rename the 'normal' task, .e.g :test becomes something like :test_only and :cleanup_and_test becomes :test -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale --0016362836896445ec046348945d--