Remove SourceReader::Inspec#prepare_load_path

We already monkeypatch require so that it is redirected through the
require_loader.  All of the tests pass with this removal.  We might
cause some breakage with this removal that we aren't testing, but given
that we are mucking with `require` it seems preferable to have one
mechanism by which we do that and solve any bugs with that single path.

Signed-off-by: Steven Danna <steve@chef.io>
This commit is contained in:
Steven Danna 2016-09-06 12:39:04 +01:00 committed by Christoph Hartmann
parent bd64428458
commit 210dbc9425

View file

@ -34,7 +34,6 @@ module SourceReaders
@tests = load_tests
@libraries = load_libs
prepare_load_paths
end
private
@ -52,27 +51,5 @@ module SourceReaders
end
Hash[tests.map { |x| [x, @target.read(x)] }]
end
# Ensure each test directory exists on the $LOAD_PATH. This
# will ensure traditional RSpec-isms like `require 'spec_helper'`
# continue to work. The method outlined here is only meant to be temporary!
def prepare_load_paths
t = @target
t = @target.parent unless @target.parent.nil?
unless t.is_a?(Fetchers::Local)
return # no need to mess with load-paths if this is not on disk
end
rel_dirs = (@libraries.keys + @tests.keys)
.map { |x| File.dirname(x) }.uniq
abs_dirs = rel_dirs.map { |x| @target.abs_path(x) }
.find_all { |x| File.directory?(x) }
.map { |x| File.expand_path(x) }
abs_dirs.each do |dir|
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
end
end
end
end