diff options
| author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2023-12-01 12:53:43 +0100 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-12-07 13:56:22 +0900 |
| commit | 33bd95625756562f4865fbc6ad5c39e0cfbc26d6 (patch) | |
| tree | ab0a3ade84487022e7fd92b09e61fb9139d2f591 /test | |
| parent | 0f3f907e17bba1b94c5e202cb57988af8c6c91fc (diff) | |
[rubygems/rubygems] Better approach to falling back to user installation when GEM_HOME not writable
https://github.com/rubygems/rubygems/commit/f67bced16b
Diffstat (limited to 'test')
| -rw-r--r-- | test/rubygems/test_gem_command.rb | 62 | ||||
| -rw-r--r-- | test/rubygems/test_gem_install_update_options.rb | 31 | ||||
| -rw-r--r-- | test/rubygems/test_gem_installer.rb | 20 |
3 files changed, 20 insertions, 93 deletions
diff --git a/test/rubygems/test_gem_command.rb b/test/rubygems/test_gem_command.rb index d50f3d2c79..3d0f04830e 100644 --- a/test/rubygems/test_gem_command.rb +++ b/test/rubygems/test_gem_command.rb @@ -399,66 +399,4 @@ ERROR: Possible alternatives: non_existent_with_hint assert_equal expected, @ui.error end - - def test_show_defaulting_to_user_install_when_appropriate - omit "this test doesn't work with ruby-core setup" if ruby_repo? - - Gem.stub(:default_dir, "/this-directory-does-not-exist") do - # Replace `Gem.paths` with a new instance, so `Gem.paths.auto_user_install` - # is accurate. - Gem.stub(:paths, Gem::PathSupport.new(ENV)) do - output_regex = "Defaulting to user installation" - - test_command = Class.new(Gem::Command) do - def initialize - # "gem install" should ALWAYS print the warning. - super("install", "Gem::Command instance for testing") - end - - def execute - true - end - end - - cmd = test_command.new - - use_ui @ui do - cmd.invoke - assert_match output_regex, @ui.output, - "Gem.default_dir = #{Gem.default_dir.inspect}\n" \ - "Gem.paths.auto_user_install = #{Gem.paths.auto_user_install.inspect}" - end - end - end - end - - def test_dont_show_defaulting_to_user_install_when_appropriate - Gem.stub(:default_dir, "/this-directory-does-not-exist") do - # Replace `Gem.paths` with a new instance, so `Gem.paths.auto_user_install` - # is accurate. - Gem.stub(:paths, Gem::PathSupport.new(ENV)) do - output_regex = /^Defaulting to user installation/ - - test_command = Class.new(Gem::Command) do - def initialize - # "gem blargh" should NEVER print the warning. - super("blargh", "Gem::Command instance for testing") - end - - def execute - true - end - end - - cmd = test_command.new - - use_ui @ui do - cmd.invoke - assert_no_match output_regex, @ui.output, - "Gem.default_dir = #{Gem.default_dir.inspect}\n" \ - "Gem.paths.auto_user_install = #{Gem.paths.auto_user_install.inspect}" - end - end - end - end end diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index 8f92e43bf7..8fd5d9c543 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -156,37 +156,6 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase FileUtils.chmod 0o755, @gemhome end - def test_auto_install_dir_unless_gem_home_writable - if Process.uid.zero? - pend("test_auto_install_dir_unless_gem_home_writable test skipped in root privilege") - return - end - - orig_gem_home = ENV["GEM_HOME"] - ENV.delete("GEM_HOME") - - @spec = quick_gem "a" do |spec| - util_make_exec spec - end - - util_build_gem @spec - @gem = @spec.cache_file - - @cmd.handle_options %w[] - - assert_not_equal Gem.paths.home, Gem.user_dir - - FileUtils.chmod 0o755, @userhome - FileUtils.chmod 0o000, @gemhome - - Gem.use_paths nil, @userhome - - assert_equal Gem.paths.home, Gem.user_dir - ensure - FileUtils.chmod 0o755, @gemhome - ENV["GEM_HOME"] = orig_gem_home if orig_gem_home - end - def test_vendor vendordir(File.join(@tempdir, "vendor")) do @cmd.handle_options %w[--vendor] diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index a00814370f..03903ff9d3 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -1955,6 +1955,26 @@ end assert_equal " Plugins dir: #{plugins_dir}", errors.shift end + def test_process_options_fallback_to_user_install_when_gem_home_not_writable + if Process.uid.zero? + pend("skipped in root privilege") + return + end + + orig_gem_home = ENV.delete("GEM_HOME") + + @gem = setup_base_gem + + FileUtils.chmod 0o000, @gemhome + + use_ui(@ui) { Gem::Installer.at @gem } + + assert_equal "Defaulting to user installation because default installation directory (#{@gemhome}) is not writable.", @ui.output.strip + ensure + FileUtils.chmod 0o755, @gemhome + ENV["GEM_HOME"] = orig_gem_home + end + def test_shebang_arguments load_relative "no" do installer = setup_base_installer |
