每种方法检测到Rspec测试失败 [英] Detect Rspec test failure on after each method

查看:63
本文介绍了每种方法检测到Rspec测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行RSpec测试,并且我想在after方法中检测测试是否失败.我现在有这样的东西:

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

如您所见,我需要替换result?函数,以检测测试是否失败,并获取有关失败测试的信息.

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.

推荐答案

除了Daniel的回答,在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:

after(:each) do |example|
  if example.exception
    # ...
  end
end

这篇关于每种方法检测到Rspec测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆