Module: Henitai::Integration::RspecTestSelection

Included in:
Minitest, Rspec
Defined in:
lib/henitai/integration/rspec_test_selection.rb

Overview

Spec-file discovery and subject-to-spec matching for the RSpec integration. Selection uses longest-prefix matching against the subject expression and namespace, with a transitive require-based fallback.

Constant Summary collapse

REQUIRE_DIRECTIVE_PATTERN =
/
  \A\s*
  (require|require_relative)
  \s*
  (?:\(\s*)?
  ["']([^"']+)["']
  \s*\)?
/x

Instance Method Summary collapse

Instance Method Details

#select_tests(subject) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/henitai/integration/rspec_test_selection.rb', line 18

def select_tests(subject)
  matches = spec_files.select do |path|
    content = File.read(path)
    selection_patterns(subject).any? { |pattern| content.include?(pattern) }
  rescue StandardError
    false
  end

  return matches unless matches.empty?

  fallback_spec_files(subject)
end