File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -680,9 +680,13 @@ def process_options # :nodoc:
680680 unless @gem_home
681681 # `--build-root` overrides `--user-install` and auto-user-install
682682 if @build_root . nil?
683+ # Please note that `options[:user_install]` might have three states:
684+ # * `true`: `--user-install`
685+ # * `false`: `--no-user-install` and
686+ # * `nil`: option was not specified
683687 if options [ :user_install ]
684688 @gem_home = Gem . user_dir
685- elsif !ENV . key? ( "GEM_HOME" ) && ( File . exist? ( Gem . dir ) && !File . writable? ( Gem . dir ) )
689+ elsif options [ :user_install ] . nil? && !ENV . key? ( "GEM_HOME" ) && ( File . exist? ( Gem . dir ) && !File . writable? ( Gem . dir ) )
686690 say "Defaulting to user installation because default installation directory (#{ Gem . dir } ) is not writable."
687691 @gem_home = Gem . user_dir
688692 end
Original file line number Diff line number Diff line change @@ -1987,14 +1987,36 @@ def test_process_options_fallback_to_user_install_when_gem_home_not_writable
19871987
19881988 FileUtils . chmod 0o000 , @gemhome
19891989
1990- use_ui ( @ui ) { Gem ::Installer . at @gem }
1990+ installer = use_ui ( @ui ) { Gem ::Installer . at @gem }
19911991
1992+ assert_equal Gem . user_dir , installer . gem_home
19921993 assert_equal "Defaulting to user installation because default installation directory (#{ @gemhome } ) is not writable." , @ui . output . strip
19931994 ensure
19941995 FileUtils . chmod 0o755 , @gemhome
19951996 ENV [ "GEM_HOME" ] = orig_gem_home
19961997 end
19971998
1999+ def test_process_options_does_not_fallback_to_user_install_when_gem_home_not_writable_and_no_user_install
2000+ if Process . uid . zero?
2001+ pend ( "skipped in root privilege" )
2002+ return
2003+ end
2004+
2005+ orig_gem_home = ENV . delete ( "GEM_HOME" )
2006+
2007+ @gem = setup_base_gem
2008+
2009+ FileUtils . chmod 0o000 , @gemhome
2010+
2011+ installer = use_ui ( @ui ) { Gem ::Installer . at @gem , user_install : false }
2012+
2013+ assert_equal @gemhome , installer . gem_home
2014+ assert_empty @ui . output . strip
2015+ ensure
2016+ FileUtils . chmod 0o755 , @gemhome
2017+ ENV [ "GEM_HOME" ] = orig_gem_home
2018+ end
2019+
19982020 def test_shebang_arguments
19992021 load_relative "no" do
20002022 installer = setup_base_installer
You can’t perform that action at this time.
0 commit comments