当抛出RSpec ExpectationnotMet时,如何使Cucumber测试继续运行

我正在使用Cucumber / Ruby运行场景,每次测试运行时,RSpec都会捕获错误。 将跳过所有剩余步骤(步骤定义)。 我不希望他们跳过。 我希望程序完全运行,只报告发生的问题。 关于如何让这个工作的任何想法?

它看起来像这样:

RSpec :: Expectations :: ExpectationNotMetError:期望“某事”不包括“别的东西”

跳过一步
跳过一步
跳过一步
跳过一步
跳过一步
跳过一步
跳过一步
跳过一步
跳过一步
跳过一步

免责声明:正如安东尼所指出的,这不是最佳做法,但我认为你有充分的理由要求。 🙂

您需要构建某种forms的错误收集器。 捕获每个RSpecexception并将该错误添加到收集器。 在After hook中,检查收集器是否包含某些内容,如果有,则会使方案失败。 您还希望充实收集的错误消息,以包含有关哪个步骤失败以及失败位置的更多信息。 这只是一个简单的方法,让您了解该怎么做。

关键是抢救和记录您的错误,然后再处理它们。


test.feature

Scenario: Test out someting Given this step passes And this step has a collected error Then this step passes 

test_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 

支持/ hooks.rb

 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 someting