【发布时间】:2019-08-05 13:33:12
【问题描述】:
当测试失败时,我会尝试做一些额外的事情。
这是失败的测试:
it 'fails' do
expect(1213).to eq('123456')
end
以下代码被添加到 spec_helper 中:
RSpec.configure do |config|
config.after(:each) do |example|
if example.exception
puts 'Do something'
end
end
结果如下:
预期:“123456” 得到:“1213” (使用 == 比较)
1 个示例,1 个失败,0 个通过
2秒完成
示例中的异常保持为零,我不明白为什么。测试失败后还有其他方法可以实现额外的代码吗?
【问题讨论】:
-
尝试使用
example.execution_result.status = ...而不是example.exception -
我试过了,但值始终为空。
-
查看此评论github.com/rspec/rspec-core/issues/2011#issuecomment-114669886 - 我认为这是答案(也有解决方案)
标签: ruby rspec automated-tests