picardo
picardo

Reputation: 24886

How to make sure cucumber stops execution when a step fails?

Cucumber keeps executing even after a step definition has failed, and it outputs not only the failing steps, but also the passing ones. What option do I need to use in order to ensure that Cucumber stop executing as soon as it has encountered a failing step?

This is my cucumber.yml file

<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
autotest: <%= std_opts %> features --color

Upvotes: 16

Views: 7815

Answers (3)

janDro
janDro

Reputation: 1466

As of Cucumber 2.1 you can pass the --fail-fast tag.

It should fail at the first scenario that fails and skip remaining scenarios.

Part of this PR https://github.com/cucumber/cucumber-ruby/pull/906

Upvotes: 5

Dan Kohn
Dan Kohn

Reputation: 34327

This lets fail fast be invoked from the command line:

# `FAST=1 cucumber` to stop on first failure
After do |scenario|
  Cucumber.wants_to_quit = ENV['FAST'] && scenario.failed?
end

Upvotes: 4

Kenny Meyer
Kenny Meyer

Reputation: 8027

Use a cucumber hook:

After do |s| 
  # Tell Cucumber to quit after this scenario is done - if it failed.
  Cucumber.wants_to_quit = true if s.failed?
end

Or, raise an exception.

The recommended way is using a cucumber hook, though.

Upvotes: 14

Related Questions