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(path, filter = nil) ⇒ Loader

Returns a new instance of Loader.



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

def initialize(path, filter = nil)
  @path = File.expand_path(path)
  if @directory = File.directory?(@path)
    @path = File.join(@path, "/")
    @paths = Megatest.glob(@path)
  else
    @paths = [@path]
  end
  @filter = filter
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



57
58
59
# File 'lib/megatest/selector.rb', line 57

def path
  @path
end

Instance Method Details

#append_paths(paths_to_load) ⇒ Object



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

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

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



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

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)


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

def partial?
  !!@filter
end

#select(registry) ⇒ Object



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

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