Rspec:失败后调用方法
我试图找出如何在每次失败后调用规范助手中的方法。我觉得问这个问题很糟糕,因为它似乎以前已经被问过,但对我来说有点无法谷歌,因为我发现的只是检测 after(:each) 中的失败。
基本上,我想给自己设置一个通知,例如:
def you_failed
system "say -v Bad test failed"
end
I'm trying to find out how to call a method in a spec helper after each failure. I feel bad asking this question because it seems like it'd have been asked before, but it's sort of unGoogleable to me since all I find is detecting failures in after(:each).
Basically, I want to set up a notification to myself, something like:
def you_failed
system "say -v Bad test failed"
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要创建一个自定义格式化程序。查看 Core::BaseFormatter 和 Core::BaseTextFormatter。您会发现 example_failed 方法。在自定义格式化程序中重写此方法以包含示例失败时要调用的代码。请注意,这可以运行多次,具体取决于失败测试的数量。
You will want to create a custom formatter. Look at the Core::BaseFormatter and Core::BaseTextFormatter. You'll find a example_failed method. Override this method in your custom formatter to include the code to call when the example fails. Note this can run multiple times depending on the number of failed tests.