aboutsummaryrefslogtreecommitdiffstats
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.rb90
1 files changed, 79 insertions, 11 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 90695b56d7..b9c0337c0a 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -157,6 +157,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'
@@ -345,7 +374,7 @@ class TestGem < Gem::TestCase
begin
Dir.chdir 'detect/a/b'
- assert_empty Gem.detect_gemdeps
+ assert_equal [BUNDLER_FULL_NAME], Gem.detect_gemdeps.map(&:full_name)
ensure
Dir.chdir @tempdir
end
@@ -961,6 +990,9 @@ class TestGem < Gem::TestCase
def test_self_sources
assert_equal %w[http://gems.example.com/], Gem.sources
+ Gem.sources = nil
+ Gem.configuration.sources = %w[http://test.example.com/]
+ assert_equal %w[http://test.example.com/], Gem.sources
end
def test_try_activate_returns_true_for_activated_specs
@@ -1394,7 +1426,7 @@ class TestGem < Gem::TestCase
Gem.detect_gemdeps
- assert_equal %w!a-1 b-1 c-1!, loaded_spec_names
+ assert_equal %W(a-1 b-1 #{BUNDLER_FULL_NAME} c-1), loaded_spec_names
end
def test_auto_activation_of_detected_gemdeps_file
@@ -1417,10 +1449,40 @@ class TestGem < Gem::TestCase
ENV['RUBYGEMS_GEMDEPS'] = "-"
- assert_equal [a,b,c], Gem.detect_gemdeps.sort_by { |s| s.name }
+ assert_equal [a, b, util_spec("bundler", Bundler::VERSION), c], 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 test_use_gemdeps_uses_bundler_postit_trampoline
+ refute_includes $LOADED_FEATURES, File.join(BUNDLER_LIB_PATH, "bundler/postit_trampoline.rb".dup.untaint)
+ ENV.delete("BUNDLE_DISABLE_POSTIT")
+
+ a = new_spec "a", "1", nil, "lib/a.rb"
+ b = new_spec "b", "1", nil, "lib/b.rb"
+ c = new_spec "c", "1", nil, "lib/c.rb"
+
+ install_specs a, b, c
+
+ path = File.join @tempdir, "gem.deps.rb"
+
+ File.open path, "w" do |f|
+ f.puts "gem 'a'"
+ f.puts "gem 'b'"
+ f.puts "gem 'c'"
+ end
+
+ ENV['RUBYGEMS_GEMDEPS'] = path
+
+ Gem.detect_gemdeps
+
+ assert_equal %W(a-1 b-1 #{BUNDLER_FULL_NAME} c-1), loaded_spec_names
+
+ trampoline_path = RUBY_VERSION > "1.9" ? File.join(BUNDLER_LIB_PATH, "bundler/postit_trampoline.rb".dup.untaint) : "bundler/postit_trampoline.rb"
+ assert_includes $LOADED_FEATURES, trampoline_path
+ end
def test_looks_for_gemdeps_files_automatically_on_start
util_clear_gems
@@ -1447,9 +1509,9 @@ class TestGem < Gem::TestCase
ENV['GEM_PATH'] = path
ENV['RUBYGEMS_GEMDEPS'] = "-"
- out = `#{Gem.ruby.dup.untaint} -I "#{LIB_PATH.untaint}" -rubygems -e "p Gem.loaded_specs.values.map(&:full_name).sort"`
+ out = `#{Gem.ruby.dup.untaint} -I "#{LIB_PATH.untaint}" -I "#{BUNDLER_LIB_PATH.untaint}" -rubygems -e "p Gem.loaded_specs.values.map(&:full_name).sort"`
- assert_equal '["a-1", "b-1", "c-1"]', out.strip
+ assert_equal %W(a-1 b-1 #{BUNDLER_FULL_NAME} c-1).inspect, out.strip
end
def test_looks_for_gemdeps_files_automatically_on_start_in_parent_dir
@@ -1479,12 +1541,12 @@ class TestGem < Gem::TestCase
Dir.mkdir "sub1"
out = Dir.chdir "sub1" do
- `#{Gem.ruby.dup.untaint} -I "#{LIB_PATH.untaint}" -rubygems -e "p Gem.loaded_specs.values.map(&:full_name).sort"`
+ `#{Gem.ruby.dup.untaint} -I "#{LIB_PATH.untaint}" -I "#{BUNDLER_LIB_PATH.untaint}" -rubygems -e "p Gem.loaded_specs.values.map(&:full_name).sort"`
end
Dir.rmdir "sub1"
- assert_equal '["a-1", "b-1", "c-1"]', out.strip
+ assert_equal %W(a-1 b-1 #{BUNDLER_FULL_NAME} c-1).inspect, out.strip
end
def test_register_default_spec
@@ -1558,7 +1620,7 @@ class TestGem < Gem::TestCase
Gem.use_gemdeps gem_deps_file
- assert spec.activated?
+ assert_equal %W(a-1 #{BUNDLER_FULL_NAME}), loaded_spec_names
refute_nil Gem.gemdeps
end
@@ -1619,7 +1681,7 @@ class TestGem < Gem::TestCase
Gem.use_gemdeps
- assert spec.activated?
+ assert_equal %W(a-1 #{BUNDLER_FULL_NAME}), loaded_spec_names
ensure
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end
@@ -1661,8 +1723,14 @@ class TestGem < Gem::TestCase
io.write 'gem "a"'
end
+ platform = Bundler::GemHelpers.generic_local_platform
+ if platform == Gem::Platform::RUBY
+ platform = ''
+ else
+ platform = " #{platform}"
+ end
expected = <<-EXPECTED
-Unable to resolve dependency: user requested 'a (>= 0)'
+Could not find gem 'a#{platform}' in any of the gem sources listed in your Gemfile or available on this machine.
You may need to `gem install -g` to install missing gems
EXPECTED
@@ -1690,7 +1758,7 @@ You may need to `gem install -g` to install missing gems
Gem.use_gemdeps
- assert spec.activated?
+ assert_equal %W(a-1 #{BUNDLER_FULL_NAME}), loaded_spec_names
ensure
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end