From ee9cb86bb49db0fe1613a5121a89587630506780 Mon Sep 17 00:00:00 2001 From: Ellen Marie Dash Date: Fri, 29 Sep 2023 21:48:44 -0400 Subject: [rubygems/rubygems] Split out Gem::PathSupport#default_home_dir to fix "bundle doctor" specs. https://github.com/rubygems/rubygems/commit/d7f3f901f1 --- lib/rubygems/path_support.rb | 22 +++++++++++++++------- spec/bundler/commands/doctor_spec.rb | 4 ++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index 310d6a0669..b7900f67eb 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -24,13 +24,7 @@ class Gem::PathSupport # hashtable, or defaults to ENV, the system environment. # def initialize(env) - @home = env["GEM_HOME"] || Gem.default_dir - - if File::ALT_SEPARATOR - @home = @home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) - end - - @home = expand(@home) + @home = default_home_dir(env) # If @home (aka Gem.paths.home) exists, but we can't write to it, # fall back to Gem.user_dir (the directory used for user installs). @@ -54,6 +48,20 @@ class Gem::PathSupport private + ## + # The default home directory. + # This function was broken out to accommodate tests in `bundler/spec/commands/doctor_spec.rb`. + + def default_home_dir(env) + home = env["GEM_HOME"] || Gem.default_dir + + if File::ALT_SEPARATOR + home = home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) + end + + expand(home) + end + ## # Split the Gem search path (as reported by Gem.path). diff --git a/spec/bundler/commands/doctor_spec.rb b/spec/bundler/commands/doctor_spec.rb index 13aaf2670c..4a8d0d6f46 100644 --- a/spec/bundler/commands/doctor_spec.rb +++ b/spec/bundler/commands/doctor_spec.rb @@ -38,6 +38,10 @@ RSpec.describe "bundle doctor" do allow(stat).to receive(:uid) { Process.uid } allow(File).to receive(:writable?).with(unwritable_file) { true } allow(File).to receive(:readable?).with(unwritable_file) { true } + + # The following 2 lines are for `Gem::PathSupport#initialize`. + allow(File).to receive(:exist?).with(Gem.paths.send(:default_home_dir)) + allow(File).to receive(:writable?).with(Gem.paths.send(:default_home_dir)) end it "exits with no message if the installed gem has no C extensions" do -- cgit v1.2.3