Class: Megatest::Selector::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/megatest/selector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, path, filter = nil) ⇒ Loader

Returns a new instance of Loader.



61
62
63
64
65
66
67
68
69
# File 'lib/megatest/selector.rb', line 61

def initialize(config, path, filter = nil)
  @config = config
  @path = File.expand_path(path)
  if @directory = File.directory?(@path)
    @path = File.join(@path, "/")
  end
  @paths = nil
  @filter = filter
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



59
60
61
# File 'lib/megatest/selector.rb', line 59

def path
  @path
end

Instance Method Details

#append_paths(paths_to_load) ⇒ Object



84
85
86
# File 'lib/megatest/selector.rb', line 84

def append_paths(paths_to_load)
  paths_to_load.concat(paths)
end

#append_tests(tests_to_run, registry, random:) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/megatest/selector.rb', line 75

def append_tests(tests_to_run, registry, random:)
  test_cases = select(registry)
  if partial?
    test_cases.sort!
    test_cases.shuffle!(random: random) if random
  end
  tests_to_run.concat(test_cases)
end

#partial?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/megatest/selector.rb', line 71

def partial?
  !!@filter
end

#select(registry) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/megatest/selector.rb', line 88

def select(registry)
  test_cases = if @directory
    registry.test_cases.select do |test_case|
      test_case.source_file.start_with?(@path)
    end
  else
    registry.test_cases_by_path(@path)
  end

  if @filter
    @filter.select(test_cases)
  else
    test_cases
  end
end