如何让 rcov 任务知道子任务是否失败?
我有这样的任务:
task :all => ['foo', 'bar', 'announce_success']
如果 foo
和 bar
不引发异常,那么 announce_success
就会发生。如果特定任务或代码块确实引发异常,我该如何执行它们?
I have this task:
task :all => ['foo', 'bar', 'announce_success']
If foo
and bar
don't raise exceptions, then announce_success
happens. How can I have a particular task or code block execute if they do raise exceptions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦依赖项之一失败/引发和异常,您定义任务的方式将导致 rake 退出。这是rake的核心功能。
解决方法之一是做类似的事情
The way you have defined your tasks will cause rake to exit as soon as one of the dependencies fails/raises and exception. This is the core functionality of rake.
One way to work around though is to do something like
不幸的是,这违背了 Rake 的原则。
Ruby 有一个
at_exit
挂钩,如果您想在 Rake 终止时运行一些清理工作,您可以向其中添加代码块。您可以将 rake-tasks 和 at_exit 挂钩组合起来,如下所示:只需确保
:cleanup
在依赖项列表的早期执行即可。Unfortunately that goes against the grain of Rake.
Ruby has an
at_exit
hook you can add a block of code to, if you want to run a bit of cleanup when Rake terminates. You can combine rake-tasks andat_exit
hook like this:Just make sure
:cleanup
is executed early in the list of dependencies.