Module: RSpec::Rerun::Tasks

Defined in:
lib/rspec-rerun/tasks.rb

Class Method Summary collapse

Class Method Details

.failed_countObject



52
53
54
# File 'lib/rspec-rerun/tasks.rb', line 52

def failed_count
  failing_specs.count
end

.failing_specsObject



48
49
50
# File 'lib/rspec-rerun/tasks.rb', line 48

def failing_specs
  File.read(RSpec::Rerun::Formatter::FILENAME).split
end

.failure_messageObject



56
57
58
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Object



64
65
66
# 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) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# 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) ⇒ Object



60
61
62
# File 'lib/rspec-rerun/tasks.rb', line 60

def run(args)
  Rake::Task['rspec-rerun:run'].execute(args)
end