diff options
author | Ellen Marie Dash <me@duckie.co> | 2023-09-29 21:48:44 -0400 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-10-11 19:07:27 +0000 |
commit | ee9cb86bb49db0fe1613a5121a89587630506780 (patch) | |
tree | 92f5d31587fe57558a055dbce601875e8886dfaf | |
parent | 0b9b07a717a31b7f3c87a9097c9fe1833efe9b1d (diff) | |
download | ruby-ee9cb86bb49db0fe1613a5121a89587630506780.tar.gz |
[rubygems/rubygems] Split out Gem::PathSupport#default_home_dir to fix "bundle doctor" specs.
https://github.com/rubygems/rubygems/commit/d7f3f901f1
-rw-r--r-- | lib/rubygems/path_support.rb | 22 | ||||
-rw-r--r-- | 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). @@ -55,6 +49,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). def split_gem_path(gpaths, home) 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 |