summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/test_gem.rb38
-rw-r--r--test/rubygems/test_gem_command_manager.rb10
-rw-r--r--test/rubygems/test_gem_commands_build_command.rb41
-rw-r--r--test/rubygems/test_gem_commands_dependency_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_setup_command.rb25
-rw-r--r--test/rubygems/test_gem_config_file.rb4
-rw-r--r--test/rubygems/test_gem_installer.rb34
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb1
-rw-r--r--test/rubygems/test_gem_requirement.rb6
-rw-r--r--test/rubygems/test_gem_uninstaller.rb23
-rw-r--r--test/rubygems/test_gem_version.rb7
-rw-r--r--test/rubygems/test_require.rb13
12 files changed, 149 insertions, 55 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index abf7092991..af927ffa29 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -267,6 +267,14 @@ class TestGem < Gem::TestCase
assert_match 'a-2/bin/exec', Gem.bin_path('a', 'exec', '>= 0')
end
+ def test_self_activate_bin_path_no_exec_name
+ e = assert_raises ArgumentError do
+ Gem.activate_bin_path 'a'
+ end
+
+ assert_equal 'you must supply exec_name', e.message
+ end
+
def test_activate_bin_path_resolves_eagerly
a1 = util_spec 'a', '1' do |s|
s.executables = ['exec']
@@ -1548,19 +1556,15 @@ class TestGem < Gem::TestCase
ENV['RUBYGEMS_GEMDEPS'] = "-"
- expected_specs = [a, b, (Gem::USE_BUNDLER_FOR_GEMDEPS || nil) && util_spec("bundler", Bundler::VERSION), c].compact
+ expected_specs = [a, b, util_spec("bundler", Bundler::VERSION), c].compact
assert_equal expected_specs, Gem.use_gemdeps.sort_by { |s| s.name }
end
LIB_PATH = File.expand_path "../../../lib".dup.untaint, __FILE__.dup.untaint
-
- if Gem::USE_BUNDLER_FOR_GEMDEPS
- BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }.dup.untaint
- BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze
- end
+ BUNDLER_LIB_PATH = File.expand_path $LOAD_PATH.find {|lp| File.file?(File.join(lp, "bundler.rb")) }.dup.untaint
+ BUNDLER_FULL_NAME = "bundler-#{Bundler::VERSION}".freeze
def add_bundler_full_name(names)
- return names unless Gem::USE_BUNDLER_FOR_GEMDEPS
names << BUNDLER_FULL_NAME
names.sort!
names
@@ -1600,7 +1604,7 @@ class TestGem < Gem::TestCase
out = IO.popen(cmd, &:read).split(/\n/)
assert_equal ["b-1", "c-1"], out - out0
- end if Gem::USE_BUNDLER_FOR_GEMDEPS
+ end
def test_looks_for_gemdeps_files_automatically_on_start_in_parent_dir
util_clear_gems
@@ -1640,7 +1644,7 @@ class TestGem < Gem::TestCase
Dir.rmdir "sub1"
assert_equal ["b-1", "c-1"], out - out0
- end if Gem::USE_BUNDLER_FOR_GEMDEPS
+ end
def test_register_default_spec
Gem.clear_default_specs
@@ -1819,27 +1823,19 @@ class TestGem < Gem::TestCase
else
platform = " #{platform}"
end
- expected =
- if Gem::USE_BUNDLER_FOR_GEMDEPS
- <<-EXPECTED
-Could not find gem 'a#{platform}' in any of the gem sources listed in your Gemfile.
-You may need to `gem install -g` to install missing gems
- EXPECTED
- else
- <<-EXPECTED
-Unable to resolve dependency: user requested 'a (>= 0)'
+ expected = <<-EXPECTED
+Could not find gem 'a#{platform}' in any of the gem sources listed in your Gemfile.
You may need to `gem install -g` to install missing gems
- EXPECTED
- end
+ EXPECTED
assert_output nil, expected do
Gem.use_gemdeps
end
ensure
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
- end if Gem::USE_BUNDLER_FOR_GEMDEPS
+ end
def test_use_gemdeps_specific
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], 'x'
diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb
index 83757b74c8..6ada96f1c1 100644
--- a/test/rubygems/test_gem_command_manager.rb
+++ b/test/rubygems/test_gem_command_manager.rb
@@ -103,16 +103,6 @@ class TestGemCommandManager < Gem::TestCase
assert_match(/invalid option: --bad-arg/i, @ui.error)
end
- def test_process_args_bad_no_ri
- use_ui @ui do
- assert_raises Gem::MockGemUi::TermError do
- @command_manager.process_args %w[--no-ri]
- end
- end
-
- assert_match(/invalid option: --no-ri. Use --no-document instead./i, @ui.error)
- end
-
# HACK move to install command test
def test_process_args_install
#capture all install options
diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb
index 02d1b98e8f..6441587cf6 100644
--- a/test/rubygems/test_gem_commands_build_command.rb
+++ b/test/rubygems/test_gem_commands_build_command.rb
@@ -351,4 +351,45 @@ class TestGemCommandsBuildCommand < Gem::TestCase
assert_equal(28, cert_days_to_expire)
end
+ def test_build_auto_resign_cert
+ skip 'openssl is missing' unless defined?(OpenSSL::SSL)
+
+ gem_path = File.join Gem.user_home, ".gem"
+ Dir.mkdir gem_path
+
+ Gem::Security.trust_dir
+
+ tmp_expired_cert_file = File.join gem_path, "gem-public_cert.pem"
+ File.write(tmp_expired_cert_file, File.read(EXPIRED_CERT_FILE))
+
+ tmp_private_key_file = File.join gem_path, "gem-private_key.pem"
+ File.write(tmp_private_key_file, File.read(PRIVATE_KEY_FILE))
+
+ spec = util_spec 'some_gem' do |s|
+ s.signing_key = tmp_private_key_file
+ s.cert_chain = [tmp_expired_cert_file]
+ end
+
+ gemspec_file = File.join(@tempdir, spec.spec_name)
+
+ File.open gemspec_file, 'w' do |gs|
+ gs.write spec.to_ruby
+ end
+
+ @cmd.options[:args] = [gemspec_file]
+
+ Gem.configuration.cert_expiration_length_days = 28
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ output = @ui.output.split "\n"
+ assert_equal "INFO: Your certificate has expired, trying to re-sign it...", output.shift
+ assert_equal "INFO: Your cert: #{tmp_expired_cert_file } has been auto re-signed with the key: #{tmp_private_key_file}", output.shift
+ assert_match /INFO: Your expired cert will be located at: .+\Wgem-public_cert\.pem\.expired\.[0-9]+/, output.shift
+ end
+
end
diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb
index 25b759dd85..eaa9594163 100644
--- a/test/rubygems/test_gem_commands_dependency_command.rb
+++ b/test/rubygems/test_gem_commands_dependency_command.rb
@@ -101,7 +101,7 @@ Gem x-2
fetcher.spec 'b', 2
end
- @cmd.options[:args] = %w[/[ab]/]
+ @cmd.options[:args] = %w[[ab]]
use_ui @stub_ui do
@cmd.execute
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index 87ec5c204c..3f9887eedf 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -135,24 +135,17 @@ class TestGemCommandsSetupCommand < Gem::TestCase
gem_exec = sprintf Gem.default_exec_format, 'gem'
default_gem_bin_path = File.join @install_dir, 'bin', gem_exec
- if Gem::USE_BUNDLER_FOR_GEMDEPS
- bundle_exec = sprintf Gem.default_exec_format, 'bundle'
- default_bundle_bin_path = File.join @install_dir, 'bin', bundle_exec
- end
-
+ bundle_exec = sprintf Gem.default_exec_format, 'bundle'
+ default_bundle_bin_path = File.join @install_dir, 'bin', bundle_exec
ruby_exec = sprintf Gem.default_exec_format, 'ruby'
if Gem.win_platform?
assert_match %r%\A#!\s*#{ruby_exec}%, File.read(default_gem_bin_path)
- if Gem::USE_BUNDLER_FOR_GEMDEPS
- assert_match %r%\A#!\s*#{ruby_exec}%, File.read(default_bundle_bin_path)
- end
+ assert_match %r%\A#!\s*#{ruby_exec}%, File.read(default_bundle_bin_path)
assert_match %r%\A#!\s*#{ruby_exec}%, File.read(gem_bin_path)
else
assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(default_gem_bin_path)
- if Gem::USE_BUNDLER_FOR_GEMDEPS
- assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(default_bundle_bin_path)
- end
+ assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(default_bundle_bin_path)
assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(gem_bin_path)
end
end
@@ -176,10 +169,8 @@ class TestGemCommandsSetupCommand < Gem::TestCase
assert_path_exists File.join(dir, 'rubygems.rb')
assert_path_exists File.join(dir, 'rubygems/ssl_certs/rubygems.org/foo.pem')
- if Gem::USE_BUNDLER_FOR_GEMDEPS
- assert_path_exists File.join(dir, 'bundler.rb')
- assert_path_exists File.join(dir, 'bundler/b.rb')
- end
+ assert_path_exists File.join(dir, 'bundler.rb')
+ assert_path_exists File.join(dir, 'bundler/b.rb')
end
end
@@ -223,7 +214,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
# expect to not remove bundler-* direcotyr.
assert_path_exists 'default/gems/bundler-audit-1.0.0'
- end if Gem::USE_BUNDLER_FOR_GEMDEPS
+ end
def test_remove_old_lib_files
lib = File.join @install_dir, 'lib'
@@ -271,7 +262,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
refute_path_exists old_builder_rb
refute_path_exists old_format_rb
- refute_path_exists old_bundler_c_rb if Gem::USE_BUNDLER_FOR_GEMDEPS
+ refute_path_exists old_bundler_c_rb
assert_path_exists securerandom_rb
assert_path_exists engine_defaults_rb
diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb
index 858d268d79..ea79cb8984 100644
--- a/test/rubygems/test_gem_config_file.rb
+++ b/test/rubygems/test_gem_config_file.rb
@@ -157,8 +157,8 @@ class TestGemConfigFile < Gem::TestCase
File.open conf3, 'w' do |fp|
fp.puts ':verbose: :loud'
end
-
- ENV['GEMRC'] = conf1 + ':' + conf2 + ';' + conf3
+ ps = File::PATH_SEPARATOR
+ ENV['GEMRC'] = conf1 + ps + conf2 + ps + conf3
util_config_file
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index d8b5868fd2..7f325080ec 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -901,6 +901,36 @@ gem 'other', version
assert_includes(e.message, "can't find gem a (= 3.0)")
end
+ def test_install_creates_binstub_that_prefers_user_installed_gem_to_default
+ Dir.mkdir util_inst_bindir
+
+ install_default_gems new_default_spec('default', '2')
+
+ util_setup_gem do |spec|
+ spec.name = 'default'
+ spec.version = '2'
+ end
+
+ util_clear_gems
+
+ @installer.wrappers = true
+
+ @newspec = nil
+ build_rake_in do
+ use_ui @ui do
+ @newspec = @installer.install
+ end
+ end
+
+ exe = File.join @gemhome, 'bin', 'executable'
+
+ e = assert_raises RuntimeError do
+ instance_eval File.read(exe)
+ end
+
+ assert_equal(e.message, "ran executable")
+ end
+
def test_install_creates_binstub_that_dont_trust_encoding
Dir.mkdir util_inst_bindir
util_setup_gem
@@ -1724,7 +1754,9 @@ gem 'other', version
dest = File.join @gemhome, 'gems', @spec.full_name
- @installer.unpack dest
+ Gem::Deprecate.skip_during do
+ @installer.unpack dest
+ end
assert_path_exists File.join dest, 'lib', 'code.rb'
assert_path_exists File.join dest, 'bin', 'executable'
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index a5ff929bd0..e21ece2f50 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -53,7 +53,6 @@ gems:
homepage: http://rake.rubyforge.org
description: Rake is a Make-like program implemented in Ruby. Tasks and dependencies are specified in standard Ruby syntax.
autorequire:
- default_executable: rake
bindir: bin
has_rdoc: true
required_ruby_version: !ruby/object:Gem::Version::Requirement
diff --git a/test/rubygems/test_gem_requirement.rb b/test/rubygems/test_gem_requirement.rb
index a93eea56b7..3db393e978 100644
--- a/test/rubygems/test_gem_requirement.rb
+++ b/test/rubygems/test_gem_requirement.rb
@@ -265,6 +265,12 @@ class TestGemRequirement < Gem::TestCase
assert_satisfied_by "3.0.rc2", "< 3.0.1"
assert_satisfied_by "3.0.rc2", "> 0"
+
+ assert_satisfied_by "5.0.0.rc2", "~> 5.a"
+ refute_satisfied_by "5.0.0.rc2", "~> 5.x"
+
+ assert_satisfied_by "5.0.0", "~> 5.a"
+ assert_satisfied_by "5.0.0", "~> 5.x"
end
def test_illformed_requirements
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index 126011be99..7440ca0191 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -22,9 +22,10 @@ class TestGemUninstaller < Gem::InstallerTestCase
end
def test_initialize_expand_path
- uninstaller = Gem::Uninstaller.new nil, :install_dir => '/foo//bar'
+ FileUtils.mkdir_p 'foo/bar'
+ uninstaller = Gem::Uninstaller.new nil, :install_dir => 'foo//bar'
- assert_match %r|/foo/bar$|, uninstaller.instance_variable_get(:@gem_home)
+ assert_match %r|foo/bar$|, uninstaller.instance_variable_get(:@gem_home)
end
def test_ask_if_ok
@@ -133,6 +134,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
end
def test_remove_not_in_home
+ Dir.mkdir "#{@gemhome}2"
uninstaller = Gem::Uninstaller.new nil, :install_dir => "#{@gemhome}2"
e = assert_raises Gem::GemNotInHomeException do
@@ -149,6 +151,22 @@ class TestGemUninstaller < Gem::InstallerTestCase
assert_path_exists @spec.gem_dir
end
+ def test_remove_symlinked_gem_home
+ Dir.mktmpdir("gem_home") do |dir|
+ symlinked_gem_home = "#{dir}/#{File.basename(@gemhome)}"
+
+ FileUtils.ln_s(@gemhome, dir)
+
+ uninstaller = Gem::Uninstaller.new nil, :install_dir => symlinked_gem_home
+
+ use_ui ui do
+ uninstaller.remove @spec
+ end
+
+ refute_path_exists @spec.gem_dir
+ end
+ end
+
def test_path_ok_eh
uninstaller = Gem::Uninstaller.new nil
@@ -313,6 +331,7 @@ create_makefile '#{@spec.name}'
end
def test_uninstall_wrong_repo
+ Dir.mkdir "#{@gemhome}2"
Gem.use_paths "#{@gemhome}2", [@gemhome]
uninstaller = Gem::Uninstaller.new @spec.name, :executables => true
diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb
index 6d3893c256..c90648f562 100644
--- a/test/rubygems/test_gem_version.rb
+++ b/test/rubygems/test_gem_version.rb
@@ -157,6 +157,13 @@ class TestGemVersion < Gem::TestCase
assert_equal(1, v("1.8.2.a10") <=> v("1.8.2.a9"))
assert_equal(0, v("") <=> v("0"))
+ assert_equal(0, v("0.beta.1") <=> v("0.0.beta.1"))
+ assert_equal(-1, v("0.0.beta") <=> v("0.0.beta.1"))
+ assert_equal(-1, v("0.0.beta") <=> v("0.beta.1"))
+
+ assert_equal(-1, v("5.a") <=> v("5.0.0.rc2"))
+ assert_equal(1, v("5.x") <=> v("5.0.0.rc2"))
+
assert_nil v("1.0") <=> "whatever"
end
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index 16159ef65e..678dde2cae 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -323,6 +323,19 @@ class TestGemRequire < Gem::TestCase
assert_equal %w(default-3.0), loaded_spec_names
end
+ 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)
+
+ 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)
+
+ assert_require "default/gem"
+ assert_equal %w(default-3.0.0.rc2), loaded_spec_names
+ end
+
def loaded_spec_names
Gem.loaded_specs.values.map(&:full_name).sort
end