Class: SpecsFor::Finder
- Inherits:
-
Object
- Object
- SpecsFor::Finder
- Defined in:
- lib/specs_for/finder.rb
Overview
Finder maps source files to their corresponding spec files.
Constant Summary collapse
- SPEC_SUFFIX =
"_spec.rb"- SPEC_DIRS =
Default search paths for spec files, in priority order.
%w[spec test].freeze
Instance Attribute Summary collapse
-
#spec_dirs ⇒ Object
readonly
Returns the value of attribute spec_dirs.
Instance Method Summary collapse
-
#candidates_for(file) ⇒ Array<String>
Compute candidate spec paths for a single file.
-
#find(files) ⇒ Array<String>
Given a list of file paths, return the unique set of existing spec files that correspond to those paths.
-
#initialize(spec_dirs: SPEC_DIRS) ⇒ Finder
constructor
A new instance of Finder.
-
#spec_file?(file) ⇒ Boolean
Return true when
filealready looks like a spec file.
Constructor Details
Instance Attribute Details
#spec_dirs ⇒ Object (readonly)
Returns the value of attribute spec_dirs.
11 12 13 |
# File 'lib/specs_for/finder.rb', line 11 def spec_dirs @spec_dirs end |
Instance Method Details
#candidates_for(file) ⇒ Array<String>
Compute candidate spec paths for a single file.
33 34 35 36 37 |
# File 'lib/specs_for/finder.rb', line 33 def candidates_for(file) return [file] if spec_file?(file) spec_dirs.flat_map { |dir| spec_paths_in(file, dir) } end |
#find(files) ⇒ Array<String>
Given a list of file paths, return the unique set of existing spec files that correspond to those paths.
22 23 24 25 26 27 |
# File 'lib/specs_for/finder.rb', line 22 def find(files) files.flat_map { |file| candidates_for(file) } .uniq .select { |f| File.exist?(f) } .sort end |
#spec_file?(file) ⇒ Boolean
Return true when file already looks like a spec file.
40 41 42 |
# File 'lib/specs_for/finder.rb', line 40 def spec_file?(file) file.end_with?(SPEC_SUFFIX) end |