Created
May 30, 2014 13:01
-
-
Save naps62/b6e405e3157b5a4d29e2 to your computer and use it in GitHub Desktop.
Retrying failing cucumber steps automatically until everything is green
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip -r features/support -r features/step_definitions" %> | |
<% rerun_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --format rerun --out tmp/rerun.txt --strict --tags ~@wip -r features/support -r features/step_definitions" %> | |
default: <%= std_opts %> features | |
all: <%= rerun_opts %> features | |
rerun: <%= rerun_opts %> @tmp/rerun.txt | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cucumber/rake/task' | |
NUM_RETRIES = ENV['NUM_RETRIES'] || 2 | |
task :default => "cucumber:run" | |
namespace :cucumber do | |
directory "tmp" | |
@rerun_file = 'tmp/rerun.txt' | |
Cucumber::Rake::Task.new(:all) do |task| | |
task.profile = "all" | |
end | |
desc 'Run cucumber features' | |
task :run => "tmp" do | |
retry_on_failure do | |
run_features | |
end | |
clean_up | |
exit @exit_status | |
end | |
def retry_on_failure | |
rm_rf @rerun_file | |
@retries = 0 | |
begin | |
@exit_status = 0 | |
yield | |
rescue SystemExit => e | |
@exit_status = e.status | |
if retry?(exception: e) | |
@retries += 1 | |
retry | |
end | |
end | |
end | |
def run_features | |
if File.exists? @rerun_file | |
Cucumber::Rake::Task::ForkedCucumberRunner.new(['lib'], Cucumber::BINARY, ['--profile', 'rerun'], true, []).run | |
else | |
Rake::Task["cucumber:all"].invoke | |
end | |
end | |
def retry?(exception: nil) | |
@retries < NUM_RETRIES && !exception.success? | |
end | |
def clean_up | |
rm_rf @rerun_file.pathmap("%d") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment