aboutsummaryrefslogtreecommitdiffstats
path: root/test/rubygems
diff options
context:
space:
mode:
authorEllen Marie Dash <me@duckie.co>2023-11-29 18:49:08 -0500
committergit <svn-admin@ruby-lang.org>2023-11-30 19:58:40 +0000
commit7008d97b76649928cd5552eb0f44a496d468daf0 (patch)
tree5dfe0a5e2ab0ccd82c9da6302ab58200706cff06 /test/rubygems
parent060f14bf62ad3f426a6666901c45b82d4334fa26 (diff)
downloadruby-7008d97b76649928cd5552eb0f44a496d468daf0.tar.gz
[rubygems/rubygems] Only show "Defaulting to user installation" message when it matters.
https://github.com/rubygems/rubygems/commit/61b0947225
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/test_gem_command.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/rubygems/test_gem_command.rb b/test/rubygems/test_gem_command.rb
index 3d0f04830e..d50f3d2c79 100644
--- a/test/rubygems/test_gem_command.rb
+++ b/test/rubygems/test_gem_command.rb
@@ -399,4 +399,66 @@ 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