Class: RSpecTurbo::FileDiscovery

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_turbo/file_discovery.rb

Overview

Discovers *_spec.rb files under the given folders (or all of spec/ if none are given), de-duplicates them and applies –exclude-pattern glob filters.

Returned paths are relative to spec/ (e.g. “models/user_spec.rb”).

Constant Summary collapse

FNMATCH_FLAGS =
File::FNM_PATHNAME | File::FNM_EXTGLOB

Instance Method Summary collapse

Constructor Details

#initialize(folders, exclude_patterns: []) ⇒ FileDiscovery

Returns a new instance of FileDiscovery.



11
12
13
14
# File 'lib/rspec_turbo/file_discovery.rb', line 11

def initialize(folders, exclude_patterns: [])
  @folders = folders
  @exclude_patterns = exclude_patterns
end

Instance Method Details

#filesObject



16
17
18
19
20
21
22
23
24
# File 'lib/rspec_turbo/file_discovery.rb', line 16

def files
  raw = collect_files

  return raw if @exclude_patterns.empty?

  raw.reject do |file|
    @exclude_patterns.any? { |pattern| File.fnmatch(pattern, "spec/#{file}", FNMATCH_FLAGS) }
  end
end