From e0602f707e98529c1340190b3b9cf40e19cc6b06 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Fri, 24 Sep 2021 12:03:58 -0700 Subject: [PATCH] (maint) Remove overstubbing Dir.glob behaves differently across platforms and ruby versions, don't stub it. --- spec/unit/util/autoload_spec.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/unit/util/autoload_spec.rb b/spec/unit/util/autoload_spec.rb index 3a03d12af85..be3e8a79b1f 100644 --- a/spec/unit/util/autoload_spec.rb +++ b/spec/unit/util/autoload_spec.rb @@ -178,15 +178,14 @@ def with_libdir(libdir) end describe "when loading all files" do + let(:basedir) { tmpdir('autoloader') } + let(:path) { File.join(basedir, @autoload.path, 'file.rb') } + before do - allow(@autoload.class).to receive(:search_directories).and_return([make_absolute("/a")]) - allow(FileTest).to receive(:directory?).and_return(true) - allow(Dir).to receive(:glob).and_return([make_absolute("/a/foo/file.rb")]) - allow(Puppet::FileSystem).to receive(:exist?).and_return(true) - @time_a = Time.utc(2010, 'jan', 1, 6, 30) - allow(File).to receive(:mtime).and_return(@time_a) + FileUtils.mkdir_p(File.dirname(path)) + FileUtils.touch(path) - allow(@autoload.class).to receive(:loaded?).and_return(false) + allow(@autoload.class).to receive(:search_directories).and_return([basedir]) end [RuntimeError, LoadError, SyntaxError].each do |error| @@ -198,7 +197,7 @@ def with_libdir(libdir) end it "should require the full path to the file" do - expect(Kernel).to receive(:load).with(make_absolute("/a/foo/file.rb"), any_args) + expect(Kernel).to receive(:load).with(path, any_args) @autoload.loadall(env) end