Skip to content

Instantly share code, notes, and snippets.

@ciembor
Last active August 29, 2015 14:20
Show Gist options
  • Save ciembor/f19fe14f0b6a8cb94227 to your computer and use it in GitHub Desktop.
Save ciembor/f19fe14f0b6a8cb94227 to your computer and use it in GitHub Desktop.
# we don't have knapsack in our :production gems group, so the deploy would fail without this condition
if Rails.env.development? || Rails.env.test?
require 'knapsack'
# we have multiple nodes, so we need different files for each node
def failing_scenarios_filename
"failing_scenarios_#{ENV['CIRCLE_NODE_INDEX']}.txt"
end
namespace :knapsack do
task :cucumber_record_failing, [:cucumber_args] do |t, args|
allocator = Knapsack::AllocatorBuilder.new(Knapsack::Adapters::CucumberAdapter).allocator
puts
puts 'Report features:'
puts allocator.report_node_tests
puts
puts 'Leftover features:'
puts allocator.leftover_node_tests
puts
# run cucumber and record failing scenarios to the file, exit 0, we don't want failed build because of this
cmd = %Q[bundle exec cucumber #{args[:cucumber_args]} -f rerun --out #{failing_scenarios_filename} -- #{allocator.stringify_node_tests}; exit 0]
exec(cmd)
end
task :cucumber_rerun, [:cucumber_args] do |t, args|
# we don't need to run cucumber again if all scenarios passed
unless File.zero?("#{failing_scenarios_filename}")
puts
puts 'Rerun failing cucumber specs:'
puts
# run cucumber with failing scenarios only
cmd = %Q[bundle exec cucumber #{args[:cucumber_args]} @#{failing_scenarios_filename}]
exec(cmd)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment