module TestBench::Bootstrap::Run

Public Class Methods

call(argv=nil, exclude_file_pattern: nil) click to toggle source
# File lib/test_bench/bootstrap.rb, line 225
def self.call(argv=nil, exclude_file_pattern: nil)
  argv ||= ::ARGV

  exclude_file_pattern = ENV['TEST_BENCH_EXCLUDE_FILE_PATTERN']
  exclude_file_pattern ||= %r{automated_init\.rb}

  if argv.empty?
    tests_dir = ENV['TEST_BENCH_TESTS_DIR'] || 'test/automated'

    file_patterns = [File.join(tests_dir, '**', '*.rb')]
  else
    file_patterns = argv
  end

  file_patterns.each do |file_pattern|
    if File.directory?(file_pattern)
      file_pattern = File.join(file_pattern, '**/*.rb')
    end

    files = Dir.glob(file_pattern).reject do |file|
      File.basename(file).match?(exclude_file_pattern)
    end

    files.sort.each do |file|
      puts "Running #{file}"

      begin
        load file
      ensure
        puts
      end
    end
  end
end