[rubygems/rubygems] Put bundler gemspec stub at the right place

So that it's found when needed, rather than dynamically modifying
loaded stubs and thus messing with RubyGems internals.

cd3e7cb9e5
This commit is contained in:
David Rodríguez 2021-12-04 13:44:07 +01:00 committed by git
parent 668e78f01b
commit ac56e5c1ab

View file

@ -615,7 +615,7 @@ class TestGem < Gem::TestCase
end
def test_self_use_gemdeps
with_local_bundler do
with_local_bundler_at(Gem.dir) do
with_rubygems_gemdeps("-") do
FileUtils.mkdir_p "detect/a/b"
FileUtils.mkdir_p "detect/a/Isolate"
@ -775,7 +775,7 @@ class TestGem < Gem::TestCase
end
def test_self_find_files_with_gemfile
with_local_bundler do
with_local_bundler_at(Gem.dir) do
cwd = File.expand_path("test/rubygems", PROJECT_DIR)
actual_load_path = $LOAD_PATH.unshift(cwd).dup
@ -1635,7 +1635,7 @@ class TestGem < Gem::TestCase
end
def test_auto_activation_of_specific_gemdeps_file
with_local_bundler do
with_local_bundler_at(Gem.dir) do
a = util_spec "a", "1", nil, "lib/a.rb"
b = util_spec "b", "1", nil, "lib/b.rb"
c = util_spec "c", "1", nil, "lib/c.rb"
@ -1659,7 +1659,7 @@ class TestGem < Gem::TestCase
end
def test_auto_activation_of_used_gemdeps_file
with_local_bundler do
with_local_bundler_at(Gem.dir) do
a = util_spec "a", "1", nil, "lib/a.rb"
b = util_spec "b", "1", nil, "lib/b.rb"
c = util_spec "c", "1", nil, "lib/c.rb"
@ -1691,7 +1691,9 @@ class TestGem < Gem::TestCase
end
def test_looks_for_gemdeps_files_automatically_from_binstubs
with_local_bundler do
path = File.join(@tempdir, "gd-tmp")
with_local_bundler_at(path) do
a = util_spec "a", "1" do |s|
s.executables = %w[foo]
s.bindir = "exe"
@ -1706,7 +1708,6 @@ class TestGem < Gem::TestCase
install_specs a, b, c
path = File.join(@tempdir, "gd-tmp")
install_gem a, :install_dir => path
install_gem b, :install_dir => path
install_gem c, :install_dir => path
@ -1740,7 +1741,9 @@ class TestGem < Gem::TestCase
end
def test_looks_for_gemdeps_files_automatically_from_binstubs_in_parent_dir
with_local_bundler do
path = File.join(@tempdir, "gd-tmp")
with_local_bundler_at(path) do
pend "IO.popen has issues on JRuby when passed :chdir" if Gem.java_platform?
a = util_spec "a", "1" do |s|
@ -1757,7 +1760,6 @@ class TestGem < Gem::TestCase
install_specs a, b, c
path = File.join(@tempdir, "gd-tmp")
install_gem a, :install_dir => path
install_gem b, :install_dir => path
install_gem c, :install_dir => path
@ -1835,7 +1837,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps
with_local_bundler do
with_local_bundler_at(Gem.dir) do
gem_deps_file = "gem.deps.rb".tap(&Gem::UNTAINT)
spec = util_spec "a", 1
install_specs spec
@ -1857,7 +1859,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_ENV
with_local_bundler do
with_local_bundler_at(Gem.dir) do
with_rubygems_gemdeps(nil) do
spec = util_spec "a", 1
@ -1875,7 +1877,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_argument_missing
with_local_bundler do
with_local_bundler_at(Gem.dir) do
e = assert_raise ArgumentError do
Gem.use_gemdeps "gem.deps.rb"
end
@ -1886,7 +1888,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_argument_missing_match_ENV
with_local_bundler do
with_local_bundler_at(Gem.dir) do
with_rubygems_gemdeps("gem.deps.rb") do
e = assert_raise ArgumentError do
Gem.use_gemdeps "gem.deps.rb"
@ -1899,7 +1901,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_automatic
with_local_bundler do
with_local_bundler_at(Gem.dir) do
with_rubygems_gemdeps("-") do
spec = util_spec "a", 1
install_specs spec
@ -1919,7 +1921,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_automatic_missing
with_local_bundler do
with_local_bundler_at(Gem.dir) do
with_rubygems_gemdeps("-") do
Gem.use_gemdeps
@ -1929,7 +1931,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_disabled
with_local_bundler do
with_local_bundler_at(Gem.dir) do
with_rubygems_gemdeps("") do
spec = util_spec "a", 1
@ -1947,7 +1949,7 @@ class TestGem < Gem::TestCase
end
def test_use_gemdeps_missing_gem
with_local_bundler do
with_local_bundler_at(Gem.dir) do
with_rubygems_gemdeps("x") do
File.open "x", "w" do |io|
io.write 'gem "a"'
@ -1971,7 +1973,7 @@ You may need to `bundle install` to install missing gems
end
def test_use_gemdeps_specific
with_local_bundler do
with_local_bundler_at(Gem.dir) do
with_rubygems_gemdeps("x") do
spec = util_spec "a", 1
install_specs spec
@ -2121,17 +2123,18 @@ You may need to `bundle install` to install missing gems
ENV["RUBYGEMS_GEMDEPS"] = rubygems_gemdeps
end
def with_local_bundler
# If bundler gemspec exists, add to stubs
def with_local_bundler_at(path)
require "bundler"
# If bundler gemspec exists, pretend it's installed
bundler_gemspec = File.expand_path("../../bundler/bundler.gemspec", __dir__)
if File.exist?(bundler_gemspec)
Gem::Specification.dirs.unshift File.dirname(bundler_gemspec)
Gem::Specification.class_variable_set :@@stubs, nil
Gem::Specification.stubs
Gem::Specification.dirs.shift
end
target_gemspec_location = "#{path}/specifications/bundler-#{Bundler::VERSION}.gemspec"
require "bundler"
FileUtils.mkdir_p File.dirname(target_gemspec_location)
File.write target_gemspec_location, Gem::Specification.load(bundler_gemspec).to_ruby_for_cache
end
yield
ensure