Module: RSpec::Support::WarningsPrevention

Defined in:
lib/rspec/support/spec/prevent_load_time_warnings.rb

Instance Method Summary collapse

Instance Method Details

#files_to_require_for(lib) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rspec/support/spec/prevent_load_time_warnings.rb', line 6

def files_to_require_for(lib)
  slash         = File::SEPARATOR
  lib_path_re   = /#{slash + lib}[^#{slash}]*#{slash}lib/
  load_path     = $LOAD_PATH.grep(lib_path_re).first
  files         = Dir["#{load_path}/**/*.rb"]
  extract_regex = /#{Regexp.escape(load_path) + File::SEPARATOR}(.+)\.rb$/

  # We sort to ensure the files are loaded in a consistent order, regardless
  # of OS. Otherwise, it could load in a different order on Travis than
  # locally, and potentially trigger a "circular require considered harmful"
  # warning or similar.
  files.sort.map { |file| file[extract_regex, 1] }
end