Skip to content

Instantly share code, notes, and snippets.

@anolson
Last active February 23, 2016 13:15
Show Gist options
  • Save anolson/fdfec936b4fae9492234 to your computer and use it in GitHub Desktop.
Save anolson/fdfec936b4fae9492234 to your computer and use it in GitHub Desktop.
# Re-try randomly failing examples
config.around(:each) do |ex|
attempts = [ENV["RSPEC_ATTEMPTS"].to_i, 1].max
attempts.times do |i|
example = RSpec.current_example
example.instance_variable_set("@exception", nil)
if i > 0
puts "Re-running rspec example #{example.location}. Attempt #{i + 1} of #{attempts}"
end
ex.run
break if example.exception.nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment