在每种方法之后检测 Rspec 测试失败
我正在尝试运行 RSpec 测试,并且想检测 after
方法中的测试是否失败。我现在有这样的东西:
after(:each) do
cc = ConnectController.new()
cc.update(<TEST-SERVER-CONTROLLER>, <TC-RESULT-ID>, result?)
end
如您所见,我需要替换 result?
函数,以检测测试是否失败,并获取有关失败测试的信息。
I am trying to run an RSpec test, and I want to detect if the test failed in the after
method. I have something like this right now:
after(:each) do
cc = ConnectController.new()
cc.update(<TEST-SERVER-CONTROLLER>, <TC-RESULT-ID>, result?)
end
As you can see, the result?
function is what I need to replace, to detect if the test fails or not, and to also get information about the test that failed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了丹尼尔的回答之外,在 Rspec3 中,示例方法被删除(参见 此处了解更多信息)。
你必须做这样的事情:
In addition to Daniel's answer, in Rspec3 the example method was deleted (see here for more info).
You will have to do something like this:
编辑:这个答案仅对 RSpec 2 有效。对于 RSpec 3,请参阅 geekazoid 的答案。
After 每个块在公开
example
的类的上下文中运行,您可以通过检查example
上的exception
方法来检测失败,如下所示:EDIT: this answer is only valid for RSpec 2. for RSpec 3 see geekazoid's answer.
The after each block runs in the context of class which exposes
example
and you can detect failures by checking theexception
method onexample
thusly:我正在寻找如何检查
after(:context)
/after(:all)
块中组中的所有示例是否成功。这是我想出的:I was looking for how to check if success for all examples in a group in a
after(:context)
/after(:all)
block. Here's what I came up with: