我正在使用Cucumber/Ruby运行场景,每次测试运行时,RSpec都会捕获错误。跳过所有剩余的步骤(步骤定义)。我不想让他们跳过。我希望这个程序能够完全运行,并且只报告问题的发生。有什么办法能让我做到这一点吗?
看起来就像这样:
RSpec::ExpectationNotMetError:预期的“某事”不包括“其他的东西” 跳步 跳步 跳步 跳步 跳步 跳步 跳步 跳步 跳步 跳步
发布于 2014-11-05 16:57:52
免责声明:正如安东尼所指出的,这不是最佳实践,但我假设你有一个很好的理由去问。:)
您需要构建某种形式的错误收集器。捕获每个RSpec异常并将该错误添加到收集器中。在After钩子中,检查收集器是否包含某些内容,如果包含,则失败。您还需要充实收集的错误消息,以包含有关哪个步骤失败和哪个步骤失败的更多信息。这只是简单的告诉你该怎么做。
关键是要挽救和记录错误,然后再处理它们。
test.feature
Scenario: Test out someting
Given this step passes
And this step has a collected error
Then this step passestest_stepdef.rb
Given(/^this step passes$/) do
# keep on keeping on
end
Given(/^this step has a collected error$/) do
begin
1.should eq(0)
rescue RSpec::Expectations::ExpectationNotMetError => e
@collected_errors.push e.message
end
end支助/钩子b
Before do |scenario|
@collected_errors = []
end
After do |scenario|
fail "#{@collected_errors}" unless @collected_errors.empty?
end输出
Scenario: Test out someting # features/test.feature:6
Given this step passes # features/stepdefs/test_stepdef.rb:2
And this step has a collected error # features/stepdefs/test_stepdef.rb:6
Then this step passes # features/stepdefs/test_stepdef.rb:2
["expected: 0
got: 1
(compared using ==)"] (RuntimeError)
features/support/hooks.rb:21:in `After'
Failing Scenarios:
cucumber features/test.feature:6 # Scenario: Test out sometinghttps://stackoverflow.com/questions/26761624
复制相似问题