Skip to content

Instantly share code, notes, and snippets.

@mipearson
Created December 10, 2013 22:33
Show Gist options
  • Save mipearson/7901589 to your computer and use it in GitHub Desktop.
Save mipearson/7901589 to your computer and use it in GitHub Desktop.
Parallel rspec w/ re-run of failing specs.
--colour
--format ParallelTests::RSpec::SummaryLogger
--format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log
--format ParallelTests::RSpec::FailuresLogger --out tmp/rspec_failures.log
#!/usr/bin/env ruby
# tmp/rspec_failures.log looks like:
#Pending:
# Billing attempt_payment with a successful payment response should send a successful payment email
# # ./spec/models/billing_spec.rb:130
#
# Failed examples:
# rspec ./spec/models/taxon_spec.rb:23 # Taxon.has_option_type should only return taxon that have the asked for option type
# rspec ./spec/models/taxon_spec.rb:91 # Taxon tree prevent infinite loop should not be valid if taxon's parent is its grand child
# Failed examples:
# rspec ./spec/models/cart_spec.rb:14 # Cart empty? can add a variant
# Pending:
# Billing becoming paid ecommerce_setup should mark the retailer as ecommerce-enabled
# # Not yet implemented
# # ./spec/models/billing_spec.rb:252
rspec_args = ARGV.any? ? ARGV.join(' ') : 'spec'
system "parallel_rspec #{rspec_args}"
if $?.exitstatus != 0
# failed, rerun failed examples sequentially
failures = File.read(File.expand_path("../../tmp/rspec_failures.log", __FILE__))
failures = failures.split("\n")
failures = failures.map do |line|
line =~ %r{rspec (\./spec[\w/._:\d]+)} ? $1 : nil
end
failures.compact!
if failures.empty?
puts "parallel_rspec failed, but no failures recorded in tmp/rspec_failures.log!"
exit 1
end
command = "rspec #{failures.join(' ')}"
puts "$ #{command.inspect}" # Use inspect here to expose any colour codes from the log
system command
exit $?.exitstatus
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment