Class: MinitestRerunFailed::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest_rerun_failed/runner.rb

Constant Summary collapse

DEFAULT_FILENAME =
".minitest_failed_tests.txt"
DEFAULT_REPORT_DIR =
"./"

Instance Method Summary collapse

Constructor Details

#initialize(report_dir: ENV.fetch("MINITEST_FAILED_TESTS_REPORT_DIR", DEFAULT_REPORT_DIR), filename: DEFAULT_FILENAME, io: $stdout, command_runner: nil) ⇒ Runner

Returns a new instance of Runner.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/minitest_rerun_failed/runner.rb', line 10

def initialize(
  report_dir: ENV.fetch("MINITEST_FAILED_TESTS_REPORT_DIR", DEFAULT_REPORT_DIR),
  filename: DEFAULT_FILENAME,
  io: $stdout,
  command_runner: nil
)
  @report_dir = report_dir
  @filename = filename
  @io = io
  @command_runner = command_runner
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
# File 'lib/minitest_rerun_failed/runner.rb', line 22

def call
  return report_missing_file unless File.exist?(filepath)
  return report_empty_file if File.empty?(filepath)

  failed_tests = read_failed_tests
  return report_empty_file if failed_tests.empty?

  run_commands(commands_for(failed_tests))
end

#commands_for(failed_tests) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/minitest_rerun_failed/runner.rb', line 32

def commands_for(failed_tests)
  if rails_installed?
    [
      ["bundle", "exec", "rails", "test", *failed_tests]
    ]
  else
    ruby_test_files(failed_tests).map do |test_file|
      ["bundle", "exec", "ruby", test_file]
    end
  end
end