Skip to content

Instantly share code, notes, and snippets.

@HarlemSquirrel
Created January 5, 2022 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarlemSquirrel/5f92c9054c8eecfaa2787e4d63edbe8f to your computer and use it in GitHub Desktop.
Save HarlemSquirrel/5f92c9054c8eecfaa2787e4d63edbe8f to your computer and use it in GitHub Desktop.
Run one or more specs as many times as you need in a row.
#!/usr/bin/env ruby
##
# Run one or more specs as many times as you need in a row.
#
# The files are loaded just once for speed and
# failure counts are tracked and reported at the end.
#
# Provide the number of times and the file(s).
# i.e.
# rspec-repeat 5 spec/models/user_spec.rb:11
#
raise("No run count provided") unless ARGV[0] =~ /\A[0-9]+\z/
RUN_COUNT = ARGV[0].to_i
require 'bundler/setup'
require 'rspec/core'
failure_count = 0
puts "🔁 Running specs #{RUN_COUNT} times..."
RUN_COUNT.times do
# This does not generate a new seed each time but there must be a way to do that if needed.
failure_count += RSpec::Core::Runner.run(ARGV[1..])
RSpec.clear_examples
end
puts "\nDone!", "We had #{failure_count} failures in all."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment