summaryrefslogtreecommitdiff
path: root/test/rubygems
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-02-01 11:14:04 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-02-01 11:14:57 +0900
commit600a715c9bde99fe2e9a669465d78833445273e8 (patch)
tree8244622e8cc02b40dd0dad29d30fc60a11342396 /test/rubygems
parentadc303131187654d8ce83f3db17eefa3d5bae26c (diff)
Merge the current master branch of rubygems/rubygems.
Just started to develop RubyGems 3.2.0.
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/test_deprecate.rb18
-rw-r--r--test/rubygems/test_gem.rb79
-rw-r--r--test/rubygems/test_gem_command_manager.rb41
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb37
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb857
-rw-r--r--test/rubygems/test_gem_commands_setup_command.rb37
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb40
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb54
-rw-r--r--test/rubygems/test_gem_config_file.rb7
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb2
-rw-r--r--test/rubygems/test_gem_doctor.rb28
-rw-r--r--test/rubygems/test_gem_gem_runner.rb30
-rw-r--r--test/rubygems/test_gem_installer.rb74
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb25
-rw-r--r--test/rubygems/test_gem_request_set.rb52
-rw-r--r--test/rubygems/test_gem_specification.rb13
-rw-r--r--test/rubygems/test_gem_uninstaller.rb104
-rw-r--r--test/rubygems/test_gem_version.rb2
19 files changed, 556 insertions, 946 deletions
diff --git a/test/rubygems/test_deprecate.rb b/test/rubygems/test_deprecate.rb
index b92bd1c3da..f5cd83ee89 100644
--- a/test/rubygems/test_deprecate.rb
+++ b/test/rubygems/test_deprecate.rb
@@ -77,4 +77,22 @@ class TestDeprecate < Gem::TestCase
assert_match(/on or after 2099-03-01/, err)
end
+ def test_deprecate_command
+ require 'rubygems/command'
+ foo_command = Class.new(Gem::Command) do
+ extend Gem::Deprecate
+
+ deprecate_command(2099, 4)
+
+ def execute
+ puts "pew pew!"
+ end
+ end
+
+ Gem::Commands.send(:const_set, :FooCommand, foo_command)
+ assert Gem::Commands::FooCommand.new("foo").deprecated?
+ ensure
+ Gem::Commands.send(:remove_const, :FooCommand)
+ end
+
end
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 6d223b7d69..2890e13dfb 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -11,12 +11,6 @@ if File.exist?(File.join(Dir.tmpdir, "Gemfile"))
raise "rubygems/bundler tests do not work correctly if there is #{ File.join(Dir.tmpdir, "Gemfile") }"
end
-# TODO: push this up to test_case.rb once battle tested
-
-$LOAD_PATH.map! do |path|
- path.dup.tap(&Gem::UNTAINT)
-end
-
class TestGem < Gem::TestCase
PLUGINS_LOADED = [] # rubocop:disable Style/MutableConstant
@@ -161,10 +155,8 @@ class TestGem < Gem::TestCase
def test_self_install_permissions_with_format_executable_and_non_standard_ruby_install_name
Gem::Installer.exec_format = nil
- with_clean_path_to_ruby do
- ruby_install_name 'ruby27' do
- assert_self_install_permissions(format_executable: true)
- end
+ ruby_install_name 'ruby27' do
+ assert_self_install_permissions(format_executable: true)
end
ensure
Gem::Installer.exec_format = nil
@@ -1024,21 +1016,17 @@ class TestGem < Gem::TestCase
end
def test_self_ruby_escaping_spaces_in_path
- with_clean_path_to_ruby do
- with_bindir_and_exeext("C:/Ruby 1.8/bin", ".exe") do
- ruby_install_name "ruby" do
- assert_equal "\"C:/Ruby 1.8/bin/ruby.exe\"", Gem.ruby
- end
+ with_bindir_and_exeext("C:/Ruby 1.8/bin", ".exe") do
+ ruby_install_name "ruby" do
+ assert_equal "\"C:/Ruby 1.8/bin/ruby.exe\"", Gem.ruby
end
end
end
def test_self_ruby_path_without_spaces
- with_clean_path_to_ruby do
- with_bindir_and_exeext("C:/Ruby18/bin", ".exe") do
- ruby_install_name "ruby" do
- assert_equal "C:/Ruby18/bin/ruby.exe", Gem.ruby
- end
+ with_bindir_and_exeext("C:/Ruby18/bin", ".exe") do
+ ruby_install_name "ruby" do
+ assert_equal "C:/Ruby18/bin/ruby.exe", Gem.ruby
end
end
end
@@ -1090,7 +1078,7 @@ class TestGem < Gem::TestCase
util_restore_RUBY_VERSION
end
- def test_self_ruby_version_with_prerelease
+ def test_self_ruby_version_with_svn_prerelease
util_set_RUBY_VERSION '2.6.0', -1, 63539, 'ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-linux]'
assert_equal Gem::Version.new('2.6.0.preview2'), Gem.ruby_version
@@ -1098,6 +1086,14 @@ class TestGem < Gem::TestCase
util_restore_RUBY_VERSION
end
+ def test_self_ruby_version_with_git_prerelease
+ util_set_RUBY_VERSION '2.7.0', -1, 'b563439274a402e33541f5695b1bfd4ac1085638', 'ruby 2.7.0preview3 (2019-11-23 master b563439274) [x86_64-linux]'
+
+ assert_equal Gem::Version.new('2.7.0.preview3'), Gem.ruby_version
+ ensure
+ util_restore_RUBY_VERSION
+ end
+
def test_self_ruby_version_with_non_mri_implementations_with_mri_prerelase_compatibility
util_set_RUBY_VERSION '2.6.0', -1, 63539, 'weirdjruby 9.2.0.0 (2.6.0preview2) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]', 'weirdjruby', '9.2.0.0'
@@ -1106,7 +1102,7 @@ class TestGem < Gem::TestCase
util_restore_RUBY_VERSION
end
- def test_self_ruby_version_with_trunk
+ def test_self_ruby_version_with_svn_trunk
util_set_RUBY_VERSION '1.9.2', -1, 23493, 'ruby 1.9.2dev (2009-05-20 trunk 23493) [x86_64-linux]'
assert_equal Gem::Version.new('1.9.2.dev'), Gem.ruby_version
@@ -1114,6 +1110,14 @@ class TestGem < Gem::TestCase
util_restore_RUBY_VERSION
end
+ def test_self_ruby_version_with_git_master
+ util_set_RUBY_VERSION '2.7.0', -1, '5de284ec78220e75643f89b454ce999da0c1c195', 'ruby 2.7.0dev (2019-12-23T01:37:30Z master 5de284ec78) [x86_64-linux]'
+
+ assert_equal Gem::Version.new('2.7.0.dev'), Gem.ruby_version
+ ensure
+ util_restore_RUBY_VERSION
+ end
+
def test_self_rubygems_version
assert_equal Gem::Version.new(Gem::VERSION), Gem.rubygems_version
end
@@ -1470,7 +1474,6 @@ class TestGem < Gem::TestCase
install_gem foo2
end
- Gem.searcher = nil
Gem::Specification.reset
gem 'foo'
@@ -1904,15 +1907,19 @@ You may need to `gem install -g` to install missing gems
end
def ruby_install_name(name)
- orig_RUBY_INSTALL_NAME = RbConfig::CONFIG['ruby_install_name']
- RbConfig::CONFIG['ruby_install_name'] = name
+ with_clean_path_to_ruby do
+ orig_RUBY_INSTALL_NAME = RbConfig::CONFIG['ruby_install_name']
+ RbConfig::CONFIG['ruby_install_name'] = name
- yield
- ensure
- if orig_RUBY_INSTALL_NAME
- RbConfig::CONFIG['ruby_install_name'] = orig_RUBY_INSTALL_NAME
- else
- RbConfig::CONFIG.delete 'ruby_install_name'
+ begin
+ yield
+ ensure
+ if orig_RUBY_INSTALL_NAME
+ RbConfig::CONFIG['ruby_install_name'] = orig_RUBY_INSTALL_NAME
+ else
+ RbConfig::CONFIG.delete 'ruby_install_name'
+ end
+ end
end
end
@@ -1924,16 +1931,6 @@ You may need to `gem install -g` to install missing gems
end
end
- def with_clean_path_to_ruby
- orig_ruby = Gem.ruby
-
- Gem.instance_variable_set :@ruby, nil
-
- yield
- ensure
- Gem.instance_variable_set :@ruby, orig_ruby
- end
-
def with_plugin(path)
test_plugin_path = File.expand_path("test/rubygems/plugin/#{path}",
PROJECT_DIR)
diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb
index 45be9f01be..c6aaff291a 100644
--- a/test/rubygems/test_gem_command_manager.rb
+++ b/test/rubygems/test_gem_command_manager.rb
@@ -224,26 +224,34 @@ class TestGemCommandManager < Gem::TestCase
end
#check defaults
- @command_manager.process_args %w[query]
+ Gem::Deprecate.skip_during do
+ @command_manager.process_args %w[query]
+ end
assert_equal(//, check_options[:name])
assert_equal :local, check_options[:domain]
assert_equal false, check_options[:details]
#check settings
check_options = nil
- @command_manager.process_args %w[query --name foobar --local --details]
+ Gem::Deprecate.skip_during do
+ @command_manager.process_args %w[query --name foobar --local --details]
+ end
assert_equal(/foobar/i, check_options[:name])
assert_equal :local, check_options[:domain]
assert_equal true, check_options[:details]
#remote domain
check_options = nil
- @command_manager.process_args %w[query --remote]
+ Gem::Deprecate.skip_during do
+ @command_manager.process_args %w[query --remote]
+ end
assert_equal :remote, check_options[:domain]
#both (local/remote) domains
check_options = nil
- @command_manager.process_args %w[query --both]
+ Gem::Deprecate.skip_during do
+ @command_manager.process_args %w[query --both]
+ end
assert_equal :both, check_options[:domain]
end
@@ -268,4 +276,29 @@ class TestGemCommandManager < Gem::TestCase
assert_equal Dir.pwd, check_options[:install_dir]
end
+ def test_deprecated_command
+ require 'rubygems/command'
+ foo_command = Class.new(Gem::Command) do
+ extend Gem::Deprecate
+
+ deprecate_command(2099, 4)
+
+ def execute
+ say "pew pew!"
+ end
+ end
+
+ Gem::Commands.send(:const_set, :FooCommand, foo_command)
+ @command_manager.register_command(:foo, foo_command.new("foo"))
+
+ use_ui @ui do
+ @command_manager.process_args(%w[foo])
+ end
+
+ assert_equal "pew pew!\n", @ui.output
+ assert_equal("WARNING: foo command is deprecated. It will be removed on or after 2099-04-01.\n", @ui.error)
+ ensure
+ Gem::Commands.send(:remove_const, :FooCommand)
+ end
+
end
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 50c447e2eb..a2e8f284eb 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -147,7 +147,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
error = @ui.error.split "\n"
assert_equal "WARNING: licenses is empty, but is recommended. Use a license identifier from", error.shift
assert_equal "http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.", error.shift
- assert_equal "WARNING: See http://guides.rubygems.org/specification-reference/ for help", error.shift
+ assert_equal "WARNING: See https://guides.rubygems.org/specification-reference/ for help", error.shift
assert_equal [], error
gem_file = File.join @tempdir, File.basename(@gem.cache_file)
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index e872a80957..4ebe1efecb 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -215,7 +215,6 @@ class TestGemCommandsPristineCommand < Gem::TestCase
io.write "# extconf.rb\nrequire 'mkmf'; create_makefile 'a'"
end
- util_build_gem a
install_gem a
@cmd.options[:args] = %w[a]
@@ -491,6 +490,42 @@ class TestGemCommandsPristineCommand < Gem::TestCase
refute File.exist? gem_lib
end
+ def test_execute_only_plugins
+ a = util_spec 'a' do |s|
+ s.executables = %w[foo]
+ s.files = %w[bin/foo lib/a.rb lib/rubygems_plugin.rb]
+ end
+ write_file File.join(@tempdir, 'lib', 'a.rb') do |fp|
+ fp.puts "puts __FILE__"
+ end
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |fp|
+ fp.puts "puts __FILE__"
+ end
+ write_file File.join(@tempdir, 'bin', 'foo') do |fp|
+ fp.puts "#!/usr/bin/ruby"
+ end
+
+ install_gem a
+
+ gem_lib = File.join @gemhome, 'gems', a.full_name, 'lib', 'a.rb'
+ gem_plugin = File.join @gemhome, 'plugins', 'a_plugin.rb'
+ gem_exec = File.join @gemhome, 'bin', 'foo'
+
+ FileUtils.rm gem_exec
+ FileUtils.rm gem_plugin
+ FileUtils.rm gem_lib
+
+ @cmd.handle_options %w[--all --only-plugins]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ refute File.exist? gem_exec
+ assert File.exist? gem_plugin
+ refute File.exist? gem_lib
+ end
+
def test_execute_bindir
a = util_spec 'a' do |s|
s.name = "test_gem"
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
deleted file mode 100644
index 6183e592e9..0000000000
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ /dev/null
@@ -1,857 +0,0 @@
-# frozen_string_literal: true
-require 'rubygems/test_case'
-require 'rubygems/commands/query_command'
-
-module TestGemCommandsQueryCommandSetup
- def setup
- super
-
- @cmd = Gem::Commands::QueryCommand.new
-
- @specs = add_gems_to_fetcher
- @stub_ui = Gem::MockGemUi.new
- @stub_fetcher = Gem::FakeFetcher.new
-
- @stub_fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
- raise Gem::RemoteFetcher::FetchError
- end
- end
-end
-
-class TestGemCommandsQueryCommandWithInstalledGems < Gem::TestCase
-
- include TestGemCommandsQueryCommandSetup
-
- def test_execute
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-r]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (2)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_all
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-r --all]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (2, 1)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_all_prerelease
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-r --all --prerelease]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (3.a, 2, 1)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_details
- spec_fetcher do |fetcher|
- fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 4
- s.authors = ['Abraham Lincoln', 'Hirohito']
- s.homepage = 'http://a.example.com/'
- end
-
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-r -d]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (2)
- Authors: Abraham Lincoln, Hirohito
- Homepage: http://a.example.com/
-
- This is a lot of text. This is a lot of text. This is a lot of text.
- This is a lot of text.
-
-pl (1)
- Platform: i386-linux
- Author: A User
- Homepage: http://example.com
-
- this is a summary
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_details_cleans_text
- spec_fetcher do |fetcher|
- fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 4
- s.authors = ["Abraham Lincoln \x01", "\x02 Hirohito"]
- s.homepage = "http://a.example.com/\x03"
- end
-
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-r -d]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (2)
- Authors: Abraham Lincoln ., . Hirohito
- Homepage: http://a.example.com/.
-
- This is a lot of text. This is a lot of text. This is a lot of text.
- This is a lot of text.
-
-pl (1)
- Platform: i386-linux
- Author: A User
- Homepage: http://example.com
-
- this is a summary
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_details_truncates_summary
- spec_fetcher do |fetcher|
- fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 10_000
- s.authors = ["Abraham Lincoln \x01", "\x02 Hirohito"]
- s.homepage = "http://a.example.com/\x03"
- end
-
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-r -d]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (2)
- Authors: Abraham Lincoln ., . Hirohito
- Homepage: http://a.example.com/.
-
- Truncating the summary for a-2 to 100,000 characters:
-#{" This is a lot of text. This is a lot of text. This is a lot of text.\n" * 1449} This is a lot of te
-
-pl (1)
- Platform: i386-linux
- Author: A User
- Homepage: http://example.com
-
- this is a summary
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_installed
- @cmd.handle_options %w[-n a --installed]
-
- assert_raises Gem::MockGemUi::SystemExitException do
- use_ui @stub_ui do
- @cmd.execute
- end
- end
-
- assert_equal "true\n", @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_installed_inverse
- @cmd.handle_options %w[-n a --no-installed]
-
- e = assert_raises Gem::MockGemUi::TermError do
- use_ui @stub_ui do
- @cmd.execute
- end
- end
-
- assert_equal "false\n", @stub_ui.output
- assert_equal '', @stub_ui.error
-
- assert_equal 1, e.exit_code
- end
-
- def test_execute_installed_inverse_not_installed
- @cmd.handle_options %w[-n not_installed --no-installed]
-
- assert_raises Gem::MockGemUi::SystemExitException do
- use_ui @stub_ui do
- @cmd.execute
- end
- end
-
- assert_equal "true\n", @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_installed_no_name
- @cmd.handle_options %w[--installed]
-
- e = assert_raises Gem::MockGemUi::TermError do
- use_ui @stub_ui do
- @cmd.execute
- end
- end
-
- assert_equal '', @stub_ui.output
- assert_equal "ERROR: You must specify a gem name\n", @stub_ui.error
-
- assert_equal 4, e.exit_code
- end
-
- def test_execute_installed_not_installed
- @cmd.handle_options %w[-n not_installed --installed]
-
- e = assert_raises Gem::MockGemUi::TermError do
- use_ui @stub_ui do
- @cmd.execute
- end
- end
-
- assert_equal "false\n", @stub_ui.output
- assert_equal '', @stub_ui.error
-
- assert_equal 1, e.exit_code
- end
-
- def test_execute_installed_version
- @cmd.handle_options %w[-n a --installed --version 2]
-
- assert_raises Gem::MockGemUi::SystemExitException do
- use_ui @stub_ui do
- @cmd.execute
- end
- end
-
- assert_equal "true\n", @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_installed_version_not_installed
- @cmd.handle_options %w[-n c --installed --version 2]
-
- e = assert_raises Gem::MockGemUi::TermError do
- use_ui @stub_ui do
- @cmd.execute
- end
- end
-
- assert_equal "false\n", @stub_ui.output
- assert_equal '', @stub_ui.error
-
- assert_equal 1, e.exit_code
- end
-
- def test_execute_local
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.options[:domain] = :local
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-a (3.a, 2, 1)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_local_notty
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[]
-
- @stub_ui.outs.tty = false
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-a (3.a, 2, 1)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_local_quiet
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.options[:domain] = :local
- Gem.configuration.verbose = false
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-a (3.a, 2, 1)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_no_versions
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-r --no-versions]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a
-pl
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_notty
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-r]
-
- @stub_ui.outs.tty = false
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-a (2)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_prerelease
- @cmd.handle_options %w[-r --prerelease]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (3.a)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_prerelease_local
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-l --prerelease]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-a (3.a, 2, 1)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- end
-
- def test_execute_no_prerelease_local
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-l --no-prerelease]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-a (2, 1)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- end
-
- def test_execute_remote
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.options[:domain] = :remote
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (2)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_remote_notty
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[]
-
- @stub_ui.outs.tty = false
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-a (3.a, 2, 1)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_remote_quiet
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.options[:domain] = :remote
- Gem.configuration.verbose = false
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-a (2)
-pl (1 i386-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_make_entry
- a_2_name = @specs['a-2'].original_name
-
- @stub_fetcher.data.delete \
- "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{a_2_name}.gemspec.rz"
-
- a2 = @specs['a-2']
- entry_tuples = [
- [Gem::NameTuple.new(a2.name, a2.version, a2.platform),
- Gem.sources.first],
- ]
-
- platforms = { a2.version => [a2.platform] }
-
- entry = @cmd.send :make_entry, entry_tuples, platforms
-
- assert_equal 'a (2)', entry
- end
-
- # Test for multiple args handling!
- def test_execute_multiple_args
- spec_fetcher do |fetcher|
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[a pl]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- assert_match %r%^a %, @stub_ui.output
- assert_match %r%^pl %, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_show_gems
- @cmd.options[:name] = //
- @cmd.options[:domain] = :remote
-
- use_ui @stub_ui do
- @cmd.send :show_gems, /a/i
- end
-
- assert_match %r%^a %, @stub_ui.output
- refute_match %r%^pl %, @stub_ui.output
- assert_empty @stub_ui.error
- end
-
- private
-
- def add_gems_to_fetcher
- spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 2
- fetcher.spec 'a', '3.a'
- end
- end
-
-end
-
-class TestGemCommandsQueryCommandWithoutInstalledGems < Gem::TestCase
-
- include TestGemCommandsQueryCommandSetup
-
- def test_execute_platform
- spec_fetcher do |fetcher|
- fetcher.spec 'a', 1
- fetcher.spec 'a', 1 do |s|
- s.platform = 'x86-linux'
- end
-
- fetcher.spec 'a', 2 do |s|
- s.platform = 'universal-darwin'
- end
- end
-
- @cmd.handle_options %w[-r -a]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-a (2 universal-darwin, 1 ruby x86-linux)
- EOF
-
- assert_equal expected, @stub_ui.output
- assert_equal '', @stub_ui.error
- end
-
- def test_execute_show_default_gems
- spec_fetcher { |fetcher| fetcher.spec 'a', 2 }
-
- a1 = new_default_spec 'a', 1
- install_default_specs a1
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-a (2, default: 1)
-EOF
-
- assert_equal expected, @stub_ui.output
- end
-
- def test_execute_show_default_gems_with_platform
- a1 = new_default_spec 'a', 1
- a1.platform = 'java'
- install_default_specs a1
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-a (default: 1 java)
-EOF
-
- assert_equal expected, @stub_ui.output
- end
-
- def test_execute_default_details
- spec_fetcher do |fetcher|
- fetcher.spec 'a', 2
- end
-
- a1 = new_default_spec 'a', 1
- install_default_specs a1
-
- @cmd.handle_options %w[-l -d]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-a (2, 1)
- Author: A User
- Homepage: http://example.com
- Installed at (2): #{@gemhome}
- (1, default): #{a1.base_dir}
-
- this is a summary
- EOF
-
- assert_equal expected, @stub_ui.output
- end
-
- def test_execute_local_details
- spec_fetcher do |fetcher|
- fetcher.spec 'a', 1 do |s|
- s.platform = 'x86-linux'
- end
-
- fetcher.spec 'a', 2 do |s|
- s.summary = 'This is a lot of text. ' * 4
- s.authors = ['Abraham Lincoln', 'Hirohito']
- s.homepage = 'http://a.example.com/'
- s.platform = 'universal-darwin'
- end
-
- fetcher.legacy_platform
- end
-
- @cmd.handle_options %w[-l -d]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- str = @stub_ui.output
-
- str.gsub!(/\(\d\): [^\n]*/, "-")
- str.gsub!(/at: [^\n]*/, "at: -")
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-a (2, 1)
- Platforms:
- 1: x86-linux
- 2: universal-darwin
- Authors: Abraham Lincoln, Hirohito
- Homepage: http://a.example.com/
- Installed at -
- -
-
- This is a lot of text. This is a lot of text. This is a lot of text.
- This is a lot of text.
-
-pl (1)
- Platform: i386-linux
- Author: A User
- Homepage: http://example.com
- Installed at: -
-
- this is a summary
- EOF
-
- assert_equal expected, @stub_ui.output
- end
-
- def test_execute_exact_remote
- spec_fetcher do |fetcher|
- fetcher.spec 'coolgem-omg', 3
- fetcher.spec 'coolgem', '4.2.1'
- fetcher.spec 'wow_coolgem', 1
- end
-
- @cmd.handle_options %w[--remote --exact coolgem]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** REMOTE GEMS ***
-
-coolgem (4.2.1)
- EOF
-
- assert_equal expected, @stub_ui.output
- end
-
- def test_execute_exact_local
- spec_fetcher do |fetcher|
- fetcher.spec 'coolgem-omg', 3
- fetcher.spec 'coolgem', '4.2.1'
- fetcher.spec 'wow_coolgem', 1
- end
-
- @cmd.handle_options %w[--exact coolgem]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-coolgem (4.2.1)
- EOF
-
- assert_equal expected, @stub_ui.output
- end
-
- def test_execute_exact_multiple
- spec_fetcher do |fetcher|
- fetcher.spec 'coolgem-omg', 3
- fetcher.spec 'coolgem', '4.2.1'
- fetcher.spec 'wow_coolgem', 1
-
- fetcher.spec 'othergem-omg', 3
- fetcher.spec 'othergem', '1.2.3'
- fetcher.spec 'wow_othergem', 1
- end
-
- @cmd.handle_options %w[--exact coolgem othergem]
-
- use_ui @stub_ui do
- @cmd.execute
- end
-
- expected = <<-EOF
-
-*** LOCAL GEMS ***
-
-coolgem (4.2.1)
-
-*** LOCAL GEMS ***
-
-othergem (1.2.3)
- EOF
-
- assert_equal expected, @stub_ui.output
- end
-
- private
-
- def add_gems_to_fetcher
- spec_fetcher do |fetcher|
- fetcher.download 'a', 1
- fetcher.download 'a', 2
- fetcher.download 'a', '3.a'
- end
- end
-
-end
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index c63f7177c7..9dc88d582a 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -98,6 +98,18 @@ class TestGemCommandsSetupCommand < Gem::TestCase
File.join @gemhome, 'bin', name
end
+ def gem_install_with_plugin(name)
+ gem = util_spec name do |s|
+ s.files = %W[lib/rubygems_plugin.rb]
+ end
+ write_file File.join @tempdir, 'lib', 'rubygems_plugin.rb' do |f|
+ f.puts "require '#{gem.plugins.first}'"
+ end
+ install_gem gem
+
+ File.join Gem.plugins_dir, "#{name}_plugin.rb"
+ end
+
def test_execute_regenerate_binstubs
gem_bin_path = gem_install 'a'
write_file gem_bin_path do |io|
@@ -123,6 +135,31 @@ class TestGemCommandsSetupCommand < Gem::TestCase
assert_equal "I changed it!\n", File.read(gem_bin_path)
end
+ def test_execute_regenerate_plugins
+ gem_plugin_path = gem_install_with_plugin 'a'
+ write_file gem_plugin_path do |io|
+ io.puts 'I changed it!'
+ end
+
+ @cmd.options[:document] = []
+ @cmd.execute
+
+ assert_match %r{\Arequire}, File.read(gem_plugin_path)
+ end
+
+ def test_execute_no_regenerate_plugins
+ gem_plugin_path = gem_install_with_plugin 'a'
+ write_file gem_plugin_path do |io|
+ io.puts 'I changed it!'
+ end
+
+ @cmd.options[:document] = []
+ @cmd.options[:regenerate_plugins] = false
+ @cmd.execute
+
+ assert_equal "I changed it!\n", File.read(gem_plugin_path)
+ end
+
def test_execute_informs_about_installed_executables
use_ui @ui do
@cmd.execute
diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb
index b63fbce81f..3a0899245b 100644
--- a/test/rubygems/test_gem_commands_sources_command.rb
+++ b/test/rubygems/test_gem_commands_sources_command.rb
@@ -247,7 +247,7 @@ source http://gems.example.com/ already present in the cache
end
def test_execute_add_http_rubygems_org
- http_rubygems_org = 'http://rubygems.org'
+ http_rubygems_org = 'http://rubygems.org/'
spec_fetcher do |fetcher|
fetcher.spec 'a', 1
@@ -284,6 +284,44 @@ source http://gems.example.com/ already present in the cache
assert_empty @ui.error
end
+ def test_execute_add_https_rubygems_org
+ https_rubygems_org = 'https://rubygems.org/'
+
+ spec_fetcher do |fetcher|
+ fetcher.spec 'a', 1
+ end
+
+ specs = Gem::Specification.map do |spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
+
+ specs_dump_gz = StringIO.new
+ Zlib::GzipWriter.wrap specs_dump_gz do |io|
+ Marshal.dump specs, io
+ end
+
+ @fetcher.data["#{https_rubygems_org}/specs.#{@marshal_version}.gz"] =
+ specs_dump_gz.string
+
+ @cmd.handle_options %W[--add #{https_rubygems_org}]
+
+ ui = Gem::MockGemUi.new "n"
+
+ use_ui ui do
+ assert_raises Gem::MockGemUi::TermError do
+ @cmd.execute
+ end
+ end
+
+ assert_equal [@gem_repo], Gem.sources
+
+ expected = <<-EXPECTED
+ EXPECTED
+
+ assert_equal expected, @ui.output
+ assert_empty @ui.error
+ end
+
def test_execute_add_bad_uri
@cmd.handle_options %w[--add beta-gems.example.com]
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index 37f990ea1a..340c658b9d 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -159,6 +159,44 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
assert_empty out
end
+ def test_execute_system_specific_older_than_3_2_removes_plugins_dir
+ spec_fetcher do |fetcher|
+ fetcher.download 'rubygems-update', 3.1 do |s|
+ s.files = %w[setup.rb]
+ end
+ end
+
+ @cmd.options[:args] = []
+ @cmd.options[:system] = "3.1"
+
+ FileUtils.mkdir_p Gem.plugins_dir
+ write_file File.join(Gem.plugins_dir, 'a_plugin.rb')
+
+ @cmd.execute
+
+ refute_path_exists Gem.plugins_dir, "Plugins folder not removed when updating rubygems to pre-3.2"
+ end
+
+ def test_execute_system_specific_newer_than_or_equal_to_3_2_leaves_plugins_dir_alone
+ spec_fetcher do |fetcher|
+ fetcher.download 'rubygems-update', 3.2 do |s|
+ s.files = %w[setup.rb]
+ end
+ end
+
+ @cmd.options[:args] = []
+ @cmd.options[:system] = "3.2"
+
+ FileUtils.mkdir_p Gem.plugins_dir
+ plugin_file = File.join(Gem.plugins_dir, 'a_plugin.rb')
+ write_file plugin_file
+
+ @cmd.execute
+
+ assert_path_exists Gem.plugins_dir, "Plugin folder removed when updating rubygems to post-3.2"
+ assert_path_exists plugin_file, "Plugin removed when updating rubygems to post-3.2"
+ end
+
def test_execute_system_specifically_to_latest_version
spec_fetcher do |fetcher|
fetcher.download 'rubygems-update', 8 do |s|
@@ -359,10 +397,10 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
end
def test_execute_user_install
- spec_fetcher do |fetcher|
- fetcher.download 'a', 2
- fetcher.spec 'a', 1
- end
+ a = util_spec "a", 1
+ b = util_spec "b", 1
+ install_gem_user(a)
+ install_gem(b)
@cmd.handle_options %w[--user-install]
@@ -373,7 +411,13 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
installer = @cmd.installer
user_install = installer.instance_variable_get :@user_install
- assert user_install, 'user_install must be set on the installer'
+ assert user_install, "user_install must be set on the installer"
+
+ out = @ui.output.split "\n"
+ assert_equal "Updating installed gems", out.shift
+ assert_equal "Updating a", out.shift
+ assert_equal "Gems updated: a", out.shift
+ assert_empty out
end
def test_fetch_remote_gems
diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb
index 492a0c5a05..8ea8fa61e5 100644
--- a/test/rubygems/test_gem_config_file.rb
+++ b/test/rubygems/test_gem_config_file.rb
@@ -11,10 +11,6 @@ class TestGemConfigFile < Gem::TestCase
@cfg_args = %W[--config-file #{@temp_conf}]
- @orig_SYSTEM_WIDE_CONFIG_FILE = Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE
- Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
- Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
- File.join(@tempdir, 'system-gemrc')
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
Gem::ConfigFile::PLATFORM_DEFAULTS.clear
@@ -27,9 +23,6 @@ class TestGemConfigFile < Gem::TestCase
def teardown
Gem::ConfigFile::OPERATING_SYSTEM_DEFAULTS.clear
Gem::ConfigFile::PLATFORM_DEFAULTS.clear
- Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
- Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
- @orig_SYSTEM_WIDE_CONFIG_FILE
ENV['GEMRC'] = @env_gemrc
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index 22f3a9158f..487b8290bb 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -440,7 +440,7 @@ class TestGemDependencyInstaller < Gem::TestCase
e1 = util_spec 'e', '1', nil, 'extconf.rb' do |s|
s.extensions << 'extconf.rb'
end
- e1_gem = File.join @tempdir, 'gems', "#{e1.full_name}.gem"
+ e1_gem = e1.cache_file
_, f1_gem = util_gem 'f', '1', 'e' => nil
diff --git a/test/rubygems/test_gem_doctor.rb b/test/rubygems/test_gem_doctor.rb
index a0e3a18d7f..75d406ac88 100644
--- a/test/rubygems/test_gem_doctor.rb
+++ b/test/rubygems/test_gem_doctor.rb
@@ -153,6 +153,34 @@ This directory does not appear to be a RubyGems repository, skipping
assert true # count
end
+ def test_doctor_badly_named_plugins
+ gem 'a'
+
+ Gem.use_paths @gemhome.to_s
+
+ FileUtils.mkdir_p Gem.plugins_dir
+ bad_plugin = File.join(Gem.plugins_dir, "a_badly_named_file.rb")
+ write_file bad_plugin
+
+ doctor = Gem::Doctor.new @gemhome
+
+ capture_io do
+ use_ui @ui do
+ doctor.doctor
+ end
+ end
+
+ # refute_path_exists bad_plugin
+
+ expected = <<-OUTPUT
+Checking #{@gemhome}
+Removed file plugins/a_badly_named_file.rb
+
+ OUTPUT
+
+ assert_equal expected, @ui.output
+ end
+
def test_gem_repository_eh
doctor = Gem::Doctor.new @gemhome
diff --git a/test/rubygems/test_gem_gem_runner.rb b/test/rubygems/test_gem_gem_runner.rb
index efde71dce6..71b792c957 100644
--- a/test/rubygems/test_gem_gem_runner.rb
+++ b/test/rubygems/test_gem_gem_runner.rb
@@ -67,4 +67,34 @@ class TestGemGemRunner < Gem::TestCase
assert_equal %w[--foo], args
end
+ def test_info_succeeds
+ args = %w[info]
+
+ use_ui @ui do
+ assert_nil @runner.run(args)
+ end
+
+ assert_empty @ui.error
+ end
+
+ def test_list_succeeds
+ args = %w[list]
+
+ use_ui @ui do
+ assert_nil @runner.run(args)
+ end
+
+ assert_empty @ui.error
+ end
+
+ def test_search_succeeds
+ args = %w[search]
+
+ use_ui @ui do
+ assert_nil @runner.run(args)
+ end
+
+ assert_empty @ui.error
+ end
+
end
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 731a1ac01d..eaeff4a8fc 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -744,6 +744,70 @@ gem 'other', version
assert_match(/#{default_shebang}/, shebang_line)
end
+ def test_generate_plugins
+ installer = util_setup_installer do |spec|
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
+ io.write "puts __FILE__"
+ end
+
+ spec.files += %w[lib/rubygems_plugin.rb]
+ end
+
+ build_rake_in do
+ installer.install
+ end
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+
+ FileUtils.rm plugin_path
+
+ installer.generate_plugins
+
+ assert File.exist?(plugin_path), 'plugin not written'
+ end
+
+ def test_keeps_plugins_up_to_date
+ # NOTE: version a-2 is already installed by setup hooks
+
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
+ io.write "puts __FILE__"
+ end
+
+ build_rake_in do
+ util_setup_installer do |spec|
+ spec.version = '1'
+ spec.files += %w[lib/rubygems_plugin.rb]
+ end.install
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+ refute File.exist?(plugin_path), 'old version installed while newer version without plugin also installed, but plugin written'
+
+ util_setup_installer do |spec|
+ spec.version = '2'
+ spec.files += %w[lib/rubygems_plugin.rb]
+ end.install
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+ assert File.exist?(plugin_path), 'latest version reinstalled, but plugin not written'
+ assert_match %r{\Arequire.*a-2/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'written plugin has incorrect content'
+
+ util_setup_installer do |spec|
+ spec.version = '3'
+ spec.files += %w[lib/rubygems_plugin.rb]
+ end.install
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+ assert File.exist?(plugin_path), 'latest version installed, but plugin removed'
+ assert_match %r{\Arequire.*a-3/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'written plugin has incorrect content'
+
+ util_setup_installer do |spec|
+ spec.version = '4'
+ end.install
+
+ refute File.exist?(plugin_path), 'new version installed without a plugin while older version with a plugin installed, but plugin not removed'
+ end
+ end
+
def test_initialize
spec = util_spec 'a' do |s|
s.platform = Gem::Platform.new 'mswin32'
@@ -940,7 +1004,13 @@ gem 'other', version
end
def test_install_creates_binstub_that_prefers_user_installed_gem_to_default
- install_default_gems new_default_spec('default', '2')
+ default_spec = new_default_spec('default', '2', nil, 'exe/executable')
+ default_spec.executables = 'executable'
+ install_default_gems default_spec
+
+ exe = File.join @gemhome, 'bin', 'executable'
+
+ assert_path_exists exe, "default gem's executable not installed"
installer = util_setup_installer do |spec|
spec.name = 'default'
@@ -958,8 +1028,6 @@ gem 'other', version
end
end
- exe = File.join @gemhome, 'bin', 'executable'
-
e = assert_raises RuntimeError do
instance_eval File.read(exe)
end
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index 76a66af867..7f773febbc 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -153,20 +153,18 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
assert_equal proxy_uri, fetcher.instance_variable_get(:@proxy).to_s
end
- def test_fetch_size_bad_uri
+ def test_fetch_path_bad_uri
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
e = assert_raises ArgumentError do
- Gem::Deprecate.skip_during do
- fetcher.fetch_size 'gems.example.com/yaml'
- end
+ @fetcher.fetch_path("gems.example.com/yaml", nil, true)
end
assert_equal 'uri scheme is invalid: nil', e.message
end
- def test_fetch_size_socket_error
+ def test_fetch_path_socket_error
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
def fetcher.request(uri, request_class, last_modified = nil)
@@ -175,9 +173,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
uri = 'http://gems.example.com/yaml'
e = assert_raises Gem::RemoteFetcher::FetchError do
- Gem::Deprecate.skip_during do
- fetcher.fetch_size uri
- end
+ @fetcher.fetch_path(uri, nil, true)
end
assert_equal "SocketError: oops (#{uri})", e.message
@@ -186,9 +182,8 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_no_proxy
use_ui @stub_ui do
assert_data_from_server @fetcher.fetch_path(@server_uri)
- Gem::Deprecate.skip_during do
- assert_equal SERVER_DATA.size, @fetcher.fetch_size(@server_uri)
- end
+ response = @fetcher.fetch_path(@server_uri, nil, true)
+ assert_equal SERVER_DATA.size, response['content-length'].to_i
end
end
@@ -917,7 +912,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
def test_ssl_client_cert_auth_connection
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
skip 'openssl in jruby fails' if java_platform?
ssl_server = self.class.start_ssl_server({
@@ -935,8 +929,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
def test_do_not_allow_invalid_client_cert_auth_connection
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
-
ssl_server = self.class.start_ssl_server({
:SSLVerifyClient =>
OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT})
@@ -1083,9 +1075,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
DIR = File.expand_path(File.dirname(__FILE__))
def start_ssl_server(config = {})
- raise MiniTest::Skip, 'openssl not installed' unless
- defined?(OpenSSL::SSL)
-
null_logger = NilLog.new
server = WEBrick::HTTPServer.new({
:Port => 0,
@@ -1109,8 +1098,8 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
begin
server.start
rescue Exception => ex
- abort ex.message
puts "ERROR during server thread: #{ex.message}"
+ raise
ensure
server.shutdown
end
diff --git a/test/rubygems/test_gem_request_set.rb b/test/rubygems/test_gem_request_set.rb
index ac344015e7..fb71829471 100644
--- a/test/rubygems/test_gem_request_set.rb
+++ b/test/rubygems/test_gem_request_set.rb
@@ -183,6 +183,58 @@ DEPENDENCIES
assert_path_exists File.join @gemhome, 'specifications', 'b-1.gemspec'
end
+ def test_install_from_gemdeps_complex_dependencies
+ quick_gem("z", 1)
+ quick_gem("z", "1.0.1")
+ quick_gem("z", "1.0.2")
+ quick_gem("z", "1.0.3")
+ quick_gem("z", 2)
+
+ spec_fetcher do |fetcher|
+ fetcher.download "z", 1
+ end
+
+ rs = Gem::RequestSet.new
+ installed = []
+
+ File.open 'Gemfile.lock', 'w' do |io|
+ io.puts <<-LOCKFILE
+GEM
+ remote: #{@gem_repo}
+ specs:
+ z (1)
+
+PLATFORMS
+ #{Gem::Platform::RUBY}
+
+DEPENDENCIES
+ z (~> 1.0, >= 1.0.1)
+ LOCKFILE
+ end
+
+ File.open 'testo.gemspec', 'w' do |io|
+ io.puts <<-LOCKFILE
+Gem::Specification.new do |spec|
+ spec.name = 'testo'
+ spec.version = '1.0.0'
+ spec.add_dependency('z', '~> 1.0', '>= 1.0.1')
+end
+ LOCKFILE
+ end
+
+ File.open 'Gemfile', 'w' do |io|
+ io.puts("gemspec")
+ end
+
+ rs.install_from_gemdeps :gemdeps => 'Gemfile' do |req, installer|
+ installed << req.full_name
+ end
+
+ assert_includes installed, 'z-1.0.3'
+
+ assert_path_exists File.join @gemhome, 'specifications', 'z-1.0.3.gemspec'
+ end
+
def test_install_from_gemdeps_version_mismatch
spec_fetcher do |fetcher|
fetcher.gem 'a', 2
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index dbd45a31fd..b7df8b71fd 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -2784,7 +2784,7 @@ end
add_runtime_dependency 'l', '~> 1.2', '> 1.2.3'
#{w}: open-ended dependency on o (>= 0) is not recommended
use a bounded requirement, such as '~> x.y'
-#{w}: See http://guides.rubygems.org/specification-reference/ for help
+#{w}: See https://guides.rubygems.org/specification-reference/ for help
EXPECTED
assert_equal expected, @ui.error, 'warning'
@@ -2816,7 +2816,7 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
end
assert_equal <<-EXPECTED, @ui.error
-#{w}: See http://guides.rubygems.org/specification-reference/ for help
+#{w}: See https://guides.rubygems.org/specification-reference/ for help
EXPECTED
end
end
@@ -2927,7 +2927,7 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
end
end
- assert_match 'See http://guides.rubygems.org/specification-reference/ for help', @ui.error
+ assert_match 'See https://guides.rubygems.org/specification-reference/ for help', @ui.error
end
def test_validate_executables
@@ -3100,7 +3100,7 @@ Please report a bug if this causes problems.
assert_equal '"ftp://rubygems.org" is not a valid HTTP URI', e.message
- @a1.homepage = 'http://rubygems.org'
+ @a1.homepage = 'https://rubygems.org/'
assert_equal true, @a1.validate
@a1.homepage = 'https://rubygems.org'
@@ -3430,7 +3430,7 @@ Did you mean 'Ruby'?
@a1.validate
end
- assert_match 'See http://guides.rubygems.org/specification-reference/ for help', @ui.error
+ assert_match 'See https://guides.rubygems.org/specification-reference/ for help', @ui.error
end
def test_version
@@ -3532,7 +3532,8 @@ Did you mean 'Ruby'?
s.metadata = {
"one" => "two",
"home" => "three",
- "homepage_uri" => "https://example.com/user/repo"
+ "homepage_uri" => "https://example.com/user/repo",
+ "funding_uri" => "https://example.com/donate"
}
end
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index bf5ef5b4a2..df8dfd9a95 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -169,6 +169,41 @@ class TestGemUninstaller < Gem::InstallerTestCase
end
end
+ def test_remove_plugins
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
+ io.write "puts __FILE__"
+ end
+
+ @spec.files += %w[lib/rubygems_plugin.rb]
+
+ Gem::Installer.at(Gem::Package.build(@spec)).install
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+ assert File.exist?(plugin_path), 'plugin not written'
+
+ Gem::Uninstaller.new(nil).remove_plugins @spec
+
+ refute File.exist?(plugin_path), 'plugin not removed'
+ end
+
+ def test_regenerate_plugins_for
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
+ io.write "puts __FILE__"
+ end
+
+ @spec.files += %w[lib/rubygems_plugin.rb]
+
+ Gem::Installer.at(Gem::Package.build(@spec)).install
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+ assert File.exist?(plugin_path), 'plugin not written'
+
+ FileUtils.rm plugin_path
+ Gem::Uninstaller.new(nil).regenerate_plugins_for @spec
+
+ assert File.exist?(plugin_path), 'plugin not regenerated'
+ end
+
def test_path_ok_eh
uninstaller = Gem::Uninstaller.new nil
@@ -524,6 +559,35 @@ create_makefile '#{@spec.name}'
assert_match %r!Successfully uninstalled q-1!, lines.last
end
+ def test_uninstall_prompt_only_lists_the_dependents_that_prevented_uninstallation
+ quick_gem 'r', '1' do |s|
+ s.add_development_dependency 'q', '= 1'
+ end
+
+ quick_gem 's', '1' do |s|
+ s.add_dependency 'q', '= 1'
+ end
+
+ quick_gem 'q', '1'
+
+ un = Gem::Uninstaller.new('q', :check_dev => false)
+ ui = Gem::MockGemUi.new("y\n")
+
+ use_ui ui do
+ un.uninstall
+ end
+
+ lines = ui.output.split("\n")
+ lines.shift
+
+ assert_match %r!You have requested to uninstall the gem:!, lines.shift
+ lines.shift
+ lines.shift
+
+ assert_match %r!s-1 depends on q \(= 1\)!, lines.shift
+ assert_match %r!Successfully uninstalled q-1!, lines.last
+ end
+
def test_uninstall_no_permission
uninstaller = Gem::Uninstaller.new @spec.name, :executables => true
@@ -542,4 +606,44 @@ create_makefile '#{@spec.name}'
end
end
+ def test_uninstall_keeps_plugins_up_to_date
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
+ io.write "puts __FILE__"
+ end
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+
+ @spec.version = '1'
+ Gem::Installer.at(Gem::Package.build(@spec)).install
+
+ refute File.exist?(plugin_path), 'version without plugin installed, but plugin written'
+
+ @spec.files += %w[lib/rubygems_plugin.rb]
+ @spec.version = '2'
+ Gem::Installer.at(Gem::Package.build(@spec)).install
+
+ assert File.exist?(plugin_path), 'version with plugin installed, but plugin not written'
+ assert_match %r{\Arequire.*a-2/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'written plugin has incorrect content'
+
+ @spec.version = '3'
+ Gem::Installer.at(Gem::Package.build(@spec)).install
+
+ assert File.exist?(plugin_path), 'version with plugin installed, but plugin removed'
+ assert_match %r{\Arequire.*a-3/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'old version installed, but plugin updated'
+
+ Gem::Uninstaller.new('a', :version => '1', :executables => true).uninstall
+
+ assert File.exist?(plugin_path), 'plugin removed when old version uninstalled'
+ assert_match %r{\Arequire.*a-3/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'old version uninstalled, but plugin updated'
+
+ Gem::Uninstaller.new('a', version: '3', :executables => true).uninstall
+
+ assert File.exist?(plugin_path), 'plugin removed when old version uninstalled and another version with plugin still present'
+ assert_match %r{\Arequire.*a-2/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'latest version uninstalled, but plugin not updated to previous version'
+
+ Gem::Uninstaller.new('a', version: '2', :executables => true).uninstall
+
+ refute File.exist?(plugin_path), 'last version uninstalled, but plugin still present'
+ end
+
end
diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb
index 1deecc0eed..30b9376e30 100644
--- a/test/rubygems/test_gem_version.rb
+++ b/test/rubygems/test_gem_version.rb
@@ -236,7 +236,7 @@ class TestGemVersion < Gem::TestCase
assert_equal expected, v(version).approximate_recommendation
end
- # Assert that the "approximate" recommendation for +version+ satifies +version+.
+ # Assert that the "approximate" recommendation for +version+ satisfies +version+.
def assert_approximate_satisfies_itself(version)
gem_version = v(version)