Class: Evilution::SpecResolver

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

Constant Summary collapse

STRIPPABLE_PREFIXES =
%w[lib/ app/].freeze
CONTROLLER_PREFIX =
"controllers/"
CONVENTIONAL_SUBDIRS =

Conventional test subdirectories appended to @test_dir. Real-world gems frequently park specs under spec/unit or spec/lib (test/unit, test/lib) rather than mirroring the lib/ tree 1:1 (EV-z7f5 / GH #1325).

%w[unit lib].freeze
MINITEST_SUFFIX =
"_test.rb"

Instance Method Summary collapse

Constructor Details

#initialize(test_dir: "spec", test_suffix: "_spec.rb", request_dir: "requests") ⇒ SpecResolver

Returns a new instance of SpecResolver.



12
13
14
15
16
# File 'lib/evilution/spec_resolver.rb', line 12

def initialize(test_dir: "spec", test_suffix: "_spec.rb", request_dir: "requests")
  @test_dir = test_dir
  @test_suffix = test_suffix
  @request_dir = request_dir
end

Instance Method Details

#call(source_path, spec_pattern: nil) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/evilution/spec_resolver.rb', line 18

def call(source_path, spec_pattern: nil)
  return nil if source_path.nil? || source_path.empty?

  normalized = normalize_path(source_path)
  candidates = candidate_test_paths(normalized)
  candidates = filter_by_pattern(candidates, spec_pattern) if spec_pattern
  candidates.find { |path| project_relative_exists?(path) }
end

#resolve_all(source_paths) ⇒ Object



27
28
29
# File 'lib/evilution/spec_resolver.rb', line 27

def resolve_all(source_paths)
  Array(source_paths).filter_map { |path| call(path) }.uniq
end

#suggest(source_path) ⇒ Object

Best-guess candidate for an unresolved source, found by basename glob rather than the deterministic path mirroring used by #call. Used only to enrich the “no matching test” hint (EV-z7f5 / GH #1325) — never to pick a test to run — so a fuzzy substring match is acceptable here. Returns the shallowest match, or nil when nothing resembles the basename.



36
37
38
39
40
41
42
43
# File 'lib/evilution/spec_resolver.rb', line 36

def suggest(source_path)
  return nil if source_path.nil? || source_path.empty?

  stem = File.basename(normalize_path(source_path), ".rb")
  return nil if stem.empty?

  suggestion_globs(stem).flat_map { |glob| glob_relative(glob) }.uniq.min_by(&:length)
end