[rubygems/rubygems] Build bundler gem just once for specs

When we need to reset system gems during specs, there's no need to
rebuild bundler, we can copy over the original gem home.

7b4f80747b
This commit is contained in:
David Rodríguez 2025-07-23 20:09:47 +02:00 committed by Hiroshi SHIBATA
parent 63c4223775
commit e67f595e8f
11 changed files with 43 additions and 34 deletions

View file

@ -291,7 +291,7 @@ RSpec.describe "bundle cache" do
expect(cached_gem("platform_specific-1.0-java")).to exist
end
pristine_system_gems :bundler
pristine_system_gems
simulate_platform "x86-darwin-100" do
install_gemfile <<-G
@ -313,7 +313,7 @@ RSpec.describe "bundle cache" do
rubygems_version: "1.3.2"
FileUtils.rm_r default_bundle_path
system_gems :bundler
default_system_gems
FileUtils.rm bundled_app_lock
bundle :install, raise_on_error: false
@ -346,7 +346,7 @@ RSpec.describe "bundle cache" do
end
FileUtils.rm_r default_bundle_path
system_gems :bundler
default_system_gems
lockfile <<-L
GEM
@ -371,7 +371,7 @@ RSpec.describe "bundle cache" do
setup_main_repo
cached_gem("myrack-1.0.0").rmtree
build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache")
pristine_system_gems :bundler
pristine_system_gems
lockfile <<-L
GEM

View file

@ -164,7 +164,7 @@ RSpec.describe "bundle cache with git" do
bundle "config set path vendor/bundle"
bundle :install
pristine_system_gems :bundler
pristine_system_gems
with_path_as "" do
bundle "config set deployment true"
bundle "install --local"
@ -182,7 +182,7 @@ RSpec.describe "bundle cache with git" do
bundle "config set cache_all true"
bundle :cache, "all-platforms" => true
pristine_system_gems :bundler
pristine_system_gems
bundle "config set frozen true"
bundle "install --local --verbose"
expect(out).to_not include("Fetching")
@ -199,7 +199,7 @@ RSpec.describe "bundle cache with git" do
bundle "config set cache_all true"
bundle :cache, "all-platforms" => true
pristine_system_gems :bundler
pristine_system_gems
bundle "config set frozen true"
bundle "install --local --verbose"
expect(out).to_not include("Fetching")
@ -216,7 +216,7 @@ RSpec.describe "bundle cache with git" do
bundle "config set cache_all true"
bundle :cache, "all-platforms" => true
pristine_system_gems :bundler
pristine_system_gems
bundle "config set frozen true"
# Remove untracked files (including the empty refs dir in the cache)
@ -380,7 +380,7 @@ RSpec.describe "bundle cache with git" do
bundle "config set cache_all true"
bundle :cache, "all-platforms" => true, :install => false
pristine_system_gems :bundler
pristine_system_gems
with_path_as "" do
bundle "config set deployment true"
bundle :install, local: true

View file

@ -356,7 +356,7 @@ RSpec.describe "bundle install with gem sources" do
G
bundle :cache
pristine_system_gems :bundler
pristine_system_gems
FileUtils.rm_r gem_repo2
bundle "install --local"
@ -371,7 +371,7 @@ RSpec.describe "bundle install with gem sources" do
G
bundle :cache
pristine_system_gems :bundler
pristine_system_gems
FileUtils.rm_r gem_repo2
bundle "config set --local deployment true"
@ -388,7 +388,7 @@ RSpec.describe "bundle install with gem sources" do
G
bundle :cache
pristine_system_gems :bundler
pristine_system_gems
FileUtils.rm_r gem_repo2
bundle "config set --local cache_all_platforms true"
@ -482,7 +482,7 @@ RSpec.describe "bundle install with gem sources" do
bundle :cache
end
pristine_system_gems :bundler
pristine_system_gems
bundle "config set --local force_ruby_platform true"

View file

@ -329,7 +329,7 @@ RSpec.describe "bundle check" do
it "shows what is missing with the current Gemfile if it is not satisfied" do
FileUtils.rm_r default_bundle_path
system_gems :bundler
default_system_gems
bundle :check, raise_on_error: false
expect(err).to match(/The following gems are missing/)
expect(err).to include("* myrack (1.0")

View file

@ -974,7 +974,7 @@ RSpec.describe "bundle outdated" do
gem "terranova", '8'
G
pristine_system_gems :bundler
pristine_system_gems
update_git "foo", path: lib_path("foo")
update_repo2 do

View file

@ -88,7 +88,7 @@ RSpec.describe "install in deployment or frozen mode" do
it "still works if you are not in the app directory and specify --gemfile" do
bundle "install"
pristine_system_gems :bundler
pristine_system_gems
bundle "config set --local deployment true"
bundle "config set --local path vendor/bundle"
bundle "install --gemfile #{tmp}/bundled_app/Gemfile", dir: tmp
@ -547,7 +547,7 @@ RSpec.describe "install in deployment or frozen mode" do
bundle "install --local"
expect(out).to include("Updating files in vendor/cache")
pristine_system_gems :bundler
pristine_system_gems
bundle "config set --local deployment true"
bundle "install --verbose"
expect(out).not_to include("can't be updated because frozen mode is set")

View file

@ -37,7 +37,7 @@ RSpec.describe "bundle install with git sources" do
end
it "caches the git repo globally and properly uses the cached repo on the next invocation" do
pristine_system_gems :bundler
pristine_system_gems
bundle "config set global_gem_cache true"
bundle :install
expect(Dir["#{home}/.bundle/cache/git/foo-1.0-*"]).to have_attributes size: 1
@ -1241,7 +1241,7 @@ RSpec.describe "bundle install with git sources" do
gem "valim", "= 1.0", :git => "#{lib_path("valim")}"
G
pristine_system_gems :bundler
pristine_system_gems
bundle "config set --local deployment true"
bundle :install
@ -1628,7 +1628,7 @@ In Gemfile:
G
bundle "config set --global path vendor/bundle"
bundle :install
pristine_system_gems :bundler
pristine_system_gems
bundle "install", env: { "PATH" => "" }
expect(out).to_not include("You need to install git to be able to use gems from git repositories.")

View file

@ -161,7 +161,7 @@ RSpec.describe "bundle install across platforms" do
expect(the_bundle).to include_gems "nokogiri 1.4.2 java", "weakling 0.0.3"
pristine_system_gems :bundler
pristine_system_gems
bundle "config set --local force_ruby_platform true"
bundle "install"

View file

@ -95,7 +95,7 @@ RSpec.describe "global gem caching" do
gem "myrack"
G
pristine_system_gems :bundler
pristine_system_gems
expect(the_bundle).not_to include_gems "myrack 1.0.0"
expect(source_global_cache("myrack-1.0.0.gem")).to exist
# myrack 1.0.0 is not installed and it is in the global cache
@ -105,7 +105,7 @@ RSpec.describe "global gem caching" do
gem "myrack", "0.9.1"
G
pristine_system_gems :bundler
pristine_system_gems
expect(the_bundle).not_to include_gems "myrack 0.9.1"
expect(source2_global_cache("myrack-0.9.1.gem")).to exist
# myrack 0.9.1 is not installed and it is in the global cache
@ -119,7 +119,7 @@ RSpec.describe "global gem caching" do
# myrack 1.0.0 is installed and myrack 0.9.1 is not
expect(the_bundle).to include_gems "myrack 1.0.0"
expect(the_bundle).not_to include_gems "myrack 0.9.1"
pristine_system_gems :bundler
pristine_system_gems
gemfile <<-G
source "#{source2}"
@ -141,7 +141,7 @@ RSpec.describe "global gem caching" do
G
bundle :install, artifice: "compact_index"
pristine_system_gems :bundler
pristine_system_gems
expect(the_bundle).not_to include_gems "myrack 1.0.0"
expect(source_global_cache("myrack-1.0.0.gem")).to exist
# myrack 1.0.0 is not installed and it is in the global cache
@ -152,7 +152,7 @@ RSpec.describe "global gem caching" do
G
bundle :install, artifice: "compact_index"
pristine_system_gems :bundler
pristine_system_gems
expect(the_bundle).not_to include_gems "myrack 0.9.1"
expect(source2_global_cache("myrack-0.9.1.gem")).to exist
# myrack 0.9.1 is not installed and it is in the global cache
@ -204,7 +204,7 @@ RSpec.describe "global gem caching" do
expect(the_bundle).to include_gems "activesupport 2.3.5"
expect(source_global_cache("myrack-1.0.0.gem")).to exist
expect(source_global_cache("activesupport-2.3.5.gem")).to exist
pristine_system_gems :bundler
pristine_system_gems
# Both gems are now only in the global cache
expect(the_bundle).not_to include_gems "myrack 1.0.0"
expect(the_bundle).not_to include_gems "activesupport 2.3.5"

View file

@ -107,7 +107,7 @@ RSpec.configure do |config|
end
config.around :each do |example|
FileUtils.cp_r pristine_system_gem_path, system_gem_path
default_system_gems
with_gem_path_as(system_gem_path) do
Bundler.ui.silence { example.run }

View file

@ -310,9 +310,10 @@ module Spec
default = options.fetch(:default, false)
gems.each do |g|
gem_name = g.to_s
if gem_name.start_with?("bundler")
version = gem_name.match(/\Abundler-(?<version>.*)\z/)[:version] if gem_name != "bundler"
with_built_bundler(version, released: options.fetch(:released, false)) {|gem_path| install_gem(gem_path, install_dir, default) }
bundler = gem_name.match(/\Abundler-(?<version>.*)\z/)
if bundler
with_built_bundler(bundler[:version], released: options.fetch(:released, false)) {|gem_path| install_gem(gem_path, install_dir, default) }
elsif %r{\A(?:[a-zA-Z]:)?/.*\.gem\z}.match?(gem_name)
install_gem(gem_name, install_dir, default)
else
@ -325,7 +326,7 @@ module Spec
def self.install_dev_bundler
extend self
system_gems :bundler, path: pristine_system_gem_path
with_built_bundler {|gem_path| install_gem(gem_path, pristine_system_gem_path) }
end
def install_gem(path, install_dir, default = false)
@ -395,7 +396,11 @@ module Spec
def pristine_system_gems(*gems)
FileUtils.rm_r(system_gem_path)
system_gems(*gems)
if gems.any?
system_gems(*gems)
else
default_system_gems
end
end
def cache_gems(*gems, gem_repo: gem_repo1)
@ -412,7 +417,11 @@ module Spec
def simulate_new_machine
FileUtils.rm_r bundled_app(".bundle")
pristine_system_gems :bundler
pristine_system_gems
end
def default_system_gems
FileUtils.cp_r pristine_system_gem_path, system_gem_path
end
def simulate_ruby_platform(ruby_platform)