[rubygems/rubygems] Refactor specs to not try to remove folders that don't exist

This has the following benefits:

* Avoid duplicated work in some specs that first build a repo, and then
  overwrite it with a completely different set of gems.
* Reduce RSpec nesting and improve readability.
* The change also made surfaces several specs that were incorrect since
  they were unintentionally not testing the right thing.

ed430883e0
This commit is contained in:
David Rodríguez 2025-03-07 20:47:24 +01:00 committed by Hiroshi SHIBATA
parent c68088038f
commit f656d34f10
17 changed files with 214 additions and 156 deletions

View file

@ -291,7 +291,7 @@ RSpec.describe "bundle cache" do
expect(cached_gem("platform_specific-1.0-java")).to exist expect(cached_gem("platform_specific-1.0-java")).to exist
end end
simulate_new_machine pristine_system_gems :bundler
simulate_platform "x86-darwin-100" do simulate_platform "x86-darwin-100" do
install_gemfile <<-G install_gemfile <<-G
@ -312,7 +312,8 @@ RSpec.describe "bundle cache" do
path: cached_myrack.parent, path: cached_myrack.parent,
rubygems_version: "1.3.2" rubygems_version: "1.3.2"
simulate_new_machine FileUtils.rm_rf default_bundle_path
system_gems :bundler
FileUtils.rm bundled_app_lock FileUtils.rm bundled_app_lock
bundle :install, raise_on_error: false bundle :install, raise_on_error: false
@ -344,7 +345,8 @@ RSpec.describe "bundle cache" do
c.checksum gem_repo1, "myrack", "1.0.0" c.checksum gem_repo1, "myrack", "1.0.0"
end end
simulate_new_machine FileUtils.rm_rf default_bundle_path
system_gems :bundler
lockfile <<-L lockfile <<-L
GEM GEM
@ -369,7 +371,7 @@ RSpec.describe "bundle cache" do
setup_main_repo setup_main_repo
cached_gem("myrack-1.0.0").rmtree cached_gem("myrack-1.0.0").rmtree
build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache")
simulate_new_machine pristine_system_gems :bundler
lockfile <<-L lockfile <<-L
GEM GEM

View file

@ -164,7 +164,7 @@ RSpec.describe "bundle cache with git" do
bundle "config set path vendor/bundle" bundle "config set path vendor/bundle"
bundle :install bundle :install
simulate_new_machine pristine_system_gems :bundler
with_path_as "" do with_path_as "" do
bundle "config set deployment true" bundle "config set deployment true"
bundle "install --local" bundle "install --local"
@ -181,10 +181,8 @@ RSpec.describe "bundle cache with git" do
G G
bundle "config set cache_all true" bundle "config set cache_all true"
bundle :cache, "all-platforms" => true bundle :cache, "all-platforms" => true
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/foo-1.0-*")).first.to_s
simulate_new_machine pristine_system_gems :bundler
bundle "config set frozen true" bundle "config set frozen true"
bundle "install --local --verbose" bundle "install --local --verbose"
expect(out).to_not include("Fetching") expect(out).to_not include("Fetching")
@ -200,12 +198,9 @@ RSpec.describe "bundle cache with git" do
G G
bundle "config set cache_all true" bundle "config set cache_all true"
bundle :cache, "all-platforms" => true bundle :cache, "all-platforms" => true
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/foo-1.0-*")).first.to_s
simulate_new_machine pristine_system_gems :bundler
bundle "config set frozen true" bundle "config set frozen true"
FileUtils.rm_rf "#{default_bundle_path}/cache/bundler/git/foo-1.0-*"
bundle "install --local --verbose" bundle "install --local --verbose"
expect(out).to_not include("Fetching") expect(out).to_not include("Fetching")
expect(the_bundle).to include_gem "foo 1.0" expect(the_bundle).to include_gem "foo 1.0"
@ -220,12 +215,9 @@ RSpec.describe "bundle cache with git" do
G G
bundle "config set cache_all true" bundle "config set cache_all true"
bundle :cache, "all-platforms" => true bundle :cache, "all-platforms" => true
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s
FileUtils.rm_rf Dir.glob(default_bundle_path("bundler/gems/foo-1.0-*")).first.to_s
simulate_new_machine pristine_system_gems :bundler
bundle "config set frozen true" bundle "config set frozen true"
FileUtils.rm_rf "#{default_bundle_path}/cache/bundler/git/foo-1.0-*"
# Remove untracked files (including the empty refs dir in the cache) # Remove untracked files (including the empty refs dir in the cache)
Dir.chdir(bundled_app) do Dir.chdir(bundled_app) do
@ -388,7 +380,7 @@ RSpec.describe "bundle cache with git" do
bundle "config set cache_all true" bundle "config set cache_all true"
bundle :cache, "all-platforms" => true, :install => false bundle :cache, "all-platforms" => true, :install => false
simulate_new_machine pristine_system_gems :bundler
with_path_as "" do with_path_as "" do
bundle "config set deployment true" bundle "config set deployment true"
bundle :install, local: true bundle :install, local: true

View file

@ -356,7 +356,7 @@ RSpec.describe "bundle install with gem sources" do
G G
bundle :cache bundle :cache
simulate_new_machine pristine_system_gems :bundler
FileUtils.rm_rf gem_repo2 FileUtils.rm_rf gem_repo2
bundle "install --local" bundle "install --local"
@ -371,7 +371,7 @@ RSpec.describe "bundle install with gem sources" do
G G
bundle :cache bundle :cache
simulate_new_machine pristine_system_gems :bundler
FileUtils.rm_rf gem_repo2 FileUtils.rm_rf gem_repo2
bundle "config set --local deployment true" bundle "config set --local deployment true"
@ -388,7 +388,7 @@ RSpec.describe "bundle install with gem sources" do
G G
bundle :cache bundle :cache
simulate_new_machine pristine_system_gems :bundler
FileUtils.rm_rf gem_repo2 FileUtils.rm_rf gem_repo2
bundle "config set --local cache_all_platforms true" bundle "config set --local cache_all_platforms true"
@ -445,9 +445,8 @@ RSpec.describe "bundle install with gem sources" do
bundle "config set path vendor/bundle" bundle "config set path vendor/bundle"
bundle :cache, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } bundle :cache, artifice: "compact_index", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s }
build_repo4 do # simulate removal of all remote gems
# simulate removal of all remote gems empty_repo4
end
# delete compact index cache # delete compact index cache
FileUtils.rm_rf home(".bundle/cache/compact_index") FileUtils.rm_rf home(".bundle/cache/compact_index")
@ -483,7 +482,7 @@ RSpec.describe "bundle install with gem sources" do
bundle :cache bundle :cache
end end
simulate_new_machine pristine_system_gems :bundler
bundle "config set --local force_ruby_platform true" bundle "config set --local force_ruby_platform true"

View file

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

View file

@ -1550,88 +1550,94 @@ RSpec.describe "bundle install with gem sources" do
end end
context "with --prefer-local flag" do context "with --prefer-local flag" do
before do context "and gems available locally" do
build_repo4 do before do
build_gem "foo", "1.0.1" build_repo4 do
build_gem "foo", "1.0.0" build_gem "foo", "1.0.1"
build_gem "bar", "1.0.0" build_gem "foo", "1.0.0"
build_gem "bar", "1.0.0"
build_gem "a", "1.0.0" do |s| build_gem "a", "1.0.0" do |s|
s.add_dependency "foo", "~> 1.0.0" s.add_dependency "foo", "~> 1.0.0"
end
build_gem "b", "1.0.0" do |s|
s.add_dependency "foo", "~> 1.0.1"
end
end end
build_gem "b", "1.0.0" do |s| system_gems "foo-1.0.0", path: default_bundle_path, gem_repo: gem_repo4
s.add_dependency "foo", "~> 1.0.1" end
it "fetches remote sources when not available locally" do
install_gemfile <<-G, "prefer-local": true, verbose: true
source "https://gem.repo4"
gem "foo"
gem "bar"
G
expect(out).to include("Using foo 1.0.0").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
expect(last_command).to be_success
end
it "fetches remote sources when local version does not match requirements" do
install_gemfile <<-G, "prefer-local": true, verbose: true
source "https://gem.repo4"
gem "foo", "1.0.1"
gem "bar"
G
expect(out).to include("Fetching foo 1.0.1").and include("Installing foo 1.0.1").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
expect(last_command).to be_success
end
it "uses the locally available version for sub-dependencies when possible" do
install_gemfile <<-G, "prefer-local": true, verbose: true
source "https://gem.repo4"
gem "a"
G
expect(out).to include("Using foo 1.0.0").and include("Fetching a 1.0.0").and include("Installing a 1.0.0")
expect(last_command).to be_success
end
it "fetches remote sources for sub-dependencies when the locally available version does not satisfy the requirement" do
install_gemfile <<-G, "prefer-local": true, verbose: true
source "https://gem.repo4"
gem "b"
G
expect(out).to include("Fetching foo 1.0.1").and include("Installing foo 1.0.1").and include("Fetching b 1.0.0").and include("Installing b 1.0.0")
expect(last_command).to be_success
end
end
context "and no gems available locally" do
before do
build_repo4 do
build_gem "myreline", "0.3.8"
build_gem "debug", "0.2.1"
build_gem "debug", "1.10.0" do |s|
s.add_dependency "myreline"
end
end end
end end
system_gems "foo-1.0.0", path: default_bundle_path, gem_repo: gem_repo4 it "resolves to the latest version if no gems are available locally" do
end install_gemfile <<~G, "prefer-local": true, verbose: true
source "https://gem.repo4"
it "fetches remote sources when not available locally" do gem "debug"
install_gemfile <<-G, "prefer-local": true, verbose: true G
source "https://gem.repo4"
gem "foo" expect(out).to include("Fetching debug 1.10.0").and include("Installing debug 1.10.0").and include("Fetching myreline 0.3.8").and include("Installing myreline 0.3.8")
gem "bar" expect(last_command).to be_success
G
expect(out).to include("Using foo 1.0.0").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
expect(last_command).to be_success
end
it "fetches remote sources when local version does not match requirements" do
install_gemfile <<-G, "prefer-local": true, verbose: true
source "https://gem.repo4"
gem "foo", "1.0.1"
gem "bar"
G
expect(out).to include("Fetching foo 1.0.1").and include("Installing foo 1.0.1").and include("Fetching bar 1.0.0").and include("Installing bar 1.0.0")
expect(last_command).to be_success
end
it "uses the locally available version for sub-dependencies when possible" do
install_gemfile <<-G, "prefer-local": true, verbose: true
source "https://gem.repo4"
gem "a"
G
expect(out).to include("Using foo 1.0.0").and include("Fetching a 1.0.0").and include("Installing a 1.0.0")
expect(last_command).to be_success
end
it "fetches remote sources for sub-dependencies when the locally available version does not satisfy the requirement" do
install_gemfile <<-G, "prefer-local": true, verbose: true
source "https://gem.repo4"
gem "b"
G
expect(out).to include("Fetching foo 1.0.1").and include("Installing foo 1.0.1").and include("Fetching b 1.0.0").and include("Installing b 1.0.0")
expect(last_command).to be_success
end
it "resolves to the latest version if no gems are available locally" do
build_repo4 do
build_gem "myreline", "0.3.8"
build_gem "debug", "0.2.1"
build_gem "debug", "1.10.0" do |s|
s.add_dependency "myreline"
end
end end
install_gemfile <<~G, "prefer-local": true, verbose: true
source "https://gem.repo4"
gem "debug"
G
expect(out).to include("Fetching debug 1.10.0").and include("Installing debug 1.10.0").and include("Fetching myreline 0.3.8").and include("Installing myreline 0.3.8")
expect(last_command).to be_success
end end
end end

View file

@ -99,7 +99,7 @@ RSpec.describe "bundle lock" do
L L
end end
before :each do let(:gemfile_with_rails_weakling_and_foo_from_repo4) do
build_repo4 do build_repo4 do
FileUtils.cp rake_path, "#{gem_repo4}/gems/" FileUtils.cp rake_path, "#{gem_repo4}/gems/"
@ -143,12 +143,16 @@ RSpec.describe "bundle lock" do
end end
it "prints a lockfile when there is no existing lockfile with --print" do it "prints a lockfile when there is no existing lockfile with --print" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock --print" bundle "lock --print"
expect(out).to eq(expected_lockfile.chomp) expect(out).to eq(expected_lockfile.chomp)
end end
it "prints a lockfile when there is an existing lockfile with --print" do it "prints a lockfile when there is an existing lockfile with --print" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile expected_lockfile lockfile expected_lockfile
bundle "lock --print" bundle "lock --print"
@ -157,6 +161,8 @@ RSpec.describe "bundle lock" do
end end
it "prints a lockfile when there is an existing checksums lockfile with --print" do it "prints a lockfile when there is an existing checksums lockfile with --print" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile expected_lockfile lockfile expected_lockfile
bundle "lock --print" bundle "lock --print"
@ -165,12 +171,16 @@ RSpec.describe "bundle lock" do
end end
it "writes a lockfile when there is no existing lockfile" do it "writes a lockfile when there is no existing lockfile" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock" bundle "lock"
expect(read_lockfile).to eq(expected_lockfile) expect(read_lockfile).to eq(expected_lockfile)
end end
it "prints a lockfile without fetching new checksums if the existing lockfile had no checksums" do it "prints a lockfile without fetching new checksums if the existing lockfile had no checksums" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile expected_lockfile lockfile expected_lockfile
bundle "lock --print" bundle "lock --print"
@ -179,6 +189,8 @@ RSpec.describe "bundle lock" do
end end
it "touches the lockfile when there is an existing lockfile that does not need changes" do it "touches the lockfile when there is an existing lockfile that does not need changes" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile expected_lockfile lockfile expected_lockfile
expect do expect do
@ -187,6 +199,8 @@ RSpec.describe "bundle lock" do
end end
it "does not touch lockfile with --print" do it "does not touch lockfile with --print" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile expected_lockfile lockfile expected_lockfile
expect do expect do
@ -195,6 +209,8 @@ RSpec.describe "bundle lock" do
end end
it "writes a lockfile when there is an outdated lockfile using --update" do it "writes a lockfile when there is an outdated lockfile using --update" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile outdated_lockfile lockfile outdated_lockfile
bundle "lock --update" bundle "lock --update"
@ -203,6 +219,8 @@ RSpec.describe "bundle lock" do
end end
it "prints an updated lockfile when there is an outdated lockfile using --print --update" do it "prints an updated lockfile when there is an outdated lockfile using --print --update" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile outdated_lockfile lockfile outdated_lockfile
bundle "lock --print --update" bundle "lock --print --update"
@ -211,6 +229,8 @@ RSpec.describe "bundle lock" do
end end
it "emits info messages to stderr when updating an outdated lockfile using --print --update" do it "emits info messages to stderr when updating an outdated lockfile using --print --update" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile outdated_lockfile lockfile outdated_lockfile
bundle "lock --print --update" bundle "lock --print --update"
@ -222,6 +242,8 @@ RSpec.describe "bundle lock" do
end end
it "writes a lockfile when there is an outdated lockfile and bundle is frozen" do it "writes a lockfile when there is an outdated lockfile and bundle is frozen" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile outdated_lockfile lockfile outdated_lockfile
bundle "lock --update", env: { "BUNDLE_FROZEN" => "true" } bundle "lock --update", env: { "BUNDLE_FROZEN" => "true" }
@ -230,12 +252,16 @@ RSpec.describe "bundle lock" do
end end
it "does not fetch remote specs when using the --local option" do it "does not fetch remote specs when using the --local option" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock --update --local", raise_on_error: false bundle "lock --update --local", raise_on_error: false
expect(err).to match(/locally installed gems/) expect(err).to match(/locally installed gems/)
end end
it "does not fetch remote checksums with --local" do it "does not fetch remote checksums with --local" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile expected_lockfile lockfile expected_lockfile
bundle "lock --print --local" bundle "lock --print --local"
@ -244,6 +270,8 @@ RSpec.describe "bundle lock" do
end end
it "works with --gemfile flag" do it "works with --gemfile flag" do
gemfile_with_rails_weakling_and_foo_from_repo4
gemfile "CustomGemfile", <<-G gemfile "CustomGemfile", <<-G
source "https://gem.repo4" source "https://gem.repo4"
gem "foo" gem "foo"
@ -275,6 +303,8 @@ RSpec.describe "bundle lock" do
end end
it "writes to a custom location using --lockfile" do it "writes to a custom location using --lockfile" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock --lockfile=lock" bundle "lock --lockfile=lock"
expect(out).to match(/Writing lockfile to.+lock/) expect(out).to match(/Writing lockfile to.+lock/)
@ -283,6 +313,8 @@ RSpec.describe "bundle lock" do
end end
it "writes to custom location using --lockfile when a default lockfile is present" do it "writes to custom location using --lockfile when a default lockfile is present" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "install" bundle "install"
bundle "lock --lockfile=lock" bundle "lock --lockfile=lock"
@ -338,6 +370,8 @@ RSpec.describe "bundle lock" do
end end
it "update specific gems using --update" do it "update specific gems using --update" do
gemfile_with_rails_weakling_and_foo_from_repo4
checksums = checksums_section_when_enabled do |c| checksums = checksums_section_when_enabled do |c|
c.checksum gem_repo4, "actionmailer", "2.3.1" c.checksum gem_repo4, "actionmailer", "2.3.1"
c.checksum gem_repo4, "actionpack", "2.3.1" c.checksum gem_repo4, "actionpack", "2.3.1"
@ -515,6 +549,8 @@ RSpec.describe "bundle lock" do
end end
it "preserves unknown checksum algorithms" do it "preserves unknown checksum algorithms" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile expected_lockfile.gsub(/(sha256=[a-f0-9]+)$/, "constant=true,\\1,xyz=123") lockfile expected_lockfile.gsub(/(sha256=[a-f0-9]+)$/, "constant=true,\\1,xyz=123")
previous_lockfile = read_lockfile previous_lockfile = read_lockfile
@ -525,6 +561,8 @@ RSpec.describe "bundle lock" do
end end
it "does not unlock git sources when only uri shape changes" do it "does not unlock git sources when only uri shape changes" do
gemfile_with_rails_weakling_and_foo_from_repo4
build_git("foo") build_git("foo")
install_gemfile <<-G install_gemfile <<-G
@ -543,6 +581,8 @@ RSpec.describe "bundle lock" do
end end
it "updates specific gems using --update using the locked revision of unrelated git gems for resolving" do it "updates specific gems using --update using the locked revision of unrelated git gems for resolving" do
gemfile_with_rails_weakling_and_foo_from_repo4
ref = build_git("foo").ref_for("HEAD") ref = build_git("foo").ref_for("HEAD")
gemfile <<-G gemfile <<-G
@ -581,6 +621,8 @@ RSpec.describe "bundle lock" do
end end
it "errors when updating a missing specific gems using --update" do it "errors when updating a missing specific gems using --update" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile expected_lockfile lockfile expected_lockfile
bundle "lock --update blahblah", raise_on_error: false bundle "lock --update blahblah", raise_on_error: false
@ -590,6 +632,8 @@ RSpec.describe "bundle lock" do
end end
it "can lock without downloading gems" do it "can lock without downloading gems" do
gemfile_with_rails_weakling_and_foo_from_repo4
gemfile <<-G gemfile <<-G
source "https://gem.repo1" source "https://gem.repo1"
@ -762,6 +806,8 @@ RSpec.describe "bundle lock" do
end end
it "supports adding new platforms when there's no previous lockfile" do it "supports adding new platforms when there's no previous lockfile" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock --add-platform java x86-mingw32 --verbose" bundle "lock --add-platform java x86-mingw32 --verbose"
expect(out).to include("Resolving dependencies because there's no lockfile") expect(out).to include("Resolving dependencies because there's no lockfile")
@ -770,6 +816,8 @@ RSpec.describe "bundle lock" do
end end
it "supports adding new platforms when a previous lockfile exists" do it "supports adding new platforms when a previous lockfile exists" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock" bundle "lock"
bundle "lock --add-platform java x86-mingw32 --verbose" bundle "lock --add-platform java x86-mingw32 --verbose"
expect(out).to include("Found changes from the lockfile, re-resolving dependencies because you are adding a new platform to your lockfile") expect(out).to include("Found changes from the lockfile, re-resolving dependencies because you are adding a new platform to your lockfile")
@ -835,6 +883,8 @@ RSpec.describe "bundle lock" do
end end
it "supports adding new platforms with force_ruby_platform = true" do it "supports adding new platforms with force_ruby_platform = true" do
gemfile_with_rails_weakling_and_foo_from_repo4
lockfile <<-L lockfile <<-L
GEM GEM
remote: https://gem.repo1/ remote: https://gem.repo1/
@ -858,6 +908,8 @@ RSpec.describe "bundle lock" do
end end
it "supports adding the `ruby` platform" do it "supports adding the `ruby` platform" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock --add-platform ruby" bundle "lock --add-platform ruby"
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
@ -865,12 +917,16 @@ RSpec.describe "bundle lock" do
end end
it "fails when adding an unknown platform" do it "fails when adding an unknown platform" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock --add-platform foobarbaz", raise_on_error: false bundle "lock --add-platform foobarbaz", raise_on_error: false
expect(err).to include("The platform `foobarbaz` is unknown to RubyGems and can't be added to the lockfile") expect(err).to include("The platform `foobarbaz` is unknown to RubyGems and can't be added to the lockfile")
expect(last_command).to be_failure expect(last_command).to be_failure
end end
it "allows removing platforms" do it "allows removing platforms" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock --add-platform java x86-mingw32" bundle "lock --add-platform java x86-mingw32"
allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
@ -944,6 +1000,8 @@ RSpec.describe "bundle lock" do
end end
it "errors when removing all platforms" do it "errors when removing all platforms" do
gemfile_with_rails_weakling_and_foo_from_repo4
bundle "lock --remove-platform #{local_platform}", raise_on_error: false bundle "lock --remove-platform #{local_platform}", raise_on_error: false
expect(err).to include("Removing all platforms from the bundle is not allowed") expect(err).to include("Removing all platforms from the bundle is not allowed")
end end
@ -1378,6 +1436,8 @@ RSpec.describe "bundle lock" do
context "when an update is available" do context "when an update is available" do
before do before do
gemfile_with_rails_weakling_and_foo_from_repo4
update_repo4 do update_repo4 do
build_gem "foo", "2.0" build_gem "foo", "2.0"
end end

View file

@ -974,7 +974,7 @@ RSpec.describe "bundle outdated" do
gem "terranova", '8' gem "terranova", '8'
G G
simulate_new_machine pristine_system_gems :bundler
update_git "foo", path: lib_path("foo") update_git "foo", path: lib_path("foo")
update_repo2 do 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 it "still works if you are not in the app directory and specify --gemfile" do
bundle "install" bundle "install"
simulate_new_machine pristine_system_gems :bundler
bundle "config set --local deployment true" bundle "config set --local deployment true"
bundle "config set --local path vendor/bundle" bundle "config set --local path vendor/bundle"
bundle "install --gemfile #{tmp}/bundled_app/Gemfile", dir: tmp 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" bundle "install --local"
expect(out).to include("Updating files in vendor/cache") expect(out).to include("Updating files in vendor/cache")
simulate_new_machine pristine_system_gems :bundler
bundle "config set --local deployment true" bundle "config set --local deployment true"
bundle "install --verbose" bundle "install --verbose"
expect(out).not_to include("but the lockfile can't be updated because frozen mode is set") expect(out).not_to include("but the lockfile can't be updated because frozen mode is set")

View file

@ -31,14 +31,13 @@ RSpec.describe "bundle install with git sources" do
end end
it "does not write to cache on bundler/setup" do it "does not write to cache on bundler/setup" do
cache_path = default_bundle_path("cache") FileUtils.rm_rf(default_cache_path)
FileUtils.rm_rf(cache_path)
ruby "require 'bundler/setup'" ruby "require 'bundler/setup'"
expect(cache_path).not_to exist expect(default_cache_path).not_to exist
end end
it "caches the git repo globally and properly uses the cached repo on the next invocation" do it "caches the git repo globally and properly uses the cached repo on the next invocation" do
simulate_new_machine pristine_system_gems :bundler
bundle "config set global_gem_cache true" bundle "config set global_gem_cache true"
bundle :install bundle :install
expect(Dir["#{home}/.bundle/cache/git/foo-1.0-*"]).to have_attributes size: 1 expect(Dir["#{home}/.bundle/cache/git/foo-1.0-*"]).to have_attributes size: 1
@ -1218,7 +1217,7 @@ RSpec.describe "bundle install with git sources" do
gem "valim", "= 1.0", :git => "#{lib_path("valim")}" gem "valim", "= 1.0", :git => "#{lib_path("valim")}"
G G
simulate_new_machine pristine_system_gems :bundler
bundle "config set --local deployment true" bundle "config set --local deployment true"
bundle :install bundle :install
@ -1605,7 +1604,7 @@ In Gemfile:
G G
bundle "config set --global path vendor/bundle" bundle "config set --global path vendor/bundle"
bundle :install bundle :install
simulate_new_machine pristine_system_gems :bundler
bundle "install", env: { "PATH" => "" } bundle "install", env: { "PATH" => "" }
expect(out).to_not include("You need to install git to be able to use gems from git repositories.") expect(out).to_not include("You need to install git to be able to use gems from git repositories.")

View file

@ -7,12 +7,8 @@ RSpec.describe "bundle install with a lockfile present" do
gem "myrack", "1.0.0" gem "myrack", "1.0.0"
G G
subject do
install_gemfile(gf)
end
it "touches the lockfile on install even when nothing has changed" do it "touches the lockfile on install even when nothing has changed" do
subject install_gemfile(gf)
expect { bundle :install }.to change { bundled_app_lock.mtime } expect { bundle :install }.to change { bundled_app_lock.mtime }
end end
@ -22,31 +18,24 @@ RSpec.describe "bundle install with a lockfile present" do
context "with plugins disabled" do context "with plugins disabled" do
before do before do
bundle "config set plugins false" bundle "config set plugins false"
subject
end end
it "does not evaluate the gemfile twice" do it "does not evaluate the gemfile twice when the gem is already installed" do
install_gemfile(gf)
bundle :install bundle :install
with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "myrack 1.0.0" } with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "myrack 1.0.0" }
# The first eval is from the initial install, we're testing that the
# second install doesn't double-eval
expect(bundled_app("evals").read.lines.to_a.size).to eq(2) expect(bundled_app("evals").read.lines.to_a.size).to eq(2)
end end
context "when the gem is not installed" do it "does not evaluate the gemfile twice when the gem is not installed" do
before { FileUtils.rm_rf bundled_app(".bundle") } gemfile(gf)
bundle :install
it "does not evaluate the gemfile twice" do with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "myrack 1.0.0" }
bundle :install
with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "myrack 1.0.0" } expect(bundled_app("evals").read.lines.to_a.size).to eq(1)
# The first eval is from the initial install, we're testing that the
# second install doesn't double-eval
expect(bundled_app("evals").read.lines.to_a.size).to eq(2)
end
end end
end end
end end

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" expect(the_bundle).to include_gems "nokogiri 1.4.2 java", "weakling 0.0.3"
simulate_new_machine pristine_system_gems :bundler
bundle "config set --local force_ruby_platform true" bundle "config set --local force_ruby_platform true"
bundle "install" bundle "install"

View file

@ -51,12 +51,14 @@ RSpec.describe "global gem caching" do
describe "when the same gem from different sources is installed" do describe "when the same gem from different sources is installed" do
it "should use the appropriate one from the global cache" do it "should use the appropriate one from the global cache" do
bundle "config path.system true"
install_gemfile <<-G, artifice: "compact_index" install_gemfile <<-G, artifice: "compact_index"
source "#{source}" source "#{source}"
gem "myrack" gem "myrack"
G G
simulate_new_machine pristine_system_gems :bundler
expect(the_bundle).not_to include_gems "myrack 1.0.0" expect(the_bundle).not_to include_gems "myrack 1.0.0"
expect(source_global_cache("myrack-1.0.0.gem")).to exist 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 # myrack 1.0.0 is not installed and it is in the global cache
@ -66,7 +68,7 @@ RSpec.describe "global gem caching" do
gem "myrack", "0.9.1" gem "myrack", "0.9.1"
G G
simulate_new_machine pristine_system_gems :bundler
expect(the_bundle).not_to include_gems "myrack 0.9.1" expect(the_bundle).not_to include_gems "myrack 0.9.1"
expect(source2_global_cache("myrack-0.9.1.gem")).to exist 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 # myrack 0.9.1 is not installed and it is in the global cache
@ -80,7 +82,7 @@ RSpec.describe "global gem caching" do
# myrack 1.0.0 is installed and myrack 0.9.1 is not # 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).to include_gems "myrack 1.0.0"
expect(the_bundle).not_to include_gems "myrack 0.9.1" expect(the_bundle).not_to include_gems "myrack 0.9.1"
simulate_new_machine pristine_system_gems :bundler
gemfile <<-G gemfile <<-G
source "#{source2}" source "#{source2}"
@ -94,13 +96,15 @@ RSpec.describe "global gem caching" do
end end
it "should not install if the wrong source is provided" do it "should not install if the wrong source is provided" do
bundle "config path.system true"
gemfile <<-G gemfile <<-G
source "#{source}" source "#{source}"
gem "myrack" gem "myrack"
G G
bundle :install, artifice: "compact_index" bundle :install, artifice: "compact_index"
simulate_new_machine pristine_system_gems :bundler
expect(the_bundle).not_to include_gems "myrack 1.0.0" expect(the_bundle).not_to include_gems "myrack 1.0.0"
expect(source_global_cache("myrack-1.0.0.gem")).to exist 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 # myrack 1.0.0 is not installed and it is in the global cache
@ -111,7 +115,7 @@ RSpec.describe "global gem caching" do
G G
bundle :install, artifice: "compact_index" bundle :install, artifice: "compact_index"
simulate_new_machine pristine_system_gems :bundler
expect(the_bundle).not_to include_gems "myrack 0.9.1" expect(the_bundle).not_to include_gems "myrack 0.9.1"
expect(source2_global_cache("myrack-0.9.1.gem")).to exist 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 # myrack 0.9.1 is not installed and it is in the global cache
@ -150,6 +154,8 @@ RSpec.describe "global gem caching" do
describe "when installing gems from a different directory" do describe "when installing gems from a different directory" do
it "uses the global cache as a source" do it "uses the global cache as a source" do
bundle "config path.system true"
install_gemfile <<-G, artifice: "compact_index" install_gemfile <<-G, artifice: "compact_index"
source "#{source}" source "#{source}"
gem "myrack" gem "myrack"
@ -161,7 +167,7 @@ RSpec.describe "global gem caching" do
expect(the_bundle).to include_gems "activesupport 2.3.5" 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("myrack-1.0.0.gem")).to exist
expect(source_global_cache("activesupport-2.3.5.gem")).to exist expect(source_global_cache("activesupport-2.3.5.gem")).to exist
simulate_new_machine pristine_system_gems :bundler
# Both gems are now only in the global cache # 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 "myrack 1.0.0"
expect(the_bundle).not_to include_gems "activesupport 2.3.5" expect(the_bundle).not_to include_gems "activesupport 2.3.5"

View file

@ -1,13 +1,11 @@
# frozen_string_literal: true # frozen_string_literal: true
RSpec.context "when installing a bundle that includes yanked gems" do RSpec.context "when installing a bundle that includes yanked gems" do
before(:each) do it "throws an error when the original gem version is yanked" do
build_repo4 do build_repo4 do
build_gem "foo", "9.0.0" build_gem "foo", "9.0.0"
end end
end
it "throws an error when the original gem version is yanked" do
lockfile <<-L lockfile <<-L
GEM GEM
remote: https://gem.repo4 remote: https://gem.repo4
@ -116,6 +114,10 @@ RSpec.context "when installing a bundle that includes yanked gems" do
end end
it "throws the original error when only the Gemfile specifies a gem version that doesn't exist" do it "throws the original error when only the Gemfile specifies a gem version that doesn't exist" do
build_repo4 do
build_gem "foo", "9.0.0"
end
bundle "config set force_ruby_platform true" bundle "config set force_ruby_platform true"
install_gemfile <<-G, raise_on_error: false install_gemfile <<-G, raise_on_error: false

View file

@ -458,9 +458,8 @@ RSpec.describe "Bundler.setup" do
end end
it "works even when the cache directory has been deleted" do it "works even when the cache directory has been deleted" do
bundle "config set --local path vendor/bundle"
bundle :install bundle :install
FileUtils.rm_rf vendored_gems("cache") FileUtils.rm_rf default_cache_path
expect(the_bundle).to include_gems "myrack 1.0.0" expect(the_bundle).to include_gems "myrack 1.0.0"
end end

View file

@ -187,32 +187,37 @@ module Spec
end end
def build_repo2(**kwargs, &blk) def build_repo2(**kwargs, &blk)
FileUtils.rm_rf gem_repo2 FileUtils.cp_r gem_repo1, gem_repo2, remove_destination: true
FileUtils.cp_r gem_repo1, gem_repo2
update_repo2(**kwargs, &blk) if block_given? update_repo2(**kwargs, &blk) if block_given?
end end
# A repo that has no pre-installed gems included. (The caller completely # A repo that has no pre-installed gems included. (The caller completely
# determines the contents with the block.) # determines the contents with the block.)
def build_repo3(**kwargs, &blk) def build_repo3(**kwargs, &blk)
build_empty_repo gem_repo3, **kwargs, &blk raise "gem_repo3 already exists -- use update_repo3 instead" if File.exist?(gem_repo3)
build_repo gem_repo3, **kwargs, &blk
end end
# Like build_repo3, this is a repo that has no pre-installed gems included. # Like build_repo3, this is a repo that has no pre-installed gems included.
# We have two different methods for situations where two different empty # We have two different methods for situations where two different empty
# sources are needed. # sources are needed.
def build_repo4(**kwargs, &blk) def build_repo4(**kwargs, &blk)
build_empty_repo gem_repo4, **kwargs, &blk raise "gem_repo4 already exists -- use update_repo4 instead" if File.exist?(gem_repo4)
end build_repo gem_repo4, **kwargs, &blk
def update_repo4(&blk)
update_repo(gem_repo4, &blk)
end end
def update_repo2(**kwargs, &blk) def update_repo2(**kwargs, &blk)
update_repo(gem_repo2, **kwargs, &blk) update_repo(gem_repo2, **kwargs, &blk)
end end
def update_repo3(&blk)
update_repo(gem_repo3, &blk)
end
def update_repo4(&blk)
update_repo(gem_repo4, &blk)
end
def build_security_repo def build_security_repo
build_repo security_repo do build_repo security_repo do
build_gem "myrack" build_gem "myrack"
@ -273,7 +278,6 @@ module Spec
def check_test_gems! def check_test_gems!
if rake_path.nil? if rake_path.nil?
FileUtils.rm_rf(base_system_gems)
Spec::Rubygems.install_test_deps Spec::Rubygems.install_test_deps
end end
@ -352,11 +356,6 @@ module Spec
private private
def build_empty_repo(gem_repo, **kwargs, &blk)
FileUtils.rm_rf gem_repo
build_repo(gem_repo, **kwargs, &blk)
end
def build_with(builder, name, args, &blk) def build_with(builder, name, args, &blk)
@_build_path ||= nil @_build_path ||= nil
@_build_repo ||= nil @_build_repo ||= nil

View file

@ -414,7 +414,6 @@ module Spec
def cache_gems(*gems, gem_repo: gem_repo1) def cache_gems(*gems, gem_repo: gem_repo1)
gems = gems.flatten gems = gems.flatten
FileUtils.rm_rf("#{bundled_app}/vendor/cache")
FileUtils.mkdir_p("#{bundled_app}/vendor/cache") FileUtils.mkdir_p("#{bundled_app}/vendor/cache")
gems.each do |g| gems.each do |g|
@ -549,6 +548,12 @@ module Spec
128 + signal_number 128 + signal_number
end end
def empty_repo4
FileUtils.rm_r gem_repo4
build_repo4 {}
end
private private
def allowed_rubygems_warning?(text, extra_allowed_warning) def allowed_rubygems_warning?(text, extra_allowed_warning)

View file

@ -62,8 +62,7 @@ module Spec
source = Path.tmp_root("1") source = Path.tmp_root("1")
destination = Path.tmp_root(n.to_s) destination = Path.tmp_root(n.to_s)
FileUtils.rm_rf destination FileUtils.cp_r source, destination, remove_destination: true
FileUtils.cp_r source, destination
end end
end end