Class: Minitest::Distributed::TestSelector

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/minitest/distributed/test_selector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ TestSelector

Returns a new instance of TestSelector.



18
19
20
21
22
23
# File 'lib/minitest/distributed/test_selector.rb', line 18

def initialize(options)
  @options = options

  @filters = T.let([], T::Array[Filters::FilterInterface])
  initialize_filters
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



15
16
17
# File 'lib/minitest/distributed/test_selector.rb', line 15

def filters
  @filters
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/minitest/distributed/test_selector.rb', line 12

def options
  @options
end

Instance Method Details

#discover_testsObject



38
39
40
41
42
# File 'lib/minitest/distributed/test_selector.rb', line 38

def discover_tests
  runnables.flat_map do |runnable|
    runnable.runnable_methods.map { |method_name| runnable.new(method_name) }
  end
end

#initialize_filtersObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/minitest/distributed/test_selector.rb', line 26

def initialize_filters
  @filters << Filters::IncludeFilter.new(options[:filter]) if options[:filter]
  @filters << Filters::ExcludeFilter.new(options[:exclude]) if options[:exclude]

  exclude_file = options[:distributed].exclude_file
  @filters << Filters::ExcludeFileFilter.new(Pathname.new(exclude_file)) if exclude_file

  include_file = options[:distributed].include_file
  @filters << Filters::IncludeFileFilter.new(Pathname.new(include_file)) if include_file
end

#runnablesObject



45
46
47
48
49
50
51
52
# File 'lib/minitest/distributed/test_selector.rb', line 45

def runnables
  if options[:distributed].shuffle_suites
    srand(Minitest.seed)
    Minitest::Runnable.runnables.shuffle
  else
    Minitest::Runnable.runnables
  end
end

#select_tests(tests) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/minitest/distributed/test_selector.rb', line 55

def select_tests(tests)
  return tests if filters.empty?

  tests.flat_map do |runnable_method|
    filters.flat_map do |filter|
      filter.call(runnable_method)
    end
  end.compact
end

#testsObject



66
67
68
# File 'lib/minitest/distributed/test_selector.rb', line 66

def tests
  select_tests(discover_tests)
end