[rubygems/rubygems] Split out Gem::PathSupport#default_home_dir to fix "bundle doctor" specs.

https://github.com/rubygems/rubygems/commit/d7f3f901f1
This commit is contained in:
Ellen Marie Dash 2023-09-29 21:48:44 -04:00 committed by git
parent 0b9b07a717
commit ee9cb86bb4
2 changed files with 19 additions and 7 deletions

View File

@ -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).

View File

@ -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