summaryrefslogtreecommitdiff
path: root/test/rubygems
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-12-08 16:33:39 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-12-08 17:30:02 +0900
commit4aca77edde91f826aa243e268bf1ef5214530583 (patch)
treeef0cf1a95fcced00ca5fa40f3412c567bf95d705 /test/rubygems
parent6a6a24df9b72750d12f9b15192bdb7517e668efb (diff)
Merge prepare version of RubyGems 3.2.0
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3864
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/test_bundled_ca.rb14
-rw-r--r--test/rubygems/test_gem.rb6
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb202
-rw-r--r--test/rubygems/test_gem_commands_cert_command.rb4
-rw-r--r--test/rubygems/test_gem_commands_cleanup_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_contents_command.rb4
-rw-r--r--test/rubygems/test_gem_commands_help_command.rb17
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_owner_command.rb50
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb4
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb36
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb6
-rw-r--r--test/rubygems/test_gem_commands_setup_command.rb31
-rw-r--r--test/rubygems/test_gem_commands_signin_command.rb30
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb60
-rw-r--r--test/rubygems/test_gem_commands_specification_command.rb28
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb4
-rw-r--r--test/rubygems/test_gem_commands_yank_command.rb32
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb38
-rw-r--r--test/rubygems/test_gem_dependency_list.rb4
-rw-r--r--test/rubygems/test_gem_ext_builder.rb24
-rw-r--r--test/rubygems/test_gem_ext_cmake_builder.rb12
-rw-r--r--test/rubygems/test_gem_ext_configure_builder.rb12
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb35
-rw-r--r--test/rubygems/test_gem_ext_rake_builder.rb18
-rw-r--r--test/rubygems/test_gem_gem_runner.rb9
-rw-r--r--test/rubygems/test_gem_gemcutter_utilities.rb6
-rw-r--r--test/rubygems/test_gem_install_update_options.rb18
-rw-r--r--test/rubygems/test_gem_installer.rb85
-rw-r--r--test/rubygems/test_gem_package.rb16
-rw-r--r--test/rubygems/test_gem_package_old.rb8
-rw-r--r--test/rubygems/test_gem_package_tar_writer.rb2
-rw-r--r--test/rubygems/test_gem_platform.rb67
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb32
-rw-r--r--test/rubygems/test_gem_request.rb4
-rw-r--r--test/rubygems/test_gem_request_set_lockfile.rb8
-rw-r--r--test/rubygems/test_gem_resolver_api_set.rb16
-rw-r--r--test/rubygems/test_gem_resolver_conflict.rb2
-rw-r--r--test/rubygems/test_gem_resolver_vendor_set.rb2
-rw-r--r--test/rubygems/test_gem_security.rb4
-rw-r--r--test/rubygems/test_gem_security_policy.rb4
-rw-r--r--test/rubygems/test_gem_security_signer.rb4
-rw-r--r--test/rubygems/test_gem_security_trust_dir.rb4
-rw-r--r--test/rubygems/test_gem_source.rb5
-rw-r--r--test/rubygems/test_gem_source_subpath_problem.rb49
-rw-r--r--test/rubygems/test_gem_specification.rb9
-rw-r--r--test/rubygems/test_gem_uninstaller.rb14
-rw-r--r--test/rubygems/test_gem_validator.rb2
-rw-r--r--test/rubygems/test_gem_version_option.rb2
-rw-r--r--test/rubygems/test_require.rb59
50 files changed, 873 insertions, 233 deletions
diff --git a/test/rubygems/test_bundled_ca.rb b/test/rubygems/test_bundled_ca.rb
index 557298d8d5..6973758c4c 100644
--- a/test/rubygems/test_bundled_ca.rb
+++ b/test/rubygems/test_bundled_ca.rb
@@ -3,7 +3,7 @@ require 'rubygems/test_case'
require 'net/http'
require 'rubygems/openssl'
-unless defined?(OpenSSL::SSL)
+unless Gem::HAVE_OPENSSL
warn 'Skipping bundled certificates tests. openssl not found.'
end
@@ -46,11 +46,15 @@ class TestBundledCA < Gem::TestCase
assert_https('rubygems.org')
end
- def test_accessing_fastly
- assert_https('rubygems.global.ssl.fastly.net')
+ def test_accessing_www_rubygems
+ assert_https('www.rubygems.org')
+ end
+
+ def test_accessing_staging
+ assert_https('staging.rubygems.org')
end
def test_accessing_new_index
- assert_https('fastly.rubygems.org')
+ assert_https('index.rubygems.org')
end
-end if defined?(OpenSSL::SSL)
+end if Gem::HAVE_OPENSSL
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index cf5c9720b4..344b03be9b 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -164,7 +164,7 @@ class TestGem < Gem::TestCase
:prog_mode => win_platform? ? 0410 : 0510,
:data_mode => 0640,
:wrappers => true,
- :format_executable => format_executable
+ :format_executable => format_executable,
}
Dir.chdir @tempdir do
Dir.mkdir 'bin'
@@ -765,7 +765,7 @@ class TestGem < Gem::TestCase
expected = [
File.expand_path('test/rubygems/sff/discover.rb', PROJECT_DIR),
- File.join(foo1.full_gem_path, discover_path)
+ File.join(foo1.full_gem_path, discover_path),
].sort
assert_equal expected, Gem.find_files('sff/discover').sort
@@ -1532,7 +1532,7 @@ class TestGem < Gem::TestCase
tests = [
[:dir0, [ Gem.dir, Gem.user_dir], m0],
- [:dir1, [ Gem.user_dir, Gem.dir], m1]
+ [:dir1, [ Gem.user_dir, Gem.dir], m1],
]
tests.each do |_name, _paths, expected|
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 24c60473f2..fe537780be 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -231,7 +231,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
assert_equal '', @ui.output
- assert_equal "ERROR: Gemspec file not found: some_gem.gemspec\n", @ui.error
+ assert_equal "ERROR: Couldn't find a gemspec file matching 'some_gem' in #{@tempdir}\n", @ui.error
end
def test_execute_outside_dir
@@ -272,8 +272,200 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert_equal "this is a summary", spec.summary
end
+ def test_execute_outside_dir_with_glob_argument
+ gemspec_dir = File.join @tempdir, 'build_command_gem'
+ gemspec_file = File.join gemspec_dir, @gem.spec_name
+ readme_file = File.join gemspec_dir, 'README.md'
+
+ FileUtils.mkdir_p gemspec_dir
+
+ File.open readme_file, 'w' do |f|
+ f.write "My awesome gem"
+ end
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write @gem.to_ruby
+ end
+
+ @cmd.options[:build_path] = gemspec_dir
+ @cmd.options[:args] = ["*.gemspec"]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ output = @ui.output.split "\n"
+ assert_equal " Successfully built RubyGem", output.shift
+ assert_equal " Name: some_gem", output.shift
+ assert_equal " Version: 2", output.shift
+ assert_equal " File: some_gem-2.gem", output.shift
+ assert_equal [], output
+
+ gem_file = File.join gemspec_dir, File.basename(@gem.cache_file)
+ assert File.exist?(gem_file)
+
+ spec = Gem::Package.new(gem_file).spec
+
+ assert_equal "some_gem", spec.name
+ assert_equal "this is a summary", spec.summary
+ end
+
+ def test_execute_outside_dir_no_gemspec_present
+ gemspec_dir = File.join @tempdir, 'build_command_gem'
+ gemspec_file = File.join @tempdir, @gem.spec_name
+ readme_file = File.join gemspec_dir, 'README.md'
+
+ FileUtils.mkdir_p gemspec_dir
+
+ File.open readme_file, 'w' do |f|
+ f.write "My awesome gem"
+ end
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write @gem.to_ruby
+ end
+
+ @cmd.options[:build_path] = gemspec_dir
+ @cmd.options[:args] = ["*.gemspec"]
+
+ use_ui @ui do
+ assert_raises Gem::MockGemUi::TermError do
+ @cmd.execute
+ end
+ end
+
+ assert_equal "", @ui.output
+ assert_equal "ERROR: Couldn't find a gemspec file matching '*.gemspec' in #{gemspec_dir}\n", @ui.error
+
+ gem_file = File.join gemspec_dir, File.basename(@gem.cache_file)
+ refute File.exist?(gem_file)
+ end
+
+ def test_execute_outside_dir_without_gem_name
+ gemspec_dir = File.join(@tempdir, 'build_command_gem')
+ gemspec_file = File.join(gemspec_dir, @gem.spec_name)
+
+ readme_file = File.join gemspec_dir, 'README.md'
+
+ FileUtils.mkdir_p(gemspec_dir)
+
+ File.open readme_file, 'w' do |f|
+ f.write "My awesome gem"
+ end
+
+ File.open(gemspec_file, "w") do |gs|
+ gs.write(@gem.to_ruby)
+ end
+
+ @cmd.options[:build_path] = gemspec_dir
+ @cmd.options[:args] = []
+
+ use_ui @ui do
+ Dir.chdir(gemspec_dir) do
+ @cmd.execute
+ end
+ end
+
+ output = @ui.output.split("\n")
+ assert_equal " Successfully built RubyGem", output.shift
+ assert_equal " Name: some_gem", output.shift
+ assert_equal " Version: 2", output.shift
+ assert_equal " File: some_gem-2.gem", output.shift
+ assert_equal [], output
+
+ gem_file = File.join gemspec_dir, File.basename(@gem.cache_file)
+ assert File.exist?(gem_file)
+
+ spec = Gem::Package.new(gem_file).spec
+
+ assert_equal "some_gem", spec.name
+ assert_equal "this is a summary", spec.summary
+ end
+
+ def test_execute_outside_dir_with_external_gemspec
+ gemspec_dir = File.join @tempdir, 'gemspec_dir'
+ gemspec_file = File.join gemspec_dir, @gem.spec_name
+
+ gemcode_dir = File.join @tempdir, 'build_command_gem'
+ readme_file = File.join gemcode_dir, 'README.md'
+
+ FileUtils.mkdir_p gemspec_dir
+ FileUtils.mkdir_p gemcode_dir
+
+ File.open readme_file, 'w' do |f|
+ f.write "My awesome gem in nested directory"
+ end
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write @gem.to_ruby
+ end
+
+ @cmd.options[:build_path] = gemcode_dir
+ @cmd.options[:args] = [gemspec_file]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ output = @ui.output.split "\n"
+ assert_equal " Successfully built RubyGem", output.shift
+ assert_equal " Name: some_gem", output.shift
+ assert_equal " Version: 2", output.shift
+ assert_equal " File: some_gem-2.gem", output.shift
+ assert_equal [], output
+
+ gem_file = File.join gemcode_dir, File.basename(@gem.cache_file)
+ assert File.exist?(gem_file)
+
+ spec = Gem::Package.new(gem_file).spec
+
+ assert_equal "some_gem", spec.name
+ assert_equal "this is a summary", spec.summary
+ end
+
+ def test_execute_outside_dir_with_external_relative_gemspec
+ gemspec_dir = File.join @tempdir, 'gemspec_dir'
+ gemspec_file = File.join gemspec_dir, @gem.spec_name
+
+ gemcode_dir = File.join @tempdir, 'build_command_gem'
+ readme_file = File.join gemcode_dir, 'README.md'
+
+ FileUtils.mkdir_p gemspec_dir
+ FileUtils.mkdir_p gemcode_dir
+
+ File.open readme_file, 'w' do |f|
+ f.write "My awesome gem in nested directory"
+ end
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write @gem.to_ruby
+ end
+
+ @cmd.options[:build_path] = gemcode_dir
+ @cmd.options[:args] = [File.join("..", "gemspec_dir", @gem.spec_name)]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ output = @ui.output.split "\n"
+ assert_equal " Successfully built RubyGem", output.shift
+ assert_equal " Name: some_gem", output.shift
+ assert_equal " Version: 2", output.shift
+ assert_equal " File: some_gem-2.gem", output.shift
+ assert_equal [], output
+
+ gem_file = File.join gemcode_dir, File.basename(@gem.cache_file)
+ assert File.exist?(gem_file)
+
+ spec = Gem::Package.new(gem_file).spec
+
+ assert_equal "some_gem", spec.name
+ assert_equal "this is a summary", spec.summary
+ end
+
def test_can_find_gemspecs_without_dot_gemspec
- gemspec_file = File.join(@tempdir, @gem.spec_name)
+ gemspec_file = File.join(@tempdir, @gem.name)
File.open gemspec_file + ".gemspec", 'w' do |gs|
gs.write @gem.to_ruby
@@ -390,7 +582,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_build_signed_gem
- skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform?
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL && !java_platform?
trust_dir = Gem::Security.trust_dir
@@ -417,7 +609,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_build_signed_gem_with_cert_expiration_length_days
- skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform?
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL && !java_platform?
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
@@ -461,7 +653,7 @@ class TestGemCommandsBuildCommand < Gem::TestCase
end
def test_build_auto_resign_cert
- skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform?
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL && !java_platform?
gem_path = File.join Gem.user_home, ".gem"
Dir.mkdir gem_path
diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb
index c4693b07cf..19867bf37a 100644
--- a/test/rubygems/test_gem_commands_cert_command.rb
+++ b/test/rubygems/test_gem_commands_cert_command.rb
@@ -2,7 +2,7 @@
require 'rubygems/test_case'
require 'rubygems/commands/cert_command'
-unless defined?(OpenSSL::SSL)
+unless Gem::HAVE_OPENSSL
warn 'Skipping `gem cert` tests. openssl not found.'
end
@@ -805,4 +805,4 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
assert_equal "invalid argument: --sign #{nonexistent}: does not exist",
e.message
end
-end if defined?(OpenSSL::SSL) && !Gem.java_platform?
+end if Gem::HAVE_OPENSSL && !Gem.java_platform?
diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb
index 81f9a24db5..d937a5e549 100644
--- a/test/rubygems/test_gem_commands_cleanup_command.rb
+++ b/test/rubygems/test_gem_commands_cleanup_command.rb
@@ -221,7 +221,7 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
@b_2 = util_spec 'b', 3
install_gem @b_1
- install_default_specs @b_default
+ install_default_gems @b_default
install_gem @b_2
@cmd.options[:args] = []
diff --git a/test/rubygems/test_gem_commands_contents_command.rb b/test/rubygems/test_gem_commands_contents_command.rb
index 07b0e0f340..7c89c67dd4 100644
--- a/test/rubygems/test_gem_commands_contents_command.rb
+++ b/test/rubygems/test_gem_commands_contents_command.rb
@@ -227,7 +227,7 @@ lib/foo.rb
nil, "default/gem.rb")
default_gem_spec.executables = ["default_command"]
default_gem_spec.files += ["default_gem.so"]
- install_default_specs(default_gem_spec)
+ install_default_gems(default_gem_spec)
@cmd.options[:args] = %w[default]
@@ -238,7 +238,7 @@ lib/foo.rb
expected = [
[RbConfig::CONFIG['bindir'], 'default_command'],
[RbConfig::CONFIG['rubylibdir'], 'default/gem.rb'],
- [RbConfig::CONFIG['archdir'], 'default_gem.so']
+ [RbConfig::CONFIG['archdir'], 'default_gem.so'],
].sort.map{|a|File.join a }.join "\n"
assert_equal expected, @ui.output.chomp
diff --git a/test/rubygems/test_gem_commands_help_command.rb b/test/rubygems/test_gem_commands_help_command.rb
index 26e22d79be..8d20563a60 100644
--- a/test/rubygems/test_gem_commands_help_command.rb
+++ b/test/rubygems/test_gem_commands_help_command.rb
@@ -40,10 +40,12 @@ class TestGemCommandsHelpCommand < Gem::TestCase
util_gem 'commands' do |out, err|
mgr.command_names.each do |cmd|
- assert_match(/\s+#{cmd}\s+\S+/, out)
+ unless mgr[cmd].deprecated?
+ assert_match(/\s+#{cmd}\s+\S+/, out)
+ end
end
- if defined?(OpenSSL::SSL)
+ if Gem::HAVE_OPENSSL
assert_empty err
refute_match 'No command found for ', out
@@ -51,6 +53,17 @@ class TestGemCommandsHelpCommand < Gem::TestCase
end
end
+ def test_gem_help_commands_omits_deprecated_commands
+ mgr = Gem::CommandManager.new
+
+ util_gem 'commands' do |out, err|
+ deprecated_commands = mgr.command_names.select {|cmd| mgr[cmd].deprecated? }
+ deprecated_commands.each do |cmd|
+ refute_match(/\A\s+#{cmd}\s+\S+\z/, out)
+ end
+ end
+ end
+
def test_gem_no_args_shows_help
util_gem do |out, err|
assert_match(/Usage:/, out)
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index ccaa4ec2dc..08530bfeca 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -410,7 +410,7 @@ ERROR: Possible alternatives: non_existent_with_hint
expected = [
"ERROR: Could not find a valid gem 'non-existent_with-hint' (>= 0) in any repository",
- "ERROR: Possible alternatives: nonexistent-with_hint"
+ "ERROR: Possible alternatives: nonexistent-with_hint",
]
output = @ui.error.split "\n"
diff --git a/test/rubygems/test_gem_commands_owner_command.rb b/test/rubygems/test_gem_commands_owner_command.rb
index 1602ae6839..4280fedff3 100644
--- a/test/rubygems/test_gem_commands_owner_command.rb
+++ b/test/rubygems/test_gem_commands_owner_command.rb
@@ -247,7 +247,7 @@ EOF
@stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
[response_fail, 401, 'Unauthorized'],
- [response_success, 200, 'OK']
+ [response_success, 200, 'OK'],
]
@otp_ui = Gem::MockGemUi.new "111111\n"
@@ -275,4 +275,52 @@ EOF
assert_match 'Code: ', @otp_ui.output
assert_equal '111111', @stub_fetcher.last_request['OTP']
end
+
+ def test_remove_owners_unathorized_api_key
+ response_forbidden = "The API key doesn't have access"
+ response_success = "Owner removed successfully."
+
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
+ [response_forbidden, 403, 'Forbidden'],
+ [response_success, 200, "OK"],
+ ]
+ @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = ["", 200, "OK"]
+ @cmd.instance_variable_set :@scope, :remove_owner
+
+ @stub_ui = Gem::MockGemUi.new "some@mail.com\npass\n"
+ use_ui @stub_ui do
+ @cmd.remove_owners("freewill", ["some@example"])
+ end
+
+ access_notice = "The existing key doesn't have access of remove_owner on RubyGems.org. Please sign in to update access."
+ assert_match access_notice, @stub_ui.output
+ assert_match "Email:", @stub_ui.output
+ assert_match "Password:", @stub_ui.output
+ assert_match "Added remove_owner scope to the existing API key", @stub_ui.output
+ assert_match response_success, @stub_ui.output
+ end
+
+ def test_add_owners_unathorized_api_key
+ response_forbidden = "The API key doesn't have access"
+ response_success = "Owner added successfully."
+
+ @stub_fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [
+ [response_forbidden, 403, 'Forbidden'],
+ [response_success, 200, "OK"],
+ ]
+ @stub_fetcher.data["#{Gem.host}/api/v1/api_key"] = ["", 200, "OK"]
+ @cmd.instance_variable_set :@scope, :add_owner
+
+ @stub_ui = Gem::MockGemUi.new "some@mail.com\npass\n"
+ use_ui @stub_ui do
+ @cmd.add_owners("freewill", ["some@example"])
+ end
+
+ access_notice = "The existing key doesn't have access of add_owner on RubyGems.org. Please sign in to update access."
+ assert_match access_notice, @stub_ui.output
+ assert_match "Email:", @stub_ui.output
+ assert_match "Password:", @stub_ui.output
+ assert_match "Added add_owner scope to the existing API key", @stub_ui.output
+ assert_match response_success, @stub_ui.output
+ end
end
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index 75243e5fa2..59f34af249 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -568,7 +568,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_equal([
"Restoring gems to pristine condition...",
"Cached gem for a-2 not found, attempting to fetch...",
- "Skipped a-2, it was not found from cache and remote sources"
+ "Skipped a-2, it was not found from cache and remote sources",
], @ui.output.split("\n"))
assert_empty @ui.error
@@ -577,7 +577,7 @@ class TestGemCommandsPristineCommand < Gem::TestCase
def test_execute_default_gem
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
- install_default_specs(default_gem_spec)
+ install_default_gems(default_gem_spec)
@cmd.options[:args] = %w[default]
diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb
index c23760a8ca..68681af22f 100644
--- a/test/rubygems/test_gem_commands_push_command.rb
+++ b/test/rubygems/test_gem_commands_push_command.rb
@@ -152,7 +152,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
keys = {
:rubygems_api_key => 'KEY',
- @host => @api_key
+ @host => @api_key,
}
FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
@@ -187,7 +187,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
keys = {
:rubygems_api_key => 'KEY',
- @host => @api_key
+ @host => @api_key,
}
FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
@@ -271,7 +271,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
keys = {
:rubygems_api_key => 'KEY',
- @host => @api_key
+ @host => @api_key,
}
FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
@@ -302,7 +302,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
api_key = "PRIVKEY"
keys = {
- host => api_key
+ host => api_key,
}
FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
@@ -373,7 +373,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
@fetcher.data["#{Gem.host}/api/v1/gems"] = [
[response_fail, 401, 'Unauthorized'],
- [response_success, 200, 'OK']
+ [response_success, 200, 'OK'],
]
@otp_ui = Gem::MockGemUi.new "111111\n"
@@ -404,6 +404,32 @@ class TestGemCommandsPushCommand < Gem::TestCase
assert_equal '111111', @fetcher.last_request['OTP']
end
+ def test_sending_gem_unathorized_api_key
+ response_forbidden = "The API key doesn't have access"
+ response_success = 'Successfully registered gem: freewill (1.0.0)'
+
+ @fetcher.data["#{@host}/api/v1/gems"] = [
+ [response_forbidden, 403, 'Forbidden'],
+ [response_success, 200, "OK"],
+ ]
+
+ @fetcher.data["#{@host}/api/v1/api_key"] = ["", 200, "OK"]
+ @cmd.instance_variable_set :@host, @host
+ @cmd.instance_variable_set :@scope, :push_rubygem
+
+ @ui = Gem::MockGemUi.new "some@mail.com\npass\n"
+ use_ui @ui do
+ @cmd.send_gem(@path)
+ end
+
+ access_notice = "The existing key doesn't have access of push_rubygem on https://rubygems.example. Please sign in to update access."
+ assert_match access_notice, @ui.output
+ assert_match "Email:", @ui.output
+ assert_match "Password:", @ui.output
+ assert_match "Added push_rubygem scope to the existing API key", @ui.output
+ assert_match response_success, @ui.output
+ end
+
private
def singleton_gem_class
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index f2f70a10ff..a21bc690fb 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -644,7 +644,7 @@ a (2 universal-darwin, 1 ruby x86-linux)
spec_fetcher {|fetcher| fetcher.spec 'a', 2 }
a1 = new_default_spec 'a', 1
- install_default_specs a1
+ install_default_gems a1
use_ui @stub_ui do
@cmd.execute
@@ -663,7 +663,7 @@ EOF
def test_execute_show_default_gems_with_platform
a1 = new_default_spec 'a', 1
a1.platform = 'java'
- install_default_specs a1
+ install_default_gems a1
use_ui @stub_ui do
@cmd.execute
@@ -685,7 +685,7 @@ EOF
end
a1 = new_default_spec 'a', 1
- install_default_specs a1
+ install_default_gems a1
@cmd.handle_options %w[-l -d]
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index 9b6aa87861..afdc5d0979 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -26,12 +26,12 @@ class TestGemCommandsSetupCommand < Gem::TestCase
bundler/exe/bundle
bundler/lib/bundler.rb
bundler/lib/bundler/b.rb
+ bundler/lib/bundler/man/bundle-b.1.ronn
+ bundler/lib/bundler/man/gemfile.5.ronn
bundler/lib/bundler/templates/.circleci/config.yml
bundler/lib/bundler/templates/.travis.yml
bundler/man/bundle-b.1
- bundler/man/bundle-b.1.ronn
bundler/man/gemfile.5
- bundler/man/gemfile.5.ronn
]
create_dummy_files(filelist)
@@ -155,23 +155,18 @@ class TestGemCommandsSetupCommand < Gem::TestCase
assert_match %r{\A#!\s*#{bin_env}#{ruby_exec}}, File.read(gem_bin_path)
end
- def test_pem_files_in
- assert_equal %w[rubygems/ssl_certs/rubygems.org/foo.pem],
- @cmd.pem_files_in('lib').sort
- end
-
- def test_rb_files_in
- assert_equal %w[rubygems.rb rubygems/test_case.rb],
- @cmd.rb_files_in('lib').sort
+ def test_files_in
+ assert_equal %w[rubygems.rb rubygems/ssl_certs/rubygems.org/foo.pem rubygems/test_case.rb],
+ @cmd.files_in('lib').sort
end
def test_bundler_man1_files_in
- assert_equal %w[bundle-b.1 bundle-b.1.ronn],
+ assert_equal %w[bundle-b.1],
@cmd.bundler_man1_files_in('bundler/man').sort
end
def test_bundler_man5_files_in
- assert_equal %w[gemfile.5 gemfile.5.ronn],
+ assert_equal %w[gemfile.5],
@cmd.bundler_man5_files_in('bundler/man').sort
end
@@ -187,7 +182,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
assert_path_exists File.join(dir, 'bundler.rb')
assert_path_exists File.join(dir, 'bundler/b.rb')
- assert_path_exists File.join(dir, 'bundler/templates/.circleci/config.yml')
+ assert_path_exists File.join(dir, 'bundler/templates/.circleci/config.yml') unless RUBY_ENGINE == "truffleruby" # https://github.com/oracle/truffleruby/issues/2116
assert_path_exists File.join(dir, 'bundler/templates/.travis.yml')
end
end
@@ -199,9 +194,9 @@ class TestGemCommandsSetupCommand < Gem::TestCase
@cmd.install_man dir
assert_path_exists File.join("#{dir}/man1", 'bundle-b.1')
- assert_path_exists File.join("#{dir}/man1", 'bundle-b.1.ronn')
+ refute_path_exists File.join("#{dir}/man1", 'bundle-b.1.ronn')
assert_path_exists File.join("#{dir}/man5", 'gemfile.5')
- assert_path_exists File.join("#{dir}/man5", 'gemfile.5.ronn')
+ refute_path_exists File.join("#{dir}/man5", 'gemfile.5.ronn')
end
end
@@ -297,7 +292,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
@cmd.remove_old_lib_files lib
- files_that_go.each {|file| refute_path_exists file }
+ files_that_go.each {|file| refute_path_exists(file) unless file == old_bundler_ci && RUBY_ENGINE == "truffleruby" } # https://github.com/oracle/truffleruby/issues/2116
files_that_stay.each {|file| assert_path_exists file }
end
@@ -313,8 +308,8 @@ class TestGemCommandsSetupCommand < Gem::TestCase
gemfile_5_ronn = File.join man, 'man5', 'gemfile.5.ronn'
gemfile_5_txt = File.join man, 'man5', 'gemfile.5.txt'
- files_that_go = [bundle_b_1_txt, gemfile_5_txt]
- files_that_stay = [ruby_1, bundle_b_1, bundle_b_1_ronn, gemfile_5, gemfile_5_ronn]
+ files_that_go = [bundle_b_1_txt, bundle_b_1_ronn, gemfile_5_txt, gemfile_5_ronn]
+ files_that_stay = [ruby_1, bundle_b_1, gemfile_5]
create_dummy_files(files_that_go + files_that_stay)
diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb
index 21d19fffc9..f8262466b1 100644
--- a/test/rubygems/test_gem_commands_signin_command.rb
+++ b/test/rubygems/test_gem_commands_signin_command.rb
@@ -73,14 +73,38 @@ class TestGemCommandsSigninCommand < Gem::TestCase
assert_equal api_key, credentials[:rubygems_api_key]
end
+ def test_excute_with_key_name_and_scope
+ email = 'you@example.com'
+ password = 'secret'
+ api_key = '1234'
+ fetcher = Gem::RemoteFetcher.fetcher
+
+ key_name_ui = Gem::MockGemUi.new "#{email}\n#{password}\ntest-key\n\ny\n\n\n\n\n\n"
+ util_capture(key_name_ui, nil, api_key, fetcher) { @cmd.execute }
+
+ user = ENV["USER"] || ENV["USERNAME"]
+
+ assert_match "API Key name [#{Socket.gethostname}-#{user}", key_name_ui.output
+ assert_match "index_rubygems [y/N]", key_name_ui.output
+ assert_match "push_rubygem [y/N]", key_name_ui.output
+ assert_match "yank_rubygem [y/N]", key_name_ui.output
+ assert_match "add_owner [y/N]", key_name_ui.output
+ assert_match "remove_owner [y/N]", key_name_ui.output
+ assert_match "access_webhooks [y/N]", key_name_ui.output
+ assert_match "show_dashboard [y/N]", key_name_ui.output
+ assert_equal "name=test-key&push_rubygem=true", fetcher.last_request.body
+
+ credentials = YAML.load_file Gem.configuration.credentials_path
+ assert_equal api_key, credentials[:rubygems_api_key]
+ end
+
# Utility method to capture IO/UI within the block passed
- def util_capture(ui_stub = nil, host = nil, api_key = nil)
+ def util_capture(ui_stub = nil, host = nil, api_key = nil, fetcher = Gem::FakeFetcher.new)
api_key ||= 'a5fdbb6ba150cbb83aad2bb2fede64cf040453903'
response = [api_key, 200, 'OK']
email = 'you@example.com'
password = 'secret'
- fetcher = Gem::FakeFetcher.new
# Set the expected response for the Web-API supplied
ENV['RUBYGEMS_HOST'] = host || Gem::DEFAULT_HOST
@@ -88,7 +112,7 @@ class TestGemCommandsSigninCommand < Gem::TestCase
fetcher.data[data_key] = response
Gem::RemoteFetcher.fetcher = fetcher
- sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n")
+ sign_in_ui = ui_stub || Gem::MockGemUi.new("#{email}\n#{password}\n\n\n\n\n\n\n\n\n")
use_ui sign_in_ui do
yield
diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb
index ff00b9aa23..59acfb1ed6 100644
--- a/test/rubygems/test_gem_commands_sources_command.rb
+++ b/test/rubygems/test_gem_commands_sources_command.rb
@@ -107,6 +107,36 @@ class TestGemCommandsSourcesCommand < Gem::TestCase
assert_empty ui.error
end
+ def test_execute_add_allow_typo_squatting_source_forced
+ rubygems_org = "https://rubyems.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["#{rubygems_org}/specs.#{@marshal_version}.gz"] = specs_dump_gz.string
+ @cmd.handle_options %W[--force --add #{rubygems_org}]
+
+ @cmd.execute
+
+ expected = "https://rubyems.org added to sources\n"
+ assert_equal expected, ui.output
+
+ source = Gem::Source.new(rubygems_org)
+ assert Gem.sources.include?(source)
+
+ assert_empty ui.error
+ end
+
def test_execute_add_deny_typo_squatting_source
rubygems_org = "https://rubyems.org"
@@ -283,6 +313,36 @@ source http://gems.example.com/ already present in the cache
assert_empty @ui.error
end
+ def test_execute_add_http_rubygems_org_forced
+ rubygems_org = "http://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["#{rubygems_org}/specs.#{@marshal_version}.gz"] = specs_dump_gz.string
+ @cmd.handle_options %W[--force --add #{rubygems_org}]
+
+ @cmd.execute
+
+ expected = "http://rubygems.org added to sources\n"
+ assert_equal expected, ui.output
+
+ source = Gem::Source.new(rubygems_org)
+ assert Gem.sources.include?(source)
+
+ assert_empty ui.error
+ end
+
def test_execute_add_https_rubygems_org
https_rubygems_org = 'https://rubygems.org/'
diff --git a/test/rubygems/test_gem_commands_specification_command.rb b/test/rubygems/test_gem_commands_specification_command.rb
index e055246cdc..732278eb6f 100644
--- a/test/rubygems/test_gem_commands_specification_command.rb
+++ b/test/rubygems/test_gem_commands_specification_command.rb
@@ -186,6 +186,34 @@ class TestGemCommandsSpecificationCommand < Gem::TestCase
assert_equal Gem::Version.new("1"), spec.version
end
+ def test_execute_remote_with_version_and_platform
+ original_platforms = Gem.platforms.dup
+
+ spec_fetcher do |fetcher|
+ fetcher.spec 'foo', "1"
+ fetcher.spec 'foo', "1" do |s|
+ s.platform = 'x86_64-linux'
+ end
+ end
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:version] = "1"
+ @cmd.options[:domain] = :remote
+ @cmd.options[:added_platform] = true
+ Gem.platforms = [Gem::Platform::RUBY, Gem::Platform.new("x86_64-linux")]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ spec = Gem::Specification.from_yaml @ui.output
+
+ assert_equal Gem::Version.new("1"), spec.version
+ assert_equal Gem::Platform.new("x86_64-linux"), spec.platform
+ ensure
+ Gem.platforms = original_platforms
+ end
+
def test_execute_remote_without_prerelease
spec_fetcher do |fetcher|
fetcher.spec 'foo', '2.0.0'
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index cacde06fd5..749e9bee20 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -198,13 +198,13 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
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|
+ fetcher.download 'rubygems-update', "3.2.a" do |s|
s.files = %w[setup.rb]
end
end
@cmd.options[:args] = []
- @cmd.options[:system] = "3.2"
+ @cmd.options[:system] = "3.2.a"
FileUtils.mkdir_p Gem.plugindir
plugin_file = File.join(Gem.plugindir, 'a_plugin.rb')
diff --git a/test/rubygems/test_gem_commands_yank_command.rb b/test/rubygems/test_gem_commands_yank_command.rb
index 8e453dfabf..3046655aa8 100644
--- a/test/rubygems/test_gem_commands_yank_command.rb
+++ b/test/rubygems/test_gem_commands_yank_command.rb
@@ -70,7 +70,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
yank_uri = 'http://example/api/v1/gems/yank'
@fetcher.data[yank_uri] = [
[response_fail, 401, 'Unauthorized'],
- ['Successfully yanked', 200, 'OK']
+ ['Successfully yanked', 200, 'OK'],
]
@cmd.options[:args] = %w[a]
@@ -147,4 +147,34 @@ class TestGemCommandsYankCommand < Gem::TestCase
assert_equal 'key', @fetcher.last_request['Authorization']
assert_equal [yank_uri], @fetcher.paths
end
+
+ def test_yank_gem_unathorized_api_key
+ response_forbidden = "The API key doesn't have access"
+ response_success = 'Successfully yanked'
+ host = 'http://example'
+
+ @fetcher.data["#{host}/api/v1/gems/yank"] = [
+ [response_forbidden, 403, 'Forbidden'],
+ [response_success, 200, "OK"],
+ ]
+
+ @fetcher.data["#{host}/api/v1/api_key"] = ["", 200, "OK"]
+ @cmd.options[:args] = %w[a]
+ @cmd.options[:added_platform] = true
+ @cmd.options[:version] = req('= 1.0')
+ @cmd.instance_variable_set :@host, host
+ @cmd.instance_variable_set :@scope, :yank_rubygem
+
+ @ui = Gem::MockGemUi.new "some@mail.com\npass\n"
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ access_notice = "The existing key doesn't have access of yank_rubygem on http://example. Please sign in to update access."
+ assert_match access_notice, @ui.output
+ assert_match "Email:", @ui.output
+ assert_match "Password:", @ui.output
+ assert_match "Added yank_rubygem scope to the existing API key", @ui.output
+ assert_match response_success, @ui.output
+ end
end
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index 803b95e88c..fe8a74c750 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -528,6 +528,40 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[a-1 e-1], inst.installed_gems.map {|s| s.full_name }
end
+ def test_install_no_minimal_deps
+ util_setup_gems
+
+ _, e1_gem = util_gem 'e', '1' do |s|
+ s.add_dependency 'b'
+ end
+
+ _, b2_gem = util_gem 'b', '2' do |s|
+ s.add_dependency 'a'
+ end
+
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ FileUtils.mv b2_gem, @tempdir
+ FileUtils.mv e1_gem, @tempdir
+
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :ignore_dependencies => true
+ inst.install 'b', req('= 1')
+ end
+
+ assert_equal %w[b-1], inst.installed_gems.map {|s| s.full_name },
+ 'sanity check'
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :minimal_deps => false
+ inst.install 'e'
+ end
+
+ assert_equal %w[a-1 b-2 e-1], inst.installed_gems.map {|s| s.full_name }
+ end
+
def test_install_no_document
util_setup_gems
@@ -749,7 +783,7 @@ class TestGemDependencyInstaller < Gem::TestCase
inst = nil
Dir.chdir @tempdir do
- inst = Gem::DependencyInstaller.new
+ inst = Gem::DependencyInstaller.new :force => true
inst.install 'a'
end
@@ -842,7 +876,7 @@ class TestGemDependencyInstaller < Gem::TestCase
require 'rubygems/openssl'
- if defined? OpenSSL
+ if Gem::HAVE_OPENSSL
def test_install_security_policy
util_setup_gems
diff --git a/test/rubygems/test_gem_dependency_list.rb b/test/rubygems/test_gem_dependency_list.rb
index d8ef3d4f0e..097e680596 100644
--- a/test/rubygems/test_gem_dependency_list.rb
+++ b/test/rubygems/test_gem_dependency_list.rb
@@ -139,8 +139,8 @@ class TestGemDependencyList < Gem::TestCase
exp = {
"b" => [
- Gem::Dependency.new("a", ">= 1")
- ]
+ Gem::Dependency.new("a", ">= 1"),
+ ],
}
assert_equal exp, @deplist.why_not_ok?
diff --git a/test/rubygems/test_gem_ext_builder.rb b/test/rubygems/test_gem_ext_builder.rb
index abd33d237a..6e6bf89f9c 100644
--- a/test/rubygems/test_gem_ext_builder.rb
+++ b/test/rubygems/test_gem_ext_builder.rb
@@ -30,9 +30,8 @@ class TestGemExtBuilder < Gem::TestCase
ENV['DESTDIR'] = 'destination'
results = []
- Dir.chdir @ext do
- File.open 'Makefile', 'w' do |io|
- io.puts <<-MAKEFILE
+ File.open File.join(@ext, 'Makefile'), 'w' do |io|
+ io.puts <<-MAKEFILE
all:
\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
@@ -41,12 +40,11 @@ clean:
install:
\t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}"
- MAKEFILE
- end
-
- Gem::Ext::Builder.make @dest_path, results
+ MAKEFILE
end
+ Gem::Ext::Builder.make @dest_path, results, @ext
+
results = results.join("\n").b
assert_match %r{"DESTDIR=#{ENV['DESTDIR']}" clean$}, results
@@ -64,20 +62,18 @@ install:
ENV['DESTDIR'] = 'destination'
results = []
- Dir.chdir @ext do
- File.open 'Makefile', 'w' do |io|
- io.puts <<-MAKEFILE
+ File.open File.join(@ext, 'Makefile'), 'w' do |io|
+ io.puts <<-MAKEFILE
all:
\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
install:
\t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}"
- MAKEFILE
- end
-
- Gem::Ext::Builder.make @dest_path, results
+ MAKEFILE
end
+ Gem::Ext::Builder.make @dest_path, results, @ext
+
results = results.join("\n").b
assert_match %r{"DESTDIR=#{ENV['DESTDIR']}" clean$}, results
diff --git a/test/rubygems/test_gem_ext_cmake_builder.rb b/test/rubygems/test_gem_ext_cmake_builder.rb
index 60a1fa13f6..e347359679 100644
--- a/test/rubygems/test_gem_ext_cmake_builder.rb
+++ b/test/rubygems/test_gem_ext_cmake_builder.rb
@@ -36,9 +36,7 @@ install (FILES test.txt DESTINATION bin)
output = []
- Dir.chdir @ext do
- Gem::Ext::CmakeBuilder.build nil, @dest_path, output
- end
+ Gem::Ext::CmakeBuilder.build nil, @dest_path, output, [], nil, @ext
output = output.join "\n"
@@ -54,9 +52,7 @@ install (FILES test.txt DESTINATION bin)
output = []
error = assert_raises Gem::InstallError do
- Dir.chdir @ext do
- Gem::Ext::CmakeBuilder.build nil, @dest_path, output
- end
+ Gem::Ext::CmakeBuilder.build nil, @dest_path, output, [], nil, @ext
end
output = output.join "\n"
@@ -77,9 +73,7 @@ install (FILES test.txt DESTINATION bin)
output = []
- Dir.chdir @ext do
- Gem::Ext::CmakeBuilder.build nil, @dest_path, output
- end
+ Gem::Ext::CmakeBuilder.build nil, @dest_path, output, [], nil, @ext
output = output.join "\n"
diff --git a/test/rubygems/test_gem_ext_configure_builder.rb b/test/rubygems/test_gem_ext_configure_builder.rb
index 7d7f3759ea..a74f5ce055 100644
--- a/test/rubygems/test_gem_ext_configure_builder.rb
+++ b/test/rubygems/test_gem_ext_configure_builder.rb
@@ -25,9 +25,7 @@ class TestGemExtConfigureBuilder < Gem::TestCase
output = []
- Dir.chdir @ext do
- Gem::Ext::ConfigureBuilder.build nil, @dest_path, output
- end
+ Gem::Ext::ConfigureBuilder.build nil, @dest_path, output, [], nil, @ext
assert_match(/^current directory:/, output.shift)
assert_equal "sh ./configure --prefix=#{@dest_path}", output.shift
@@ -48,9 +46,7 @@ class TestGemExtConfigureBuilder < Gem::TestCase
output = []
error = assert_raises Gem::InstallError do
- Dir.chdir @ext do
- Gem::Ext::ConfigureBuilder.build nil, @dest_path, output
- end
+ Gem::Ext::ConfigureBuilder.build nil, @dest_path, output, [], nil, @ext
end
shell_error_msg = %r{(\./configure: .*)|((?:[Cc]an't|cannot) open '?\./configure'?(?:: No such file or directory)?)}
@@ -74,9 +70,7 @@ class TestGemExtConfigureBuilder < Gem::TestCase
end
output = []
- Dir.chdir @ext do
- Gem::Ext::ConfigureBuilder.build nil, @dest_path, output
- end
+ Gem::Ext::ConfigureBuilder.build nil, @dest_path, output, [], nil, @ext
assert_contains_make_command 'clean', output[1]
assert_contains_make_command '', output[4]
diff --git a/test/rubygems/test_gem_ext_ext_conf_builder.rb b/test/rubygems/test_gem_ext_ext_conf_builder.rb
index 05ac538ec2..21fe27166b 100644
--- a/test/rubygems/test_gem_ext_ext_conf_builder.rb
+++ b/test/rubygems/test_gem_ext_ext_conf_builder.rb
@@ -29,12 +29,9 @@ class TestGemExtExtConfBuilder < Gem::TestCase
output = []
- Dir.chdir @ext do
- result =
- Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
+ result = Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output, [], nil, @ext
- assert_same result, output
- end
+ assert_same result, output
assert_match(/^current directory:/, output[0])
assert_match(/^#{Gem.ruby}.* extconf.rb/, output[1])
@@ -59,9 +56,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase
output = []
- Dir.chdir @ext do
- Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
- end
+ Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output, [], nil, @ext
assert_equal "creating Makefile\n", output[2]
assert_contains_make_command 'clean', output[4]
@@ -86,9 +81,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase
output = []
assert_raises Gem::InstallError do
- Dir.chdir @ext do
- Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
- end
+ Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output, [], nil, @ext
end
assert_equal "creating Makefile\n", output[2]
@@ -112,9 +105,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase
output = []
error = assert_raises Gem::InstallError do
- Dir.chdir @ext do
- Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
- end
+ Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output, [], nil, @ext
end
assert_equal 'extconf failed, exit code 1', error.message
@@ -139,9 +130,7 @@ class TestGemExtExtConfBuilder < Gem::TestCase
output = []
- Dir.chdir @ext do
- Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
- end
+ Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output, [], nil, @ext
refute_includes(output, "To see why this extension failed to compile, please check the mkmf.log which can be found here:\n")
@@ -181,9 +170,7 @@ end
output = []
- Dir.chdir @ext do
- Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output
- end
+ Gem::Ext::ExtConfBuilder.build 'extconf.rb', @dest_path, output, [], nil, @ext
assert_contains_make_command 'clean', output[4]
assert_contains_make_command '', output[7]
@@ -207,9 +194,7 @@ end
makefile.puts "install:"
end
- Dir.chdir @ext do
- Gem::Ext::ExtConfBuilder.make @ext, output
- end
+ Gem::Ext::ExtConfBuilder.make @ext, output, @ext
assert_contains_make_command 'clean', output[1]
assert_contains_make_command '', output[4]
@@ -218,9 +203,7 @@ end
def test_class_make_no_Makefile
error = assert_raises Gem::InstallError do
- Dir.chdir @ext do
- Gem::Ext::ExtConfBuilder.make @ext, ['output']
- end
+ Gem::Ext::ExtConfBuilder.make @ext, ['output'], @ext
end
assert_equal 'Makefile not found', error.message
diff --git a/test/rubygems/test_gem_ext_rake_builder.rb b/test/rubygems/test_gem_ext_rake_builder.rb
index a13b09c98b..8cb96f7dd3 100644
--- a/test/rubygems/test_gem_ext_rake_builder.rb
+++ b/test/rubygems/test_gem_ext_rake_builder.rb
@@ -18,9 +18,7 @@ class TestGemExtRakeBuilder < Gem::TestCase
output = []
build_rake_in do |rake|
- Dir.chdir @ext do
- Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output
- end
+ Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output, [], nil, @ext
output = output.join "\n"
@@ -38,10 +36,8 @@ class TestGemExtRakeBuilder < Gem::TestCase
output = []
build_rake_in do |rake|
- Dir.chdir @ext do
- non_empty_args_list = ['']
- Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output, non_empty_args_list
- end
+ non_empty_args_list = ['']
+ Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', @dest_path, output, non_empty_args_list, nil, @ext
output = output.join "\n"
@@ -55,9 +51,7 @@ class TestGemExtRakeBuilder < Gem::TestCase
output = []
build_rake_in do |rake|
- Dir.chdir @ext do
- Gem::Ext::RakeBuilder.build "ext/Rakefile", @dest_path, output, ["test1", "test2"]
- end
+ Gem::Ext::RakeBuilder.build "ext/Rakefile", @dest_path, output, ["test1", "test2"], nil, @ext
output = output.join "\n"
@@ -72,9 +66,7 @@ class TestGemExtRakeBuilder < Gem::TestCase
build_rake_in(false) do |rake|
error = assert_raises Gem::InstallError do
- Dir.chdir @ext do
- Gem::Ext::RakeBuilder.build "mkrf_conf.rb", @dest_path, output
- end
+ Gem::Ext::RakeBuilder.build "mkrf_conf.rb", @dest_path, output, [], nil, @ext
end
assert_match %r{^rake failed}, error.message
diff --git a/test/rubygems/test_gem_gem_runner.rb b/test/rubygems/test_gem_gem_runner.rb
index 72a5c83431..8df11ecebc 100644
--- a/test/rubygems/test_gem_gem_runner.rb
+++ b/test/rubygems/test_gem_gem_runner.rb
@@ -74,17 +74,18 @@ class TestGemGemRunner < Gem::TestCase
args = %w[query]
use_ui @ui do
- assert_nil @runner.run(args)
+ @runner.run(args)
end
assert_match(/WARNING: query command is deprecated. It will be removed in Rubygems [0-9]+/, @ui.error)
+ assert_match(/WARNING: It is recommended that you use `gem search` or `gem list` instead/, @ui.error)
end
def test_info_succeeds
args = %w[info]
use_ui @ui do
- assert_nil @runner.run(args)
+ @runner.run(args)
end
assert_empty @ui.error
@@ -94,7 +95,7 @@ class TestGemGemRunner < Gem::TestCase
args = %w[list]
use_ui @ui do
- assert_nil @runner.run(args)
+ @runner.run(args)
end
assert_empty @ui.error
@@ -104,7 +105,7 @@ class TestGemGemRunner < Gem::TestCase
args = %w[search]
use_ui @ui do
- assert_nil @runner.run(args)
+ @runner.run(args)
end
assert_empty @ui.error
diff --git a/test/rubygems/test_gem_gemcutter_utilities.rb b/test/rubygems/test_gem_gemcutter_utilities.rb
index 48f6b09715..3290a3a908 100644
--- a/test/rubygems/test_gem_gemcutter_utilities.rb
+++ b/test/rubygems/test_gem_gemcutter_utilities.rb
@@ -32,7 +32,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
def test_alternate_key_alternate_host
keys = {
:rubygems_api_key => 'KEY',
- "http://rubygems.engineyard.com" => "EYKEY"
+ "http://rubygems.engineyard.com" => "EYKEY",
}
FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
@@ -202,7 +202,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
assert_match 'You have enabled multi-factor authentication. Please enter OTP code.', @sign_in_ui.output
assert_match 'Code: ', @sign_in_ui.output
- assert_match 'Signed in.', @sign_in_ui.output
+ assert_match 'Signed in with API key:', @sign_in_ui.output
assert_equal '111111', @fetcher.last_request['OTP']
end
@@ -233,7 +233,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
@fetcher.data["#{host}/api/v1/api_key"] = response
Gem::RemoteFetcher.fetcher = @fetcher
- @sign_in_ui = Gem::MockGemUi.new("#{email}\n#{password}\n" + extra_input)
+ @sign_in_ui = Gem::MockGemUi.new("#{email}\n#{password}\n\n\n\n\n\n\n\n\n" + extra_input)
use_ui @sign_in_ui do
if args.length > 0
diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb
index d9da22b129..b4528dba17 100644
--- a/test/rubygems/test_gem_install_update_options.rb
+++ b/test/rubygems/test_gem_install_update_options.rb
@@ -30,7 +30,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
args.concat %w[--vendor] unless Gem.java_platform?
- args.concat %w[-P HighSecurity] if defined?(OpenSSL::SSL)
+ args.concat %w[-P HighSecurity] if Gem::HAVE_OPENSSL
assert @cmd.handles?(args)
end
@@ -92,7 +92,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
end
def test_security_policy
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
@cmd.handle_options %w[-P HighSecurity]
@@ -100,7 +100,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
end
def test_security_policy_unknown
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
@cmd.add_install_update_options
@@ -192,4 +192,16 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
assert_equal true, @cmd.options[:post_install_message]
end
+
+ def test_minimal_deps_no
+ @cmd.handle_options %w[--no-minimal-deps]
+
+ assert_equal false, @cmd.options[:minimal_deps]
+ end
+
+ def test_minimal_deps
+ @cmd.handle_options %w[--minimal-deps]
+
+ assert_equal true, @cmd.options[:minimal_deps]
+ end
end
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index e984c7079c..0a9a2e38dd 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -83,7 +83,7 @@ end
end
def test_check_executable_overwrite_default_bin_dir
- installer = setup_base_installer
+ installer = setup_base_installer(false)
bindir(Gem.bindir) do
util_conflict_executable false
@@ -143,7 +143,7 @@ gem 'other', version
end
def test_check_executable_overwrite_other_gem
- installer = setup_base_installer
+ installer = setup_base_installer(false)
util_conflict_executable true
@@ -287,7 +287,7 @@ gem 'other', version
end
def test_ensure_loadable_spec_security_policy
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
_, a_gem = util_gem 'a', 2 do |s|
s.add_dependency 'garbage ~> 5'
@@ -345,7 +345,7 @@ gem 'other', version
options = {
:bin_dir => bin_dir,
- :install_dir => "/non/existent"
+ :install_dir => "/non/existent",
}
inst = Gem::Installer.at '', options
@@ -794,10 +794,35 @@ gem 'other', version
assert_equal spec, installer.install
- assert !File.exist?(system_path), 'plugin not written to user plugins_dir'
+ assert !File.exist?(system_path), 'plugin incorrectly written to system plugins_dir'
assert File.exist?(user_path), 'plugin not written to user plugins_dir'
end
+ def test_generate_plugins_with_build_root
+ spec = quick_gem 'a' do |s|
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
+ io.write "puts __FILE__"
+ end
+
+ s.files += %w[lib/rubygems_plugin.rb]
+ end
+
+ util_build_gem spec
+
+ File.chmod(0555, Gem.plugindir)
+ system_path = File.join(Gem.plugindir, 'a_plugin.rb')
+
+ build_root = File.join(@tempdir, 'build_root')
+ build_root_path = File.join(build_root, Gem.plugindir.gsub(/^[a-zA-Z]:/, ''), 'a_plugin.rb')
+
+ installer = Gem::Installer.at spec.cache_file, :build_root => build_root
+
+ assert_equal spec, installer.install
+
+ assert !File.exist?(system_path), 'plugin written incorrect written to system plugins_dir'
+ assert File.exist?(build_root_path), 'plugin not written to build_root'
+ end
+
def test_keeps_plugins_up_to_date
# NOTE: version a-2 is already installed by setup hooks
@@ -1134,7 +1159,7 @@ gem 'other', version
Gem::Package.build @spec
end
end
- installer = Gem::Installer.at @gem
+ installer = Gem::Installer.at @gem, :force => true
build_rake_in do
use_ui @ui do
assert_equal @spec, installer.install
@@ -1156,6 +1181,15 @@ gem 'other', version
assert_path_exists gem_dir
end
+ def test_install_build_root
+ build_root = File.join(@tempdir, 'build_root')
+
+ @gem = setup_base_gem
+ installer = Gem::Installer.at @gem, :build_root => build_root
+
+ assert_equal @spec, installer.install
+ end
+
def test_install_missing_dirs
installer = setup_base_installer
@@ -1337,7 +1371,7 @@ gem 'other', version
# reinstall the gem, this is also the same as pristine
use_ui @ui do
- installer = Gem::Installer.at path
+ installer = Gem::Installer.at path, :force => true
installer.install
end
@@ -1537,6 +1571,7 @@ gem 'other', version
installer = setup_base_installer
@spec.add_dependency 'b', '> 5'
installer = util_setup_gem
+ installer.force = false
use_ui @ui do
assert_raises Gem::InstallError do
@@ -1781,13 +1816,24 @@ gem 'other', version
def test_process_options_build_root
build_root = File.join @tempdir, 'build_root'
+ bin_dir = File.join(build_root, @gemhome.gsub(/^[a-zA-Z]:/, ''), 'bin')
+ gem_home = File.join(build_root, @gemhome.gsub(/^[a-zA-Z]:/, ''))
+ plugins_dir = File.join(build_root, @gemhome.gsub(/^[a-zA-Z]:/, ''), 'plugins')
@gem = setup_base_gem
- installer = Gem::Installer.at @gem, :build_root => build_root
+ installer = use_ui(@ui) { Gem::Installer.at @gem, :build_root => build_root }
+
+ assert_equal build_root, installer.build_root
+ assert_equal bin_dir, installer.bin_dir
+ assert_equal gem_home, installer.gem_home
- assert_equal Pathname(build_root), installer.build_root
- assert_equal File.join(build_root, @gemhome, 'bin'), installer.bin_dir
- assert_equal File.join(build_root, @gemhome), installer.gem_home
+ errors = @ui.error.split("\n")
+
+ assert_equal "WARNING: You build with buildroot.", errors.shift
+ assert_equal " Build root: #{build_root}", errors.shift
+ assert_equal " Bin dir: #{bin_dir}", errors.shift
+ assert_equal " Gem home: #{gem_home}", errors.shift
+ assert_equal " Plugins dir: #{plugins_dir}", errors.shift
end
def test_shebang_arguments
@@ -2169,6 +2215,23 @@ gem 'other', version
assert_equal ['exe/executable'], default_spec.files
end
+ def test_default_gem_to_specific_install_dir
+ @gem = setup_base_gem
+ installer = util_installer @spec, "#{@gemhome}2"
+ installer.options[:install_as_default] = true
+
+ use_ui @ui do
+ installer.install
+ end
+
+ assert_directory_exists File.join("#{@gemhome}2", 'specifications')
+ assert_directory_exists File.join("#{@gemhome}2", 'specifications', 'default')
+
+ default_spec = eval File.read File.join("#{@gemhome}2", 'specifications', 'default', 'a-2.gemspec')
+ assert_equal Gem::Version.new("2"), default_spec.version
+ assert_equal ['bin/executable'], default_spec.files
+ end
+
def test_package_attribute
gem = quick_gem 'c' do |spec|
util_make_exec spec, '#!/usr/bin/ruby', 'exe'
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index 5e9c3b7b81..fd28f9a2a5 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -95,7 +95,7 @@ class TestGemPackage < Gem::Package::TarTestCase
'SHA256' => {
'metadata.gz' => metadata_sha256,
'data.tar.gz' => Digest::SHA256.hexdigest(tar),
- }
+ },
}
assert_equal expected, YAML.load(checksums)
@@ -252,7 +252,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_build_auto_signed
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
FileUtils.mkdir_p File.join(Gem.user_home, '.gem')
@@ -295,7 +295,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_build_auto_signed_encrypted_key
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
FileUtils.mkdir_p File.join(Gem.user_home, '.gem')
@@ -364,7 +364,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_build_signed
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
spec = Gem::Specification.new 'build', '1'
spec.summary = 'build'
@@ -401,7 +401,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_build_signed_encrypted_key
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
spec = Gem::Specification.new 'build', '1'
spec.summary = 'build'
@@ -957,7 +957,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_verify_security_policy
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
package = Gem::Package.new @gem
package.security_policy = Gem::Security::HighSecurity
@@ -974,7 +974,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_verify_security_policy_low_security
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
@spec.cert_chain = [PUBLIC_CERT.to_pem]
@spec.signing_key = PRIVATE_KEY
@@ -994,7 +994,7 @@ class TestGemPackage < Gem::Package::TarTestCase
end
def test_verify_security_policy_checksum_missing
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
@spec.cert_chain = [PUBLIC_CERT.to_pem]
@spec.signing_key = PRIVATE_KEY
diff --git a/test/rubygems/test_gem_package_old.rb b/test/rubygems/test_gem_package_old.rb
index f2b1719dc3..8c4c20006b 100644
--- a/test/rubygems/test_gem_package_old.rb
+++ b/test/rubygems/test_gem_package_old.rb
@@ -23,7 +23,7 @@ unless Gem.java_platform? # jruby can't require the simple_gem file
end
def test_contents_security_policy
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
@package.security_policy = Gem::Security::AlmostNoSecurity
@@ -44,7 +44,7 @@ unless Gem.java_platform? # jruby can't require the simple_gem file
end
def test_extract_files_security_policy
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
@package.security_policy = Gem::Security::AlmostNoSecurity
@@ -58,7 +58,7 @@ unless Gem.java_platform? # jruby can't require the simple_gem file
end
def test_spec_security_policy
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
@package.security_policy = Gem::Security::AlmostNoSecurity
@@ -68,7 +68,7 @@ unless Gem.java_platform? # jruby can't require the simple_gem file
end
def test_verify
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
assert @package.verify
diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb
index e31efdd55f..25dac5f148 100644
--- a/test/rubygems/test_gem_package_tar_writer.rb
+++ b/test/rubygems/test_gem_package_tar_writer.rb
@@ -117,7 +117,7 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
end
def test_add_file_signer
- skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+ skip 'openssl is missing' unless Gem::HAVE_OPENSSL
signer = Gem::Security::Signer.new PRIVATE_KEY, [PUBLIC_CERT]
diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb
index 030033d2af..83a6f24de4 100644
--- a/test/rubygems/test_gem_platform.rb
+++ b/test/rubygems/test_gem_platform.rb
@@ -11,10 +11,69 @@ class TestGemPlatform < Gem::TestCase
end
def test_self_match
- assert Gem::Platform.match(nil), 'nil == ruby'
- assert Gem::Platform.match(Gem::Platform.local), 'exact match'
- assert Gem::Platform.match(Gem::Platform.local.to_s), '=~ match'
- assert Gem::Platform.match(Gem::Platform::RUBY), 'ruby'
+ Gem::Deprecate.skip_during do
+ assert Gem::Platform.match(nil), 'nil == ruby'
+ assert Gem::Platform.match(Gem::Platform.local), 'exact match'
+ assert Gem::Platform.match(Gem::Platform.local.to_s), '=~ match'
+ assert Gem::Platform.match(Gem::Platform::RUBY), 'ruby'
+ end
+ end
+
+ def test_self_match_gem?
+ assert Gem::Platform.match_gem?(nil, 'json'), 'nil == ruby'
+ assert Gem::Platform.match_gem?(Gem::Platform.local, 'json'), 'exact match'
+ assert Gem::Platform.match_gem?(Gem::Platform.local.to_s, 'json'), '=~ match'
+ assert Gem::Platform.match_gem?(Gem::Platform::RUBY, 'json'), 'ruby'
+ end
+
+ def test_self_match_spec?
+ make_spec = -> platform do
+ util_spec 'mygem-for-platform-match_spec', '1' do |s|
+ s.platform = platform
+ end
+ end
+
+ assert Gem::Platform.match_spec?(make_spec.call(nil)), 'nil == ruby'
+ assert Gem::Platform.match_spec?(make_spec.call(Gem::Platform.local)), 'exact match'
+ assert Gem::Platform.match_spec?(make_spec.call(Gem::Platform.local.to_s)), '=~ match'
+ assert Gem::Platform.match_spec?(make_spec.call(Gem::Platform::RUBY)), 'ruby'
+ end
+
+ def test_self_match_spec_with_match_gem_override
+ make_spec = -> name, platform do
+ util_spec name, '1' do |s|
+ s.platform = platform
+ end
+ end
+
+ class << Gem::Platform
+ alias_method :original_match_gem?, :match_gem?
+ def match_gem?(platform, gem_name)
+ # e.g., sassc and libv8 are such gems, their native extensions do not use the Ruby C API
+ if gem_name == 'gem-with-ruby-impl-independent-precompiled-ext'
+ match_platforms?(platform, [Gem::Platform::RUBY, Gem::Platform.local])
+ else
+ match_platforms?(platform, Gem.platforms)
+ end
+ end
+ end
+
+ platforms = Gem.platforms
+ Gem.platforms = [Gem::Platform::RUBY]
+ begin
+ assert_equal true, Gem::Platform.match_spec?(make_spec.call('mygem', Gem::Platform::RUBY))
+ assert_equal false, Gem::Platform.match_spec?(make_spec.call('mygem', Gem::Platform.local))
+
+ name = 'gem-with-ruby-impl-independent-precompiled-ext'
+ assert_equal true, Gem::Platform.match_spec?(make_spec.call(name, Gem::Platform.local))
+ ensure
+ Gem.platforms = platforms
+ class << Gem::Platform
+ remove_method :match_gem?
+ alias_method :match_gem?, :original_match_gem? # rubocop:disable Lint/DuplicateMethods
+ remove_method :original_match_gem?
+ end
+ end
end
def test_self_new
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index f6ca00589f..371998497b 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -2,13 +2,9 @@
require 'rubygems/test_case'
require 'webrick'
-begin
- require 'webrick/https'
-rescue LoadError => e
- raise unless e.path == 'openssl'
-end
+require 'webrick/https' if Gem::HAVE_OPENSSL
-unless defined?(OpenSSL::SSL)
+unless Gem::HAVE_OPENSSL
warn 'Skipping Gem::RemoteFetcher tests. openssl not found.'
end
@@ -667,7 +663,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_config_creds
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:id => 'testuser', :secret => 'testpass'}
+ 'my-bucket' => {:id => 'testuser', :secret => 'testpass'},
}
url = 's3://my-bucket/gems/specs.4.8.gz'
Time.stub :now, Time.at(1561353581) do
@@ -679,7 +675,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_config_creds_with_region
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:id => 'testuser', :secret => 'testpass', :region => 'us-west-2'}
+ 'my-bucket' => {:id => 'testuser', :secret => 'testpass', :region => 'us-west-2'},
}
url = 's3://my-bucket/gems/specs.4.8.gz'
Time.stub :now, Time.at(1561353581) do
@@ -691,7 +687,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_config_creds_with_token
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:id => 'testuser', :secret => 'testpass', :security_token => 'testtoken'}
+ 'my-bucket' => {:id => 'testuser', :secret => 'testpass', :security_token => 'testtoken'},
}
url = 's3://my-bucket/gems/specs.4.8.gz'
Time.stub :now, Time.at(1561353581) do
@@ -706,7 +702,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
ENV['AWS_SECRET_ACCESS_KEY'] = 'testpass'
ENV['AWS_SESSION_TOKEN'] = nil
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:provider => 'env'}
+ 'my-bucket' => {:provider => 'env'},
}
url = 's3://my-bucket/gems/specs.4.8.gz'
Time.stub :now, Time.at(1561353581) do
@@ -722,7 +718,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
ENV['AWS_SECRET_ACCESS_KEY'] = 'testpass'
ENV['AWS_SESSION_TOKEN'] = nil
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:provider => 'env', :region => 'us-west-2'}
+ 'my-bucket' => {:provider => 'env', :region => 'us-west-2'},
}
url = 's3://my-bucket/gems/specs.4.8.gz'
Time.stub :now, Time.at(1561353581) do
@@ -738,7 +734,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
ENV['AWS_SECRET_ACCESS_KEY'] = 'testpass'
ENV['AWS_SESSION_TOKEN'] = 'testtoken'
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:provider => 'env'}
+ 'my-bucket' => {:provider => 'env'},
}
url = 's3://my-bucket/gems/specs.4.8.gz'
Time.stub :now, Time.at(1561353581) do
@@ -758,7 +754,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_instance_profile_creds
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:provider => 'instance_profile'}
+ 'my-bucket' => {:provider => 'instance_profile'},
}
url = 's3://my-bucket/gems/specs.4.8.gz'
@@ -772,7 +768,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_instance_profile_creds_with_region
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:provider => 'instance_profile', :region => 'us-west-2'}
+ 'my-bucket' => {:provider => 'instance_profile', :region => 'us-west-2'},
}
url = 's3://my-bucket/gems/specs.4.8.gz'
@@ -786,7 +782,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_instance_profile_creds_with_token
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:provider => 'instance_profile'}
+ 'my-bucket' => {:provider => 'instance_profile'},
}
url = 's3://my-bucket/gems/specs.4.8.gz'
@@ -816,7 +812,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def test_fetch_s3_no_host
Gem.configuration[:s3_source] = {
- 'my-bucket' => {:id => 'testuser', :secret => 'testpass'}
+ 'my-bucket' => {:id => 'testuser', :secret => 'testpass'},
}
url = 's3://other-bucket/gems/specs.4.8.gz'
@@ -1062,7 +1058,7 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
:SSLCertificate => cert('ssl_cert.pem'),
:SSLPrivateKey => key('ssl_key.pem'),
:SSLVerifyClient => nil,
- :SSLCertName => nil
+ :SSLCertName => nil,
}.merge(config))
server.mount_proc("/yaml") do |req, res|
res.body = "--- true\n"
@@ -1145,4 +1141,4 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
def key(filename)
OpenSSL::PKey::RSA.new(File.read(File.join(__dir__, filename)))
end
-end if defined?(OpenSSL::SSL)
+end if Gem::HAVE_OPENSSL
diff --git a/test/rubygems/test_gem_request.rb b/test/rubygems/test_gem_request.rb
index 82b95b47c3..47e5f97074 100644
--- a/test/rubygems/test_gem_request.rb
+++ b/test/rubygems/test_gem_request.rb
@@ -4,7 +4,7 @@ require 'rubygems/request'
require 'ostruct'
require 'base64'
-unless defined?(OpenSSL::SSL)
+unless Gem::HAVE_OPENSSL
warn 'Skipping Gem::Request tests. openssl not found.'
end
@@ -506,4 +506,4 @@ ERROR: Certificate is an invalid CA certificate
@response
end
end
-end if defined?(OpenSSL::SSL)
+end if Gem::HAVE_OPENSSL
diff --git a/test/rubygems/test_gem_request_set_lockfile.rb b/test/rubygems/test_gem_request_set_lockfile.rb
index e7921d6b26..44a47f2e00 100644
--- a/test/rubygems/test_gem_request_set_lockfile.rb
+++ b/test/rubygems/test_gem_request_set_lockfile.rb
@@ -51,7 +51,7 @@ class TestGemRequestSetLockfile < Gem::TestCase
expected = [
'DEPENDENCIES',
' a',
- nil
+ nil,
]
assert_equal expected, out
@@ -78,7 +78,7 @@ class TestGemRequestSetLockfile < Gem::TestCase
expected = [
'DEPENDENCIES',
' a (~> 2.0)',
- nil
+ nil,
]
assert_equal expected, out
@@ -111,7 +111,7 @@ class TestGemRequestSetLockfile < Gem::TestCase
' a (2)',
' b',
' b (2)',
- nil
+ nil,
]
assert_equal expected, out
@@ -139,7 +139,7 @@ class TestGemRequestSetLockfile < Gem::TestCase
'PLATFORMS',
' ruby',
' x86-darwin-8',
- nil
+ nil,
]
assert_equal expected, out
diff --git a/test/rubygems/test_gem_resolver_api_set.rb b/test/rubygems/test_gem_resolver_api_set.rb
index 6942b8587d..4b545b1b9a 100644
--- a/test/rubygems/test_gem_resolver_api_set.rb
+++ b/test/rubygems/test_gem_resolver_api_set.rb
@@ -39,7 +39,7 @@ class TestGemResolverAPISet < Gem::TestCase
{ :name => 'a',
:number => '1',
:platform => 'ruby',
- :dependencies => [], },
+ :dependencies => [] },
]
@fetcher.data["#{@dep_uri}?gems=a"] = Marshal.dump data
@@ -49,7 +49,7 @@ class TestGemResolverAPISet < Gem::TestCase
a_dep = @DR::DependencyRequest.new dep('a'), nil
expected = [
- @DR::APISpecification.new(set, data.first)
+ @DR::APISpecification.new(set, data.first),
]
assert_equal expected, set.find_all(a_dep)
@@ -62,7 +62,7 @@ class TestGemResolverAPISet < Gem::TestCase
{ :name => 'a',
:number => '1',
:platform => 'ruby',
- :dependencies => [], },
+ :dependencies => [] },
]
@fetcher.data["#{@dep_uri}?gems=a"] = Marshal.dump data
@@ -74,7 +74,7 @@ class TestGemResolverAPISet < Gem::TestCase
set.prefetch [a_dep]
expected = [
- @DR::APISpecification.new(set, data.first)
+ @DR::APISpecification.new(set, data.first),
]
assert_equal expected, set.find_all(a_dep)
@@ -114,7 +114,7 @@ class TestGemResolverAPISet < Gem::TestCase
{ :name => 'a',
:number => '1',
:platform => 'ruby',
- :dependencies => [], },
+ :dependencies => [] },
]
@fetcher.data["#{@dep_uri}?gems=a,b"] = Marshal.dump data
@@ -138,7 +138,7 @@ class TestGemResolverAPISet < Gem::TestCase
{ :name => 'a',
:number => '1',
:platform => 'ruby',
- :dependencies => [], },
+ :dependencies => [] },
]
@fetcher.data["#{@dep_uri}?gems=a"] = Marshal.dump data
@@ -163,7 +163,7 @@ class TestGemResolverAPISet < Gem::TestCase
{ :name => 'a',
:number => '1',
:platform => 'ruby',
- :dependencies => [], },
+ :dependencies => [] },
]
@fetcher.data["#{@dep_uri}?gems=a,b"] = Marshal.dump data
@@ -187,7 +187,7 @@ class TestGemResolverAPISet < Gem::TestCase
{ :name => 'a',
:number => '1',
:platform => 'ruby',
- :dependencies => [], },
+ :dependencies => [] },
]
@fetcher.data["#{@dep_uri}?gems=a,b"] = Marshal.dump data
diff --git a/test/rubygems/test_gem_resolver_conflict.rb b/test/rubygems/test_gem_resolver_conflict.rb
index 5a3ed80670..ff5fe9bae3 100644
--- a/test/rubygems/test_gem_resolver_conflict.rb
+++ b/test/rubygems/test_gem_resolver_conflict.rb
@@ -73,7 +73,7 @@ class TestGemResolverConflict < Gem::TestCase
expected = [
'net-ssh (>= 2.0.13), 2.2.2 activated',
- 'rye (= 0.9.8), 0.9.8 activated'
+ 'rye (= 0.9.8), 0.9.8 activated',
]
assert_equal expected, conflict.request_path(child.requester)
diff --git a/test/rubygems/test_gem_resolver_vendor_set.rb b/test/rubygems/test_gem_resolver_vendor_set.rb
index 99e2c5ae5f..d14b877b45 100644
--- a/test/rubygems/test_gem_resolver_vendor_set.rb
+++ b/test/rubygems/test_gem_resolver_vendor_set.rb
@@ -51,7 +51,7 @@ class TestGemResolverVendorSet < Gem::TestCase
source = Gem::Source::Vendor.new directory
expected = [
- Gem::Resolver::VendorSpecification.new(@set, spec, source)
+ Gem::Resolver::VendorSpecification.new(@set, spec, source),
]
assert_equal expected, found
diff --git a/test/rubygems/test_gem_security.rb b/test/rubygems/test_gem_security.rb
index 4d07887d36..92f9e55b21 100644
--- a/test/rubygems/test_gem_security.rb
+++ b/test/rubygems/test_gem_security.rb
@@ -2,7 +2,7 @@
require 'rubygems/test_case'
require 'rubygems/security'
-unless defined?(OpenSSL::SSL)
+unless Gem::HAVE_OPENSSL
warn 'Skipping Gem::Security tests. openssl not found.'
end
@@ -309,4 +309,4 @@ class TestGemSecurity < Gem::TestCase
assert_equal key.to_pem, key_from_file.to_pem
end
-end if defined?(OpenSSL::SSL) && !Gem.java_platform?
+end if Gem::HAVE_OPENSSL && !Gem.java_platform?
diff --git a/test/rubygems/test_gem_security_policy.rb b/test/rubygems/test_gem_security_policy.rb
index 86100d7c74..85e4590655 100644
--- a/test/rubygems/test_gem_security_policy.rb
+++ b/test/rubygems/test_gem_security_policy.rb
@@ -2,7 +2,7 @@
require 'rubygems/test_case'
-unless defined?(OpenSSL::SSL)
+unless Gem::HAVE_OPENSSL
warn 'Skipping Gem::Security::Policy tests. openssl not found.'
end
@@ -532,4 +532,4 @@ class TestGemSecurityPolicy < Gem::TestCase
return digests, signatures
end
-end if defined?(OpenSSL::SSL)
+end if Gem::HAVE_OPENSSL
diff --git a/test/rubygems/test_gem_security_signer.rb b/test/rubygems/test_gem_security_signer.rb
index 050748a8b5..8a09f97f26 100644
--- a/test/rubygems/test_gem_security_signer.rb
+++ b/test/rubygems/test_gem_security_signer.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'rubygems/test_case'
-unless defined?(OpenSSL::SSL)
+unless Gem::HAVE_OPENSSL
warn 'Skipping Gem::Security::Signer tests. openssl not found.'
end
@@ -214,4 +214,4 @@ toqvglr0kdbknSRRjBVLK6tsgr07aLT9gNP7mTW2PA==
signer.sign 'hello'
end
end
-end if defined?(OpenSSL::SSL)
+end if Gem::HAVE_OPENSSL
diff --git a/test/rubygems/test_gem_security_trust_dir.rb b/test/rubygems/test_gem_security_trust_dir.rb
index 64871f7bd3..201de9d36b 100644
--- a/test/rubygems/test_gem_security_trust_dir.rb
+++ b/test/rubygems/test_gem_security_trust_dir.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'rubygems/test_case'
-unless defined?(OpenSSL::SSL)
+unless Gem::HAVE_OPENSSL
warn 'Skipping Gem::Security::TrustDir tests. openssl not found.'
end
@@ -95,4 +95,4 @@ class TestGemSecurityTrustDir < Gem::TestCase
assert_equal mask, File.stat(@dest_dir).mode unless win_platform?
end
-end if defined?(OpenSSL::SSL)
+end if Gem::HAVE_OPENSSL
diff --git a/test/rubygems/test_gem_source.rb b/test/rubygems/test_gem_source.rb
index 599d490d95..09c510f096 100644
--- a/test/rubygems/test_gem_source.rb
+++ b/test/rubygems/test_gem_source.rb
@@ -240,6 +240,11 @@ class TestGemSource < Gem::TestCase
refute rubygems_source.typo_squatting?("rubysertgems.org")
end
+ def test_typo_squatting_false_positive
+ rubygems_source = Gem::Source.new("https://rubygems.org")
+ refute rubygems_source.typo_squatting?("rubygems.org")
+ end
+
def test_typo_squatting_custom_distance_threshold
rubygems_source = Gem::Source.new("https://rubgems.org")
distance_threshold = 5
diff --git a/test/rubygems/test_gem_source_subpath_problem.rb b/test/rubygems/test_gem_source_subpath_problem.rb
new file mode 100644
index 0000000000..eb92b7d404
--- /dev/null
+++ b/test/rubygems/test_gem_source_subpath_problem.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+require 'rubygems/test_case'
+require 'rubygems/source'
+
+class TestGemSourceSubpathProblem < Gem::TestCase
+ def tuple(*args)
+ Gem::NameTuple.new(*args)
+ end
+
+ def setup
+ super
+
+ @gem_repo = "http://gems.example.com/private"
+
+ spec_fetcher
+
+ @source = Gem::Source.new(@gem_repo)
+
+ util_make_gems
+ end
+
+ def test_dependency_resolver_set
+ response = Net::HTTPResponse.new '1.1', 200, 'OK'
+ response.uri = URI('http://example') if response.respond_to? :uri
+
+ @fetcher.data["#{@gem_repo}/api/v1/dependencies"] = response
+
+ set = @source.dependency_resolver_set
+
+ assert_kind_of Gem::Resolver::APISet, set
+ end
+
+ def test_fetch_spec
+ @fetcher.data["#{@gem_repo}/#{Gem::MARSHAL_SPEC_DIR}#{@a1.spec_name}.rz"] = Zlib::Deflate.deflate(Marshal.dump(@a1))
+
+ spec = @source.fetch_spec tuple('a', Gem::Version.new(1), 'ruby')
+ assert_equal @a1.full_name, spec.full_name
+ end
+
+ def test_load_specs
+ @fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = util_gzip(Marshal.dump([
+ Gem::NameTuple.new(@a1.name, @a1.version, 'ruby'),
+ Gem::NameTuple.new(@b2.name, @b2.version, 'ruby'),
+ ]))
+
+ released = @source.load_specs(:latest).map {|spec| spec.full_name }
+ assert_equal %W[a-1 b-2], released
+ end
+end
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index f635be859b..76072184bd 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'benchmark'
require 'rubygems/test_case'
+require 'date'
require 'pathname'
require 'stringio'
require 'rubygems/ext'
@@ -1999,7 +2000,7 @@ dependencies: []
test_cases = {
'i386-mswin32' => 'a-1-x86-mswin32-60',
'i386-mswin32_80' => 'a-1-x86-mswin32-80',
- 'i386-mingw32' => 'a-1-x86-mingw32'
+ 'i386-mingw32' => 'a-1-x86-mingw32',
}
test_cases.each do |arch, expected|
@@ -3035,7 +3036,7 @@ Please report a bug if this causes problems.
specification.define_singleton_method(:find_all_by_name) do |dep_name|
[
specification.new {|s| s.name = "z", s.version = Gem::Version.new("1") },
- specification.new {|s| s.name = "z", s.version = Gem::Version.new("2") }
+ specification.new {|s| s.name = "z", s.version = Gem::Version.new("2") },
]
end
@@ -3578,7 +3579,7 @@ Did you mean 'Ruby'?
"one" => "two",
"home" => "three",
"homepage_uri" => "https://example.com/user/repo",
- "funding_uri" => "https://example.com/donate"
+ "funding_uri" => "https://example.com/donate",
}
end
@@ -3838,7 +3839,7 @@ end
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
- spec_path = File.join(@default_spec_dir, default_gem_spec.spec_name)
+ spec_path = File.join(@gemhome, "specifications", "default", default_gem_spec.spec_name)
write_file(spec_path) do |file|
file.print(default_gem_spec.to_ruby)
end
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index 1c084c4c5d..1ca4991d1e 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -177,7 +177,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
@spec.files += %w[lib/rubygems_plugin.rb]
- Gem::Installer.at(Gem::Package.build(@spec)).install
+ Gem::Installer.at(Gem::Package.build(@spec), :force => true).install
plugin_path = File.join Gem.plugindir, 'a_plugin.rb'
assert File.exist?(plugin_path), 'plugin not written'
@@ -194,7 +194,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
@spec.files += %w[lib/rubygems_plugin.rb]
- Gem::Installer.at(Gem::Package.build(@spec)).install
+ Gem::Installer.at(Gem::Package.build(@spec), :force => true).install
plugin_path = File.join Gem.plugindir, 'a_plugin.rb'
assert File.exist?(plugin_path), 'plugin not written'
@@ -212,7 +212,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
@spec.files += %w[lib/rubygems_plugin.rb]
- Gem::Installer.at(Gem::Package.build(@spec)).install
+ Gem::Installer.at(Gem::Package.build(@spec), :force => true).install
plugin_path = File.join Gem.plugindir, 'a_plugin.rb'
assert File.exist?(plugin_path), 'plugin not written'
@@ -314,7 +314,7 @@ create_makefile '#{@spec.name}'
use_ui @ui do
path = Gem::Package.build @spec
- installer = Gem::Installer.at path
+ installer = Gem::Installer.at path, :force => true
installer.install
end
@@ -633,19 +633,19 @@ create_makefile '#{@spec.name}'
plugin_path = File.join Gem.plugindir, 'a_plugin.rb'
@spec.version = '1'
- Gem::Installer.at(Gem::Package.build(@spec)).install
+ Gem::Installer.at(Gem::Package.build(@spec), :force => true).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
+ Gem::Installer.at(Gem::Package.build(@spec), :force => true).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
+ Gem::Installer.at(Gem::Package.build(@spec), :force => true).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'
diff --git a/test/rubygems/test_gem_validator.rb b/test/rubygems/test_gem_validator.rb
index d4159d59e2..5158543fa9 100644
--- a/test/rubygems/test_gem_validator.rb
+++ b/test/rubygems/test_gem_validator.rb
@@ -26,7 +26,7 @@ class TestGemValidator < Gem::TestCase
@spec.file_name => [
Gem::Validator::ErrorData.new('lib/b.rb', 'Missing file'),
Gem::Validator::ErrorData.new('lib/c.rb', 'Extra file'),
- ]
+ ],
}
assert_equal expected, alien
diff --git a/test/rubygems/test_gem_version_option.rb b/test/rubygems/test_gem_version_option.rb
index 396fc6277c..49a8513dbe 100644
--- a/test/rubygems/test_gem_version_option.rb
+++ b/test/rubygems/test_gem_version_option.rb
@@ -56,7 +56,7 @@ class TestGemVersionOption < Gem::TestCase
@cmd.handle_options %w[--platform ruby]
expected = [
- Gem::Platform::RUBY
+ Gem::Platform::RUBY,
]
assert_equal expected, Gem.platforms
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index 2b6620cc65..8c7d06edc3 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -120,7 +120,7 @@ class TestGemRequire < Gem::TestCase
c1 = new_default_spec "c", "1", nil, "c/c.rb"
c2 = new_default_spec "c", "2", nil, "c/c.rb"
- install_default_specs c1, c2, b1, a1
+ install_default_gems c1, c2, b1, a1
dir = Dir.mktmpdir("test_require", @tempdir)
dash_i_arg = File.join dir, 'lib'
@@ -405,8 +405,8 @@ class TestGemRequire < Gem::TestCase
# Remove an old default gem version directly from disk as if someone ran
# gem cleanup.
- FileUtils.rm_rf(File.join @default_dir, "#{b1.full_name}")
- FileUtils.rm_rf(File.join @default_spec_dir, "#{b1.full_name}.gemspec")
+ FileUtils.rm_rf(File.join @gemhome, "#{b1.full_name}")
+ FileUtils.rm_rf(File.join @gemhome, "specifications", "default", "#{b1.full_name}.gemspec")
# Require gems that have not been removed.
assert_require 'a/b'
@@ -433,7 +433,7 @@ class TestGemRequire < Gem::TestCase
def test_default_gem_only
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
- install_default_specs(default_gem_spec)
+ install_default_gems(default_gem_spec)
assert_require "default/gem"
assert_equal %w[default-2.0.0.0], loaded_spec_names
end
@@ -441,7 +441,7 @@ class TestGemRequire < Gem::TestCase
def test_default_gem_require_activates_just_once
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
- install_default_specs(default_gem_spec)
+ install_default_gems(default_gem_spec)
assert_require "default/gem"
@@ -506,7 +506,7 @@ class TestGemRequire < Gem::TestCase
def test_default_gem_and_normal_gem
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
- install_default_specs(default_gem_spec)
+ install_default_gems(default_gem_spec)
normal_gem_spec = util_spec("default", "3.0", nil,
"lib/default/gem.rb")
install_specs(normal_gem_spec)
@@ -544,11 +544,11 @@ class TestGemRequire < Gem::TestCase
def test_default_gem_prerelease
default_gem_spec = new_default_spec("default", "2.0.0",
nil, "default/gem.rb")
- install_default_specs(default_gem_spec)
+ install_default_gems(default_gem_spec)
normal_gem_higher_prerelease_spec = util_spec("default", "3.0.0.rc2", nil,
"lib/default/gem.rb")
- install_default_specs(normal_gem_higher_prerelease_spec)
+ install_default_gems(normal_gem_higher_prerelease_spec)
assert_require "default/gem"
assert_equal %w[default-3.0.0.rc2], loaded_spec_names
@@ -586,7 +586,7 @@ class TestGemRequire < Gem::TestCase
def test_require_when_gem_defined
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
- install_default_specs(default_gem_spec)
+ install_default_gems(default_gem_spec)
c = Class.new do
def self.gem(*args)
raise "received #gem with #{args.inspect}"
@@ -677,6 +677,47 @@ class TestGemRequire < Gem::TestCase
end
end
end
+
+ def test_no_crash_when_overriding_warn_with_warning_module
+ skip "https://github.com/oracle/truffleruby/issues/2109" if RUBY_ENGINE == "truffleruby"
+
+ Dir.mktmpdir("warn_test") do |dir|
+ File.write(dir + "/main.rb", "module Warning; def warn(str); super; end; end; warn 'Foo Bar'")
+ _, err = capture_subprocess_io do
+ system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "main.rb")
+ end
+ assert_match(/Foo Bar\n$/, err)
+ _, err = capture_subprocess_io do
+ system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "main.rb")
+ end
+ assert_match(/Foo Bar\n$/, err)
+ end
+ end
+
+ def test_expected_backtrace_location_when_inheriting_from_basic_object_and_including_kernel
+ Dir.mktmpdir("warn_test") do |dir|
+ File.write(dir + "/main.rb", "\nrequire 'sub'\n")
+ File.write(dir + "/sub.rb", <<-'RUBY')
+ require 'rubygems'
+ class C < BasicObject
+ include ::Kernel
+ def deprecated
+ warn "This is a deprecated method", uplevel: 2
+ end
+ end
+ C.new.deprecated
+ RUBY
+
+ _, err = capture_subprocess_io do
+ system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "-I", dir, "main.rb")
+ end
+ assert_match(/main\.rb:2: warning: This is a deprecated method$/, err)
+ _, err = capture_subprocess_io do
+ system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "-I", dir, "main.rb")
+ end
+ assert_match(/main\.rb:2: warning: This is a deprecated method$/, err)
+ end
+ end
end
private