class RSpecRedo::Runner
Attributes
redo_opts[R]
retry_count[RW]
rspec_opts[R]
total_retries[R]
Public Class Methods
invoke(args = ARGV.dup)
click to toggle source
# File lib/rspec-redo/runner.rb, line 6 def invoke(args = ARGV.dup) opts = extract!(args) new(args, opts).invoke end
new(rspec_opts, redo_opts = {})
click to toggle source
# File lib/rspec-redo/runner.rb, line 28 def initialize(rspec_opts, redo_opts = {}) @rspec_opts = rspec_opts @redo_opts = redo_opts @total_retries = @retry_count = redo_opts.fetch('retry-count', 1) end
Private Class Methods
extract!(args)
click to toggle source
# File lib/rspec-redo/runner.rb, line 13 def extract!(args) {}.tap do |opts| if index = args.index('--retry-count') opts['retry-count'] = Integer(args.delete_at(index + 1)) args.delete_at(index) end end rescue ArgumentError abort '--retry-count must be an integer' end
Public Instance Methods
invoke()
click to toggle source
# File lib/rspec-redo/runner.rb, line 34 def invoke run # Invoke rspec for the first time rerun until $?.success? || retry_count.zero? abort! unless $?.success? end
Private Instance Methods
abort!()
click to toggle source
# File lib/rspec-redo/runner.rb, line 54 def abort! abort "Failures still occurred after #{total_retries} retries" end
rerun()
click to toggle source
# File lib/rspec-redo/runner.rb, line 46 def rerun $stderr.puts "*** Failures occurred. Attempting #{retry_count} more time(s)...\n\n" self.retry_count -= 1 env = ENV.clone.tap { |e| e.store 'RSPEC_REDO', '1' } run env: env, args: ['--only-failures'] end
run(args: [], env: ENV)
click to toggle source
# File lib/rspec-redo/runner.rb, line 42 def run(args: [], env: ENV) system(env, 'rspec', *rspec_opts, *args) end