@ -89,61 +89,35 @@ task "cucumber:debug" do
ENV [ 'TEST_DEBUG' ] = nil
ENV [ 'TEST_DEBUG' ] = nil
end
end
# Cucumber::Rake::Task.new(:cucumber) do |t|
# t.cucumber_opts = "features --format pretty"
# end
namespace :cucumber do
namespace :cucumber do
directory 'tmp'
@rerun_file = 'tmp /rerun.txt'
FAILING_CUCUMBER_SCENARIOS_FILENAME = 'log/rerun.txt'
Cucumber :: Rake :: Task . new ( :all ) do | task |
Cucumber :: Rake :: Task . new ( :start ) do | task |
task . cucumber_opts = " features --format pretty --format rerun --out tmp/rerun.txt "
task . cucumber_opts = " features --format pretty -f rerun --out #{ FAILING_CUCUMBER_SCENARIOS_FILENAME } "
end
end
desc 'Run cucumber features'
Cucumber :: Rake :: Task . new ( :retry ) do | task |
task run : :tmp do
task . cucumber_opts = " @ #{ FAILING_CUCUMBER_SCENARIOS_FILENAME } "
retry_on_failure do
run_features
end
clean_up
exit @exit_status
end
end
def retry_on_failure
task :run do
rm_rf @rerun_file
exception = nil
@retries = 0
begin
begin
@exit_status = 0
result = Rake :: Task [ 'cucumber:start' ] . execute
yield
rescue Exception = > e
rescue SystemExit = > e
begin
@exit_status = e . status
puts " \n Retrying failed scenarios... \n "
if retry ? ( exception : e )
Rake :: Task [ 'cucumber:retry' ] . execute
@retries += 1
rescue Exception = > e2
retry
exception = e2
end
end
end
end
end
def run_features
if File . exists? ( " #{ FAILING_CUCUMBER_SCENARIOS_FILENAME } " )
if File . exists? @rerun_file
File . delete ( " #{ FAILING_CUCUMBER_SCENARIOS_FILENAME } " )
Cucumber :: Rake :: Task :: ForkedCucumberRunner . new ( [ 'lib' ] , Cucumber :: BINARY , [
'features' ,
'--format' , 'pretty' ,
'@tmp/rerun.txt' ,
'--format' , 'rerun' ,
'--out' , 'tmp/rerun.txt'
] , true , [ ] ) . run
else
Rake :: Task [ 'cucumber:all' ] . invoke
end
end
end
def retry? ( exception : nil )
@retries < 2 && ! exception . success?
end
def clean_up
raise exception unless exception . nil?
rm_rf @rerun_file . pathmap ( " %d " )
end
end
end
end