module RSpec::Support::WarningsPrevention

Public Instance Methods

files_to_require_for(lib, sub_dir) click to toggle source
# File lib/rspec/support/spec/prevent_load_time_warnings.rb, line 6
def files_to_require_for(lib, sub_dir)
  slash         = File::SEPARATOR
  lib_path_re   = /#{slash + lib}[^#{slash}]*#{slash}lib/
  load_path     = $LOAD_PATH.grep(lib_path_re).first
  directory     = load_path.sub(/lib$/, sub_dir)
  files         = Dir["#{directory}/**/*.rb"]
  extract_regex = /#{Regexp.escape(directory) + 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