diff options
Diffstat (limited to 'test/rubygems')
-rw-r--r-- | test/rubygems/test_gem_command.rb | 62 |
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 |