class Spectator::SpecsMatcher
Attributes
config[R]
files[R]
matchers[R]
Public Class Methods
new(config)
click to toggle source
# File lib/spectator/specs_matcher.rb, line 6 def initialize(config) @config = config @matchers = [ %r{^#{config.spec_dir_regexp}/(.*)_spec\.rb$}, %r{^(?:#{config.base_dir_regexp})/(.*)(?:\.rb|\.\w+|)$}, ] end
reset_matchable_spec_files!()
click to toggle source
# File lib/spectator/specs_matcher.rb, line 41 def self.reset_matchable_spec_files! @@all_matchable_spec_files = nil end
Public Instance Methods
all_matchable_spec_files()
click to toggle source
# File lib/spectator/specs_matcher.rb, line 37 def all_matchable_spec_files @@all_matchable_spec_files ||= Dir['**/**'].grep(%r{^#{config.spec_dir_regexp}}) end
match_specs(matchable_paths)
click to toggle source
# File lib/spectator/specs_matcher.rb, line 31 def match_specs matchable_paths matchable_paths.uniq.flat_map do |path| all_matchable_spec_files.grep(/\b#{path}_spec\.rb$/) end end
matchable_paths(file)
click to toggle source
# File lib/spectator/specs_matcher.rb, line 25 def matchable_paths(file) matchers.map do |matcher| file.scan(matcher).flatten.first.to_s.gsub(/\.rb$/,'') end.flatten.reject(&:empty?) end
specs_for(files)
click to toggle source
# File lib/spectator/specs_matcher.rb, line 15 def specs_for(files) files.flat_map do |path| matchable_paths = self.matchable_paths(path) print "--- Searching specs for #{path.inspect} (as: #{matchable_paths.join(", ")})...".yellow specs = match_specs(matchable_paths) puts specs.empty? ? ' nothing found.'.red : " #{specs.size} matched.".green specs end end