module RSpec::Rerun::Tasks

Public Class Methods

failed_count() click to toggle source
# File lib/rspec-rerun/tasks.rb, line 52
def failed_count
  failing_specs.count
end
failing_specs() click to toggle source
# File lib/rspec-rerun/tasks.rb, line 48
def failing_specs
  File.read(RSpec::Rerun::Formatter::FILENAME).split
end
failure_message() click to toggle source
# File lib/rspec-rerun/tasks.rb, line 56
def failure_message
  "[#{Time.now}] Failed, #{failed_count} failure#{failed_count == 1 ? '' : 's'}"
end
parse_args(args) click to toggle source
# File lib/rspec-rerun/tasks.rb, line 22
def parse_args(args)
  options = args.extras

  # Error on multiple arguments
  if options.size > 1
    fail ArgumentError 'rspec-rerun can take an integer (retry_count) or options hash'
  else
    options = options[0]
  end

  # Handle if opts is just a retry_count integer
  options = if options.is_a? Hash
    options
  else
    { retry_count: options }
  end

  # Parse environment variables
  options[:pattern] ||= ENV['RSPEC_RERUN_PATTERN'] if ENV['RSPEC_RERUN_PATTERN']
  options[:tag] ||= ENV['RSPEC_RERUN_TAG'] if ENV['RSPEC_RERUN_TAG']
  options[:retry_count] ||= ENV['RSPEC_RERUN_RETRY_COUNT'] if ENV['RSPEC_RERUN_RETRY_COUNT']
  options[:verbose] = (ENV['RSPEC_RERUN_VERBOSE'] != 'false') if options[:verbose].nil?

  options
end
rerun(args) click to toggle source
# File lib/rspec-rerun/tasks.rb, line 64
def rerun(args)
  Rake::Task['rspec-rerun:rerun'].execute(args)
end
rspec_options(args, spec_files = nil) click to toggle source
# File lib/rspec-rerun/tasks.rb, line 8
def rspec_options(args, spec_files = nil)
  options = [
    spec_files,
    '--require', 'rspec-rerun/formatter',
    '--format', 'RSpec::Rerun::Formatter',
    *dot_rspec_options
  ].compact.flatten
  if args[:tag]
    options << '--tag'
    options << args[:tag]
  end
  options
end
run(args) click to toggle source
# File lib/rspec-rerun/tasks.rb, line 60
def run(args)
  Rake::Task['rspec-rerun:run'].execute(args)
end

Private Class Methods

dot_rspec_options() click to toggle source
# File lib/rspec-rerun/tasks.rb, line 70
def dot_rspec_options
  dot_rspec_file = ['.rspec', File.expand_path('~/.rspec')].detect { |f| File.exist?(f) }
  options = if dot_rspec_file
    file_contents = File.read(dot_rspec_file)
    file_contents.split(/\n+/).map(&:shellsplit).flatten
  else
    []
  end
  options.concat ['--format', 'progress'] unless options.include?('--format')
  options
end