Class: Spectator::SpecsMatcher
- Inherits:
-
Object
- Object
- Spectator::SpecsMatcher
- Defined in:
- lib/spectator/specs_matcher.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#matchers ⇒ Object
readonly
Returns the value of attribute matchers.
Class Method Summary collapse
Instance Method Summary collapse
- #all_matchable_spec_files ⇒ Object
-
#initialize(config) ⇒ SpecsMatcher
constructor
A new instance of SpecsMatcher.
- #match_specs(matchable_paths) ⇒ Object
- #matchable_paths(file) ⇒ Object
- #specs_for(files) ⇒ Object
Constructor Details
#initialize(config) ⇒ SpecsMatcher
Returns a new instance of SpecsMatcher.
6 7 8 9 10 11 12 |
# 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 |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
45 46 47 |
# File 'lib/spectator/specs_matcher.rb', line 45 def config @config end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
45 46 47 |
# File 'lib/spectator/specs_matcher.rb', line 45 def files @files end |
#matchers ⇒ Object (readonly)
Returns the value of attribute matchers.
13 14 15 |
# File 'lib/spectator/specs_matcher.rb', line 13 def matchers @matchers end |
Class Method Details
.reset_matchable_spec_files! ⇒ Object
41 42 43 |
# File 'lib/spectator/specs_matcher.rb', line 41 def self.reset_matchable_spec_files! @@all_matchable_spec_files = nil end |
Instance Method Details
#all_matchable_spec_files ⇒ Object
37 38 39 |
# 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) ⇒ Object
31 32 33 34 35 |
# 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) ⇒ Object
25 26 27 28 29 |
# 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) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# 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 |