aboutsummaryrefslogtreecommitdiffstats
path: root/test/rubygems
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-04 00:29:40 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-04 00:29:40 +0000
commit5a90f9e8f84533e7859232895fc4bbe6b31cc771 (patch)
treee15086587f691a1f5bd3c7ddbfa38e825828caf6 /test/rubygems
parentf1321bd6e7c2d6b6a29a67074bad6f2742263921 (diff)
downloadruby-5a90f9e8f84533e7859232895fc4bbe6b31cc771.tar.gz
* lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update rubygems-2.6.1.
Please see entries of 2.6.0 and 2.6.1 on https://github.com/rubygems/rubygems/blob/master/History.txt [fix GH-1270] Patch by @segiddins git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/test_gem.rb98
-rw-r--r--test/rubygems/test_gem_command.rb4
-rw-r--r--test/rubygems/test_gem_commands_cleanup_command.rb30
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb20
-rw-r--r--test/rubygems/test_gem_commands_open_command.rb19
-rw-r--r--test/rubygems/test_gem_commands_push_command.rb58
-rw-r--r--test/rubygems/test_gem_ext_cmake_builder.rb4
-rw-r--r--test/rubygems/test_gem_gemcutter_utilities.rb4
-rw-r--r--test/rubygems/test_gem_path_support.rb48
-rw-r--r--test/rubygems/test_gem_source_list.rb6
-rw-r--r--test/rubygems/test_gem_version.rb8
11 files changed, 279 insertions, 20 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index aec9d98c9a..aa57261d5e 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -473,6 +473,45 @@ class TestGem < Gem::TestCase
assert_equal cwd, $LOAD_PATH.shift
end
+ def test_self_find_files_with_gemfile
+ # write_file(File.join Dir.pwd, 'Gemfile') fails on travis 1.8.7 with $SAFE=1
+ skip if RUBY_VERSION <= "1.8.7"
+
+ cwd = File.expand_path("test/rubygems", @@project_dir)
+ $LOAD_PATH.unshift cwd
+
+ discover_path = File.join 'lib', 'sff', 'discover.rb'
+
+ foo1, _ = %w(1 2).map { |version|
+ spec = quick_gem 'sff', version do |s|
+ s.files << discover_path
+ end
+
+ write_file(File.join 'gems', spec.full_name, discover_path) do |fp|
+ fp.puts "# #{spec.full_name}"
+ end
+
+ spec
+ }
+ Gem.refresh
+
+ write_file(File.join Dir.pwd, 'Gemfile') do |fp|
+ fp.puts "source 'https://rubygems.org'"
+ fp.puts "gem '#{foo1.name}', '#{foo1.version}'"
+ end
+ Gem.use_gemdeps(File.join Dir.pwd, 'Gemfile')
+
+ expected = [
+ File.expand_path('test/rubygems/sff/discover.rb', @@project_dir),
+ File.join(foo1.full_gem_path, discover_path)
+ ]
+
+ assert_equal expected, Gem.find_files('sff/discover')
+ assert_equal expected, Gem.find_files('sff/**.rb'), '[ruby-core:31730]'
+ ensure
+ assert_equal cwd, $LOAD_PATH.shift unless RUBY_VERSION <= "1.8.7"
+ end
+
def test_self_find_latest_files
cwd = File.expand_path("test/rubygems", @@project_dir)
$LOAD_PATH.unshift cwd
@@ -929,6 +968,26 @@ class TestGem < Gem::TestCase
assert_match %r%Could not find 'b' %, e.message
end
+ def test_self_try_activate_missing_prerelease
+ b = util_spec 'b', '1.0rc1'
+ a = util_spec 'a', '1.0rc1', 'b' => '1.0rc1'
+
+ install_specs b, a
+ uninstall_gem b
+
+ a_file = File.join a.gem_dir, 'lib', 'a_file.rb'
+
+ write_file a_file do |io|
+ io.puts '# a_file.rb'
+ end
+
+ e = assert_raises Gem::LoadError do
+ Gem.try_activate 'a_file'
+ end
+
+ assert_match %r%Could not find 'b' \(= 1.0rc1\)%, e.message
+ end
+
def test_self_try_activate_missing_extensions
spec = util_spec 'ext', '1' do |s|
s.extensions = %w[ext/extconf.rb]
@@ -951,6 +1010,45 @@ class TestGem < Gem::TestCase
assert_equal expected, err
end
+ def test_self_use_paths_with_nils
+ orig_home = ENV.delete 'GEM_HOME'
+ orig_path = ENV.delete 'GEM_PATH'
+ Gem.use_paths nil, nil
+ assert_equal Gem.default_dir, Gem.paths.home
+ assert_equal (Gem.default_path + [Gem.paths.home]).uniq, Gem.paths.path
+ ensure
+ ENV['GEM_HOME'] = orig_home
+ ENV['GEM_PATH'] = orig_path
+ end
+
+ def test_setting_paths_does_not_warn_about_unknown_keys
+ stdout, stderr = capture_io do
+ Gem.paths = { 'foo' => [],
+ 'bar' => Object.new,
+ 'GEM_HOME' => Gem.paths.home,
+ 'GEM_PATH' => 'foo' }
+ end
+ assert_equal ['foo', Gem.paths.home], Gem.paths.path
+ assert_equal '', stderr
+ assert_equal '', stdout
+ end
+
+ def test_setting_paths_does_not_mutate_parameter_object
+ Gem.paths = { 'GEM_HOME' => Gem.paths.home,
+ 'GEM_PATH' => 'foo' }.freeze
+ assert_equal ['foo', Gem.paths.home], Gem.paths.path
+ end
+
+ def test_deprecated_paths=
+ stdout, stderr = capture_io do
+ Gem.paths = { 'GEM_HOME' => Gem.paths.home,
+ 'GEM_PATH' => [Gem.paths.home, 'foo'] }
+ end
+ assert_equal [Gem.paths.home, 'foo'], Gem.paths.path
+ assert_match(/Array values in the parameter are deprecated. Please use a String or nil/, stderr)
+ assert_equal '', stdout
+ end
+
def test_self_use_paths
util_ensure_gem_dirs
diff --git a/test/rubygems/test_gem_command.rb b/test/rubygems/test_gem_command.rb
index 61b73874fd..8100a34c25 100644
--- a/test/rubygems/test_gem_command.rb
+++ b/test/rubygems/test_gem_command.rb
@@ -170,12 +170,16 @@ class TestGemCommand < Gem::TestCase
@cmd.add_option('-f', '--file FILE', 'File option') do |value, options|
options[:help] = true
end
+ @cmd.add_option('--silent', 'Silence rubygems output') do |value, options|
+ options[:silent] = true
+ end
assert @cmd.handles?(['-x'])
assert @cmd.handles?(['-h'])
assert @cmd.handles?(['-h', 'command'])
assert @cmd.handles?(['--help', 'command'])
assert @cmd.handles?(['-f', 'filename'])
assert @cmd.handles?(['--file=filename'])
+ assert @cmd.handles?(['--silent'])
refute @cmd.handles?(['-z'])
refute @cmd.handles?(['-f'])
refute @cmd.handles?(['--toothpaste'])
diff --git a/test/rubygems/test_gem_commands_cleanup_command.rb b/test/rubygems/test_gem_commands_cleanup_command.rb
index f988f81e55..8354160dbf 100644
--- a/test/rubygems/test_gem_commands_cleanup_command.rb
+++ b/test/rubygems/test_gem_commands_cleanup_command.rb
@@ -112,7 +112,7 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
@cmd.execute
assert_path_exists @a_1.gem_dir
- refute_path_exists @a_1_1.gem_dir
+ assert_path_exists @a_1_1.gem_dir
ensure
FileUtils.chmod 0755, @gemhome
end unless win_platform?
@@ -165,5 +165,33 @@ class TestGemCommandsCleanupCommand < Gem::TestCase
assert_match %r%^Skipped default gems: b-2%, @ui.output
assert_empty @ui.error
end
+
+ def test_execute_remove_gem_home_only
+ c_1, = util_gem 'c', '1'
+ c_2, = util_gem 'c', '2'
+ d_1, = util_gem 'd', '1'
+ d_2, = util_gem 'd', '2'
+ e_1, = util_gem 'e', '1'
+ e_2, = util_gem 'e', '2'
+
+ c_1 = install_gem c_1, :user_install => true # pick up user install path
+ c_2 = install_gem c_2
+
+ d_1 = install_gem d_1
+ d_2 = install_gem d_2, :user_install => true # pick up user install path
+
+ e_1 = install_gem e_1
+ e_2 = install_gem e_2
+
+ Gem::Specification.dirs = [Gem.dir, Gem.user_dir]
+
+ @cmd.options[:args] = []
+
+ @cmd.execute
+
+ assert_path_exists c_1.gem_dir
+ refute_path_exists d_1.gem_dir
+ refute_path_exists e_1.gem_dir
+ end
end
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index 2525f26789..13b9a7bbad 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -438,6 +438,26 @@ ERROR: Possible alternatives: non_existent_with_hint
assert_match "1 gem installed", @ui.output
end
+ def test_execute_with_invalid_gem_file
+ FileUtils.touch("a.gem")
+
+ spec_fetcher do |fetcher|
+ fetcher.gem 'a', 2
+ end
+
+ @cmd.options[:args] = %w[a]
+
+ use_ui @ui do
+ assert_raises Gem::MockGemUi::SystemExitException, @ui.error do
+ @cmd.execute
+ end
+ end
+
+ assert_equal %w[a-2], @cmd.installed_specs.map { |spec| spec.full_name }
+
+ assert_match "1 gem installed", @ui.output
+ end
+
def test_execute_remote_ignores_files
specs = spec_fetcher do |fetcher|
fetcher.gem 'a', 1
diff --git a/test/rubygems/test_gem_commands_open_command.rb b/test/rubygems/test_gem_commands_open_command.rb
index e6cbb43355..3ec38972e6 100644
--- a/test/rubygems/test_gem_commands_open_command.rb
+++ b/test/rubygems/test_gem_commands_open_command.rb
@@ -10,9 +10,10 @@ class TestGemCommandsOpenCommand < Gem::TestCase
@cmd = Gem::Commands::OpenCommand.new
end
- def gem name
+ def gem(name, version = "1.0")
spec = quick_gem name do |gem|
gem.files = %W[lib/#{name}.rb Rakefile]
+ gem.version = version
end
write_file File.join(*%W[gems #{spec.full_name} lib #{name}.rb])
write_file File.join(*%W[gems #{spec.full_name} Rakefile])
@@ -37,6 +38,22 @@ class TestGemCommandsOpenCommand < Gem::TestCase
assert_equal "", @ui.error
end
+ def test_wrong_version
+ @cmd.options[:version] = "4.0"
+ @cmd.options[:args] = %w[foo]
+
+ gem "foo", "5.0"
+
+ assert_raises Gem::MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_match %r|Unable to find gem 'foo'|, @ui.output
+ assert_equal "", @ui.error
+ end
+
def test_execute_bad_gem
@cmd.options[:args] = %w[foo]
diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb
index 729de46f9d..b888a741f0 100644
--- a/test/rubygems/test_gem_commands_push_command.rb
+++ b/test/rubygems/test_gem_commands_push_command.rb
@@ -118,7 +118,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
end
def test_sending_gem_to_metadata_host
- @host = "http://rubygems.engineyard.com"
+ @host = "http://privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
spec.metadata['default_gem_server'] = @host
@@ -152,7 +152,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
end
def test_sending_gem_to_allowed_push_host
- @host = "http://privategemserver.com"
+ @host = "http://privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
spec.metadata['allowed_push_host'] = @host
@@ -179,8 +179,8 @@ class TestGemCommandsPushCommand < Gem::TestCase
end
def test_sending_gem_to_allowed_push_host_with_basic_credentials
- @sanitized_host = "http://privategemserver.com"
- @host = "http://user:password@privategemserver.com"
+ @sanitized_host = "http://privategemserver.example"
+ @host = "http://user:password@privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
spec.metadata['allowed_push_host'] = @sanitized_host
@@ -207,10 +207,10 @@ class TestGemCommandsPushCommand < Gem::TestCase
def test_sending_gem_to_disallowed_default_host
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata['allowed_push_host'] = "https://privategemserver.com"
+ spec.metadata['allowed_push_host'] = "https://privategemserver.example"
end
- response = %{ERROR: "#{@host}" is not allowed by the gemspec, which only allows "https://privategemserver.com"}
+ response = %{ERROR: "#{@host}" is not allowed by the gemspec, which only allows "https://privategemserver.example"}
assert_raises Gem::MockGemUi::TermError do
send_battery
@@ -220,10 +220,11 @@ class TestGemCommandsPushCommand < Gem::TestCase
end
def test_sending_gem_to_disallowed_push_host
- @host = "https://somebodyelse.com"
+ @host = "https://anotherprivategemserver.example"
+ push_host = "https://privategemserver.example"
@spec, @path = util_gem "freebird", "1.0.1" do |spec|
- spec.metadata['allowed_push_host'] = "https://privategemserver.com"
+ spec.metadata['allowed_push_host'] = push_host
end
@api_key = "PRIVKEY"
@@ -241,7 +242,7 @@ class TestGemCommandsPushCommand < Gem::TestCase
FileUtils.rm Gem.configuration.credentials_path
- response = 'ERROR: "https://somebodyelse.com" is not allowed by the gemspec, which only allows "https://privategemserver.com"'
+ response = "ERROR: \"#{@host}\" is not allowed by the gemspec, which only allows \"#{push_host}\""
assert_raises Gem::MockGemUi::TermError do
send_battery
@@ -250,6 +251,45 @@ class TestGemCommandsPushCommand < Gem::TestCase
assert_match response, @ui.error
end
+ def test_sending_gem_defaulting_to_allowed_push_host
+ host = "http://privategemserver.example"
+
+ @spec, @path = util_gem "freebird", "1.0.1" do |spec|
+ spec.metadata.delete('default_gem_server')
+ spec.metadata['allowed_push_host'] = host
+ end
+
+ api_key = "PRIVKEY"
+
+ keys = {
+ host => api_key
+ }
+
+ FileUtils.mkdir_p File.dirname Gem.configuration.credentials_path
+ open Gem.configuration.credentials_path, 'w' do |f|
+ f.write keys.to_yaml
+ end
+ Gem.configuration.load_api_keys
+
+ FileUtils.rm Gem.configuration.credentials_path
+
+ @response = "Successfully registered gem: freebird (1.0.1)"
+ @fetcher.data["#{host}/api/v1/gems"] = [@response, 200, 'OK']
+
+ # do not set @host
+ use_ui(@ui) { @cmd.send_gem(@path) }
+
+ assert_match %r{Pushing gem to #{host}...}, @ui.output
+
+ assert_equal Net::HTTP::Post, @fetcher.last_request.class
+ assert_equal Gem.read_binary(@path), @fetcher.last_request.body
+ assert_equal File.size(@path), @fetcher.last_request["Content-Length"].to_i
+ assert_equal "application/octet-stream", @fetcher.last_request["Content-Type"]
+ assert_equal api_key, @fetcher.last_request["Authorization"]
+
+ assert_match @response, @ui.output
+ end
+
def test_raises_error_with_no_arguments
def @cmd.sign_in(*); end
assert_raises Gem::CommandLineError do
diff --git a/test/rubygems/test_gem_ext_cmake_builder.rb b/test/rubygems/test_gem_ext_cmake_builder.rb
index b54399ad3d..2093c7da55 100644
--- a/test/rubygems/test_gem_ext_cmake_builder.rb
+++ b/test/rubygems/test_gem_ext_cmake_builder.rb
@@ -7,6 +7,9 @@ class TestGemExtCmakeBuilder < Gem::TestCase
def setup
super
+ # Details: https://github.com/rubygems/rubygems/issues/1270#issuecomment-177368340
+ skip "CmakeBuilder doesn't work on Windows." if Gem.win_platform?
+
`cmake #{Gem::Ext::Builder.redirector}`
skip 'cmake not present' unless $?.success?
@@ -82,4 +85,3 @@ install (FILES test.txt DESTINATION bin)
end
end
-
diff --git a/test/rubygems/test_gem_gemcutter_utilities.rb b/test/rubygems/test_gem_gemcutter_utilities.rb
index bd84d4b25a..c3f9a7ea18 100644
--- a/test/rubygems/test_gem_gemcutter_utilities.rb
+++ b/test/rubygems/test_gem_gemcutter_utilities.rb
@@ -110,7 +110,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
assert_match %r{Signed in.}, @sign_in_ui.output
credentials = YAML.load_file Gem.configuration.credentials_path
- assert_equal api_key, credentials[:rubygems_api_key]
+ assert_equal api_key, credentials['http://example.com']
end
def test_sign_in_with_host_nil
@@ -137,7 +137,7 @@ class TestGemGemcutterUtilities < Gem::TestCase
assert_match %r{Signed in.}, @sign_in_ui.output
credentials = YAML.load_file Gem.configuration.credentials_path
- assert_equal api_key, credentials[:rubygems_api_key]
+ assert_equal api_key, credentials['http://example.com']
end
def test_sign_in_skips_with_existing_credentials
diff --git a/test/rubygems/test_gem_path_support.rb b/test/rubygems/test_gem_path_support.rb
index a4be66fe61..754c43e893 100644
--- a/test/rubygems/test_gem_path_support.rb
+++ b/test/rubygems/test_gem_path_support.rb
@@ -12,7 +12,7 @@ class TestGemPathSupport < Gem::TestCase
end
def test_initialize
- ps = Gem::PathSupport.new
+ ps = Gem::PathSupport.new ENV
assert_equal ENV["GEM_HOME"], ps.home
@@ -21,7 +21,7 @@ class TestGemPathSupport < Gem::TestCase
end
def test_initialize_home
- ps = Gem::PathSupport.new "GEM_HOME" => "#{@tempdir}/foo"
+ ps = Gem::PathSupport.new ENV.to_hash.merge("GEM_HOME" => "#{@tempdir}/foo")
assert_equal File.join(@tempdir, "foo"), ps.home
@@ -39,7 +39,7 @@ class TestGemPathSupport < Gem::TestCase
end
def test_initialize_path
- ps = Gem::PathSupport.new "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar]
+ ps = Gem::PathSupport.new ENV.to_hash.merge("GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator))
assert_equal ENV["GEM_HOME"], ps.home
@@ -52,9 +52,45 @@ class TestGemPathSupport < Gem::TestCase
assert_equal expected, ps.path
end
+ def test_initialize_regexp_path_separator
+ Gem.stub(:path_separator, /#{File::PATH_SEPARATOR}/) do
+ path = %W[#{@tempdir}/foo
+ #{File::PATH_SEPARATOR}
+ #{@tempdir}/bar
+ #{File::PATH_SEPARATOR}].join
+ ps = Gem::PathSupport.new "GEM_PATH" => path, "GEM_HOME" => ENV["GEM_HOME"]
+
+ assert_equal ENV["GEM_HOME"], ps.home
+
+ expected = [
+ File.join(@tempdir, 'foo'),
+ File.join(@tempdir, 'bar'),
+ ] + Gem.default_path << ENV["GEM_HOME"]
+
+ assert_equal expected, ps.path
+ end
+ end
+
+ def test_initialize_path_with_defaults
+ path = %W[#{@tempdir}/foo
+ #{File::PATH_SEPARATOR}
+ #{@tempdir}/bar
+ #{File::PATH_SEPARATOR}].join
+ ps = Gem::PathSupport.new "GEM_PATH" => path, "GEM_HOME" => ENV["GEM_HOME"]
+
+ assert_equal ENV["GEM_HOME"], ps.home
+
+ expected = [
+ File.join(@tempdir, 'foo'),
+ File.join(@tempdir, 'bar'),
+ ] + Gem.default_path << ENV["GEM_HOME"]
+
+ assert_equal expected, ps.path
+ end
+
def test_initialize_home_path
ps = Gem::PathSupport.new("GEM_HOME" => "#{@tempdir}/foo",
- "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar])
+ "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar].join(Gem.path_separator))
assert_equal File.join(@tempdir, "foo"), ps.home
@@ -69,12 +105,12 @@ class TestGemPathSupport < Gem::TestCase
def test_initialize_spec
ENV["GEM_SPEC_CACHE"] = nil
- ps = Gem::PathSupport.new
+ ps = Gem::PathSupport.new ENV
assert_equal Gem.default_spec_cache_dir, ps.spec_cache_dir
ENV["GEM_SPEC_CACHE"] = 'bar'
- ps = Gem::PathSupport.new
+ ps = Gem::PathSupport.new ENV
assert_equal ENV["GEM_SPEC_CACHE"], ps.spec_cache_dir
ENV["GEM_SPEC_CACHE"] = File.join @tempdir, 'spec_cache'
diff --git a/test/rubygems/test_gem_source_list.rb b/test/rubygems/test_gem_source_list.rb
index 15aff9c9b4..c93e0a8697 100644
--- a/test/rubygems/test_gem_source_list.rb
+++ b/test/rubygems/test_gem_source_list.rb
@@ -25,6 +25,12 @@ class TestGemSourceList < Gem::TestCase
def test_append
sl = Gem::SourceList.new
+ sl << @uri
+ sl << @uri
+
+ assert_equal sl.to_a.size, 1
+
+ sl.clear
source = (sl << @uri)
assert_kind_of Gem::Source, source
diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb
index 53e2020aba..9898669ce6 100644
--- a/test/rubygems/test_gem_version.rb
+++ b/test/rubygems/test_gem_version.rb
@@ -146,6 +146,14 @@ class TestGemVersion < Gem::TestCase
assert_less_than "1.0.0-1", "1"
end
+ # modifying the segments of a version should not affect the segments of the cached version object
+ def test_segments
+ v('9.8.7').segments[2] += 1
+
+ refute_version_equal "9.8.8", "9.8.7"
+ assert_equal [9,8,7], v("9.8.7").segments
+ end
+
# Asserts that +version+ is a prerelease.
def assert_prerelease version