How can I set the rcov task if the subtask fails?

I have this task:

task :all => ['foo', 'bar', 'announce_success']

If foothey bardo not create exceptions, then it announce_successhappens. How can I perform a specific task or block of code if they make exceptions?

+3
source share
2 answers

The way you defined your tasks will cause rake to exit as soon as one of the dependencies completes with an error / calls and exception. This is the main functionality of the rake.

One way around this is to do something like

task :all do
 task :tmp => ['foo','bar']
 begin 
   Rake::Task[:tmp].invoke
 rescue
  #do something with the exception
 end
end
+1
source

Unfortunately, this goes against the grain of rake.

Ruby at_exit, , , Rake . rake-tasks at_exit hook :

  task :cleanup do
    at_exit {
      # cleanup code here
    }
  end 

, :cleanup .

+1

All Articles