Class: Ree::SpecRunner::SpecFilenameMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ree/spec_runner/spec_filename_matcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_path, spec_matcher) ⇒ SpecFilenameMatcher

Returns a new instance of SpecFilenameMatcher.



10
11
12
13
# File 'lib/ree/spec_runner/spec_filename_matcher.rb', line 10

def initialize(package_path, spec_matcher)
  @package_path = File.expand_path(package_path)
  @spec_matcher = spec_matcher
end

Class Method Details

.find_matches(package_path:, spec_matcher:) ⇒ Object



5
6
7
# File 'lib/ree/spec_runner/spec_filename_matcher.rb', line 5

def find_matches(package_path:, spec_matcher:)
  Ree::SpecRunner::SpecFilenameMatcher.new(package_path, spec_matcher).find_matches
end

Instance Method Details

#find_matchesObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ree/spec_runner/spec_filename_matcher.rb', line 15

def find_matches
  expected_filename = File.join(@package_path, @spec_matcher)

  if File.exist?(expected_filename)
    return Pathname.new(expected_filename).relative_path_from(Pathname.new(@package_path)).to_s.split
  end

  Dir.glob(File.join(@package_path, '**/*_spec.rb'))
    .select { |fn| File.file?(fn) }
    .map {|file| Pathname.new(file).relative_path_from(Pathname.new(@package_path)).to_s }
    .grep(/#{@spec_matcher.split('').join('.*')}/)
end