Alex Rivera | Logout

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

Asked 2011-07-18T23:31:19.547
16

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
Edit
Report

1 Answer

14

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.

answered 2011-07-18T23:45:52.487

Your Answer