summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/rubygems/test_gem.rb')
-rw-r--r--test/rubygems/test_gem.rb86
1 files changed, 72 insertions, 14 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 8b15debb49..2ec7044d7a 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -180,6 +180,35 @@ class TestGem < Gem::TestCase
assert_match 'a-2/bin/exec', Gem.bin_path('a', 'exec', '>= 0')
end
+ def test_activate_bin_path_resolves_eagerly
+ a1 = util_spec 'a', '1' do |s|
+ s.executables = ['exec']
+ s.add_dependency 'b'
+ end
+
+ b1 = util_spec 'b', '1' do |s|
+ s.add_dependency 'c', '2'
+ end
+
+ b2 = util_spec 'b', '2' do |s|
+ s.add_dependency 'c', '1'
+ end
+
+ c1 = util_spec 'c', '1'
+ c2 = util_spec 'c', '2'
+
+ install_specs c1, c2, b1, b2, a1
+
+ Gem.activate_bin_path("a", "exec", ">= 0")
+
+ # If we didn't eagerly resolve, this would activate c-2 and then the
+ # finish_resolve would cause a conflict
+ gem 'c'
+ Gem.finish_resolve
+
+ assert_equal %w(a-1 b-2 c-1), loaded_spec_names
+ end
+
def test_self_bin_path_no_exec_name
e = assert_raises ArgumentError do
Gem.bin_path 'a'
@@ -275,11 +304,13 @@ class TestGem < Gem::TestCase
expected = File.join @gemhome, 'gems', foo.full_name, 'data', 'foo'
- assert_equal expected, Gem.datadir('foo')
+ assert_equal expected, Gem::Specification.find_by_name("foo").datadir
end
def test_self_datadir_nonexistent_package
- assert_nil Gem.datadir('xyzzy')
+ assert_raises(Gem::MissingSpecError) do
+ Gem::Specification.find_by_name("xyzzy").datadir
+ end
end
def test_self_default_exec_format
@@ -368,7 +399,7 @@ class TestGem < Gem::TestCase
begin
Dir.chdir 'detect/a/b'
- assert_empty Gem.detect_gemdeps
+ assert_equal add_bundler_full_name([]), Gem.detect_gemdeps.map(&:full_name)
ensure
Dir.chdir @tempdir
end
@@ -1068,7 +1099,7 @@ class TestGem < Gem::TestCase
refute Gem.try_activate 'nonexistent'
end
- expected = "Ignoring ext-1 because its extensions are not built. " +
+ expected = "Ignoring ext-1 because its extensions are not built. " +
"Try: gem pristine ext --version 1\n"
assert_equal expected, err
@@ -1079,7 +1110,8 @@ class TestGem < Gem::TestCase
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
+ path = (Gem.default_path + [Gem.paths.home]).uniq
+ assert_equal path, Gem.paths.path
ensure
ENV['GEM_HOME'] = orig_home
ENV['GEM_PATH'] = orig_path
@@ -1420,7 +1452,7 @@ class TestGem < Gem::TestCase
Gem.detect_gemdeps
- assert_equal %w!a-1 b-1 c-1!, loaded_spec_names
+ assert_equal add_bundler_full_name(%W(a-1 b-1 c-1)), loaded_spec_names
end
def test_auto_activation_of_detected_gemdeps_file
@@ -1443,10 +1475,20 @@ class TestGem < Gem::TestCase
ENV['RUBYGEMS_GEMDEPS'] = "-"
- assert_equal [a,b,c], Gem.detect_gemdeps.sort_by { |s| s.name }
+ expected_specs = [a, b, (Gem::USE_BUNDLER_FOR_GEMDEPS || nil) && util_spec("bundler", Bundler::VERSION), c].compact
+ assert_equal expected_specs, Gem.detect_gemdeps.sort_by { |s| s.name }
end
LIB_PATH = File.expand_path "../../../lib".dup.untaint, __FILE__.dup.untaint
+ 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}"
+
+ def add_bundler_full_name(names)
+ return names unless Gem::USE_BUNDLER_FOR_GEMDEPS
+ names << BUNDLER_FULL_NAME
+ names.sort!
+ names
+ end
def test_looks_for_gemdeps_files_automatically_on_start
util_clear_gems
@@ -1466,7 +1508,8 @@ class TestGem < Gem::TestCase
ENV['RUBYGEMS_GEMDEPS'] = "-"
path = File.join @tempdir, "gem.deps.rb"
- cmd = [Gem.ruby.dup.untaint, "-I#{LIB_PATH.untaint}", "-rrubygems"]
+ cmd = [Gem.ruby.dup.untaint, "-I#{LIB_PATH.untaint}",
+ "-I#{BUNDLER_LIB_PATH.untaint}", "-rrubygems"]
if RUBY_VERSION < '1.9'
cmd << "-e 'puts Gem.loaded_specs.values.map(&:full_name).sort'"
cmd = cmd.join(' ')
@@ -1508,7 +1551,8 @@ class TestGem < Gem::TestCase
Dir.mkdir "sub1"
path = File.join @tempdir, "gem.deps.rb"
- cmd = [Gem.ruby.dup.untaint, "-Csub1", "-I#{LIB_PATH.untaint}", "-rrubygems"]
+ cmd = [Gem.ruby.dup.untaint, "-Csub1", "-I#{LIB_PATH.untaint}",
+ "-I#{BUNDLER_LIB_PATH.untaint}", "-rrubygems"]
if RUBY_VERSION < '1.9'
cmd << "-e 'puts Gem.loaded_specs.values.map(&:full_name).sort'"
cmd = cmd.join(' ')
@@ -1603,7 +1647,7 @@ class TestGem < Gem::TestCase
Gem.use_gemdeps gem_deps_file
- assert spec.activated?
+ assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names
refute_nil Gem.gemdeps
end
@@ -1664,7 +1708,7 @@ class TestGem < Gem::TestCase
Gem.use_gemdeps
- assert spec.activated?
+ assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names
ensure
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end
@@ -1706,11 +1750,25 @@ class TestGem < Gem::TestCase
io.write 'gem "a"'
end
- expected = <<-EXPECTED
+ platform = Bundler::GemHelpers.generic_local_platform
+ if platform == Gem::Platform::RUBY
+ platform = ''
+ 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)'
You may need to `gem install -g` to install missing gems
- EXPECTED
+ EXPECTED
+ end
assert_output nil, expected do
Gem.use_gemdeps
@@ -1735,7 +1793,7 @@ You may need to `gem install -g` to install missing gems
Gem.use_gemdeps
- assert spec.activated?
+ assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names
ensure
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end