Class: Evilution::SpecSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/spec_selector.rb

Instance Method Summary collapse

Constructor Details

#initialize(spec_files: [], spec_mappings: {}, spec_pattern: nil, spec_resolver: Evilution::SpecResolver.new) ⇒ SpecSelector

Returns a new instance of SpecSelector.



6
7
8
9
10
11
# File 'lib/evilution/spec_selector.rb', line 6

def initialize(spec_files: [], spec_mappings: {}, spec_pattern: nil, spec_resolver: Evilution::SpecResolver.new)
  @spec_files = Array(spec_files)
  @spec_mappings = spec_mappings || {}
  @spec_pattern = spec_pattern
  @spec_resolver = spec_resolver
end

Instance Method Details

#call(source_path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/evilution/spec_selector.rb', line 13

def call(source_path)
  return @spec_files unless @spec_files.empty?

  mapped = mapping_for(source_path)
  if mapped
    existing = mapped.select { |path| File.exist?(path) }
    return existing unless existing.empty?
  end

  resolved = @spec_resolver.call(source_path, spec_pattern: @spec_pattern)
  resolved ? [resolved] : nil
end