Class: Evilution::SpecResolver
- Inherits:
-
Object
- Object
- Evilution::SpecResolver
- 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
- #call(source_path, spec_pattern: nil) ⇒ Object
-
#initialize(test_dir: "spec", test_suffix: "_spec.rb", request_dir: "requests") ⇒ SpecResolver
constructor
A new instance of SpecResolver.
- #resolve_all(source_paths) ⇒ Object
-
#resolve_specs(source_path, spec_pattern: nil) ⇒ Object
Like #call, but returns an ARRAY of test files and additionally covers the dir-grouped layout (a source file’s tests live in a directory named after the source basename, e.g. lib/x/branch.rb -> test/unit/branch/*_test.rb, rather than a single mirror file).
-
#suggest(source_path) ⇒ Object
Best-guess candidate for an unresolved source, found by basename glob rather than the deterministic path mirroring used by #call.
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 |
#resolve_specs(source_path, spec_pattern: nil) ⇒ Object
Like #call, but returns an ARRAY of test files and additionally covers the dir-grouped layout (a source file’s tests live in a directory named after the source basename, e.g. lib/x/branch.rb -> test/unit/branch/*_test.rb, rather than a single mirror file). The deterministic file mirror from #call always wins; only when no mirror file exists is the first matching grouped directory expanded into its test files (EV-bi41). Returns nil when nothing resolves.
38 39 40 41 42 43 44 45 |
# File 'lib/evilution/spec_resolver.rb', line 38 def resolve_specs(source_path, spec_pattern: nil) return nil if source_path.nil? || source_path.empty? file = call(source_path, spec_pattern: spec_pattern) return [file] if file resolve_grouped_dir(source_path, spec_pattern: spec_pattern) 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.
52 53 54 55 56 57 58 59 |
# File 'lib/evilution/spec_resolver.rb', line 52 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 |