diff options
Diffstat (limited to 'spec/bundler/cache')
| -rw-r--r-- | spec/bundler/cache/cache_path_spec.rb | 2 | ||||
| -rw-r--r-- | spec/bundler/cache/gems_spec.rb | 30 | ||||
| -rw-r--r-- | spec/bundler/cache/git_spec.rb | 97 | ||||
| -rw-r--r-- | spec/bundler/cache/path_spec.rb | 54 |
4 files changed, 64 insertions, 119 deletions
diff --git a/spec/bundler/cache/cache_path_spec.rb b/spec/bundler/cache/cache_path_spec.rb index d5bd14965b..2a280ea858 100644 --- a/spec/bundler/cache/cache_path_spec.rb +++ b/spec/bundler/cache/cache_path_spec.rb @@ -17,7 +17,7 @@ RSpec.describe "bundle package" do context "with config cache_path" do it "caches gems at given path" do - bundle "config set cache_path vendor/cache-foo" + bundle_config "cache_path vendor/cache-foo" bundle :cache expect(bundled_app("vendor/cache-foo/myrack-1.0.0.gem")).to exist end diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb index c68b20225a..198279d84c 100644 --- a/spec/bundler/cache/gems_spec.rb +++ b/spec/bundler/cache/gems_spec.rb @@ -78,13 +78,13 @@ RSpec.describe "bundle cache" do end context "using system gems" do - before { bundle "config set path.system true" } + before { bundle_config "path.system true" } let(:path) { system_gem_path } it_behaves_like "when there are only gemsources" end context "installing into a local path" do - before { bundle "config set path ./.bundle" } + before { bundle_config "path ./.bundle" } let(:path) { local_gem_path } it_behaves_like "when there are only gemsources" end @@ -136,7 +136,7 @@ RSpec.describe "bundle cache" do gem "json" G - bundle "config set cache_all_platforms true" + bundle_config "cache_all_platforms true" bundle :cache expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist @@ -157,14 +157,14 @@ RSpec.describe "bundle cache" do context "when a remote gem is not available for caching" do it "warns, but uses builtin gems when installing to system gems" do - bundle "config set path.system true" + bundle_config "path.system true" install_gemfile %(source "https://gem.repo1"; gem 'json', '#{default_json_version}'), verbose: true expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached") expect(out).to include("Using json #{default_json_version}") end it "errors when explicitly caching" do - bundle "config set path.system true" + bundle_config "path.system true" install_gemfile <<-G source "https://gem.repo1" @@ -226,7 +226,7 @@ RSpec.describe "bundle cache" do it "re-caches during install" do setup_main_repo - cached_gem("myrack-1.0.0").rmtree + FileUtils.rm_rf cached_gem("myrack-1.0.0") bundle :install expect(out).to include("Updating files in vendor/cache") expect(cached_gem("myrack-1.0.0")).to exist @@ -291,7 +291,7 @@ RSpec.describe "bundle cache" do expect(cached_gem("platform_specific-1.0-java")).to exist end - simulate_new_machine + pristine_system_gems simulate_platform "x86-darwin-100" do install_gemfile <<-G @@ -307,12 +307,13 @@ RSpec.describe "bundle cache" do it "doesn't remove gems cached gems that don't match their remote counterparts, but also refuses to install and prints an error" do setup_main_repo cached_myrack = cached_gem("myrack-1.0.0") - cached_myrack.rmtree + FileUtils.rm_rf cached_myrack build_gem "myrack", "1.0.0", path: cached_myrack.parent, rubygems_version: "1.3.2" - simulate_new_machine + FileUtils.rm_r default_bundle_path + default_system_gems FileUtils.rm bundled_app_lock bundle :install, raise_on_error: false @@ -337,14 +338,15 @@ RSpec.describe "bundle cache" do it "raises an error when a cached gem is altered and produces a different checksum than the remote gem" do setup_main_repo - cached_gem("myrack-1.0.0").rmtree + FileUtils.rm_rf cached_gem("myrack-1.0.0") build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") checksums = checksums_section do |c| c.checksum gem_repo1, "myrack", "1.0.0" end - simulate_new_machine + FileUtils.rm_r default_bundle_path + default_system_gems lockfile <<-L GEM @@ -360,16 +362,16 @@ RSpec.describe "bundle cache" do expect(err).to include("1. remove the gem at #{cached_gem("myrack-1.0.0")}") expect(cached_gem("myrack-1.0.0")).to exist - cached_gem("myrack-1.0.0").rmtree + FileUtils.rm_rf cached_gem("myrack-1.0.0") bundle :install expect(cached_gem("myrack-1.0.0")).to exist end it "installs a modified gem with a non-matching checksum when the API implementation does not provide checksums" do setup_main_repo - cached_gem("myrack-1.0.0").rmtree + FileUtils.rm_rf cached_gem("myrack-1.0.0") build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") - simulate_new_machine + pristine_system_gems lockfile <<-L GEM diff --git a/spec/bundler/cache/git_spec.rb b/spec/bundler/cache/git_spec.rb index 38333c0219..f0976ecac7 100644 --- a/spec/bundler/cache/git_spec.rb +++ b/spec/bundler/cache/git_spec.rb @@ -13,6 +13,22 @@ RSpec.describe "git base name" do end RSpec.describe "bundle cache with git" do + it "does not copy repository to vendor cache when cache_all set to false" do + git = build_git "foo" + ref = git.ref_for("main", 11) + + install_gemfile <<-G + source "https://gem.repo1" + gem "foo", :git => '#{lib_path("foo-1.0")}' + G + + bundle_config "cache_all false" + bundle :cache + expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).not_to exist + + expect(the_bundle).to include_gems "foo 1.0" + end + it "copies repository to vendor cache and uses it" do git = build_git "foo" ref = git.ref_for("main", 11) @@ -22,13 +38,12 @@ RSpec.describe "bundle cache with git" do gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" bundle :cache expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.bundlecache")).to be_file - FileUtils.rm_rf lib_path("foo-1.0") + FileUtils.rm_r lib_path("foo-1.0") expect(the_bundle).to include_gems "foo 1.0" end @@ -41,15 +56,14 @@ RSpec.describe "bundle cache with git" do gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set --local path vendor/bundle" + bundle_config "path vendor/bundle" bundle "install" - bundle "config set cache_all true" bundle :cache expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist - FileUtils.rm_rf lib_path("foo-1.0") + FileUtils.rm_r lib_path("foo-1.0") expect(the_bundle).to include_gems "foo 1.0" end @@ -61,12 +75,11 @@ RSpec.describe "bundle cache with git" do gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" bundle :cache bundle :cache expect(out).to include "Updating files in vendor/cache" - FileUtils.rm_rf lib_path("foo-1.0") + FileUtils.rm_r lib_path("foo-1.0") expect(the_bundle).to include_gems "foo 1.0" end @@ -79,7 +92,6 @@ RSpec.describe "bundle cache with git" do gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" bundle :cache update_git "foo" do |s| @@ -95,7 +107,7 @@ RSpec.describe "bundle cache with git" do expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist - FileUtils.rm_rf lib_path("foo-1.0") + FileUtils.rm_r lib_path("foo-1.0") run "require 'foo'" expect(out).to eq("CACHE") end @@ -109,7 +121,6 @@ RSpec.describe "bundle cache with git" do gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" bundle :cache update_git "foo" do |s| @@ -124,7 +135,7 @@ RSpec.describe "bundle cache with git" do expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist - FileUtils.rm_rf lib_path("foo-1.0") + FileUtils.rm_r lib_path("foo-1.0") run "require 'foo'" expect(out).to eq("CACHE") end @@ -140,7 +151,6 @@ RSpec.describe "bundle cache with git" do bundle %(config set local.foo #{lib_path("foo-1.0")}) bundle "install" - bundle "config set cache_all true" bundle :cache expect(bundled_app("vendor/cache/foo-invalid-#{ref}")).to exist @@ -161,12 +171,12 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set path vendor/bundle" + bundle_config "path vendor/bundle" bundle :install - simulate_new_machine + pristine_system_gems with_path_as "" do - bundle "config set deployment true" + bundle_config "deployment true" bundle "install --local" expect(the_bundle).to include_gem "foo 1.0" end @@ -179,13 +189,10 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all 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 - bundle "config set frozen true" + pristine_system_gems + bundle_config "frozen true" bundle "install --local --verbose" expect(out).to_not include("Fetching") expect(the_bundle).to include_gem "foo 1.0" @@ -198,14 +205,10 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all 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 - bundle "config set frozen true" - FileUtils.rm_rf "#{default_bundle_path}/cache/bundler/git/foo-1.0-*" + pristine_system_gems + bundle_config "frozen true" bundle "install --local --verbose" expect(out).to_not include("Fetching") expect(the_bundle).to include_gem "foo 1.0" @@ -218,14 +221,10 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all 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 - bundle "config set frozen true" - FileUtils.rm_rf "#{default_bundle_path}/cache/bundler/git/foo-1.0-*" + pristine_system_gems + bundle_config "frozen true" # Remove untracked files (including the empty refs dir in the cache) Dir.chdir(bundled_app) do @@ -249,15 +248,14 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set global_gem_cache false" - bundle "config set cache_all true" - bundle "config path vendor/bundle" + bundle_config "global_gem_cache false" + bundle_config "path vendor/bundle" bundle :install # Simulate old cache by copying the real cache folder to vendor/cache FileUtils.mkdir_p bundled_app("vendor/cache") FileUtils.cp_r "#{Dir.glob(vendored_gems("cache/bundler/git/foo-1.0-*")).first}/.", cache_dir - FileUtils.rm_rf bundled_app("vendor/bundle") + FileUtils.rm_r bundled_app("vendor/bundle") bundle "install --local --verbose" expect(err).to include("Installing from cache in old \"bare repository\" format for compatibility") @@ -281,15 +279,14 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set global_gem_cache false" - bundle "config set cache_all true" - bundle "config path vendor/bundle" + bundle_config "global_gem_cache false" + bundle_config "path vendor/bundle" bundle :install # Simulate old cache by copying the real cache folder to vendor/cache FileUtils.mkdir_p bundled_app("vendor/cache") FileUtils.cp_r "#{Dir.glob(vendored_gems("cache/bundler/git/foo-1.0-*")).first}/.", cache_dir - FileUtils.rm_rf bundled_app("vendor/bundle") + FileUtils.rm_r bundled_app("vendor/bundle") bundle "install --verbose" expect(out).to include("Fetching") @@ -311,9 +308,8 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set global_gem_cache false" - bundle "config set cache_all true" - bundle "config path vendor/bundle" + bundle_config "global_gem_cache false" + bundle_config "path vendor/bundle" bundle :install # Simulate old cache by copying the real cache folder to vendor/cache @@ -350,7 +346,6 @@ RSpec.describe "bundle cache with git" do G ref = git.ref_for("main", 11) - bundle "config set cache_all true" bundle :cache expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist @@ -370,7 +365,6 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" bundle :cache ref = git.ref_for("main", 11) @@ -385,12 +379,11 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" bundle :cache, "all-platforms" => true, :install => false - simulate_new_machine + pristine_system_gems with_path_as "" do - bundle "config set deployment true" + bundle_config "deployment true" bundle :install, local: true expect(the_bundle).to include_gem "foo 1.0" end @@ -425,13 +418,13 @@ RSpec.describe "bundle cache with git" do foo! BUNDLED WITH - #{Bundler::VERSION} + #{Bundler::VERSION} L # Simulate an old incorrect situation where vendor/cache would be the install location of git gems FileUtils.mkdir_p bundled_app("vendor/cache") FileUtils.cp_r git_path, bundled_app("vendor/cache/foo-1.0-#{path_revision}") - FileUtils.rm_rf bundled_app("vendor/cache/foo-1.0-#{path_revision}/.git") + FileUtils.rm_r bundled_app("vendor/cache/foo-1.0-#{path_revision}/.git") bundle :install, env: { "BUNDLE_DEPLOYMENT" => "true", "BUNDLE_CACHE_ALL" => "true" } end @@ -444,7 +437,6 @@ RSpec.describe "bundle cache with git" do source "https://gem.repo1" gem "foo", :git => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" # The algorithm for the cache location for a git checkout is # in Bundle::Source::Git#cache_path @@ -460,7 +452,7 @@ RSpec.describe "bundle cache with git" do bundle :cache, "all-platforms" => true, :install => false # it did _NOT_ actually install the gem - neither in $GEM_HOME (bundler 2 mode), - # nor in .bundle (bundler 3 mode) + # nor in .bundle (bundler 4 mode) expect(Pathname.new(File.join(default_bundle_path, "gems/foo-1.0-#{ref}"))).to_not exist # it _did_ cache the gem in vendor/ expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist @@ -506,7 +498,6 @@ RSpec.describe "bundle cache with git" do end FileUtils.mkdir_p(bundled_app("vendor/cache")) - bundle "config set cache_all all" install_gemfile <<-G source "https://gem.repo1" diff --git a/spec/bundler/cache/path_spec.rb b/spec/bundler/cache/path_spec.rb index 966cb6f531..42648aea1f 100644 --- a/spec/bundler/cache/path_spec.rb +++ b/spec/bundler/cache/path_spec.rb @@ -9,7 +9,6 @@ RSpec.describe "bundle cache with path" do gem "foo", :path => '#{bundled_app("lib/foo")}' G - bundle "config set cache_all true" bundle :cache expect(bundled_app("vendor/cache/foo-1.0")).not_to exist expect(the_bundle).to include_gems "foo 1.0" @@ -23,7 +22,6 @@ RSpec.describe "bundle cache with path" do gem "foo", :path => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" bundle :cache expect(bundled_app("vendor/cache/foo-1.0")).to exist expect(bundled_app("vendor/cache/foo-1.0/.bundlecache")).to be_file @@ -42,7 +40,6 @@ RSpec.describe "bundle cache with path" do gem "#{libname}", :path => '#{libpath}' G - bundle "config set cache_all true" bundle :cache expect(bundled_app("vendor/cache/#{libname}")).to exist expect(bundled_app("vendor/cache/#{libname}/.bundlecache")).to be_file @@ -58,7 +55,6 @@ RSpec.describe "bundle cache with path" do gem "foo", :path => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" bundle :cache build_lib "foo" do |s| @@ -81,7 +77,6 @@ RSpec.describe "bundle cache with path" do gem "foo", :path => '#{lib_path("foo-1.0")}' G - bundle "config set cache_all true" bundle :cache expect(bundled_app("vendor/cache/foo-1.0")).to exist @@ -97,20 +92,21 @@ RSpec.describe "bundle cache with path" do expect(bundled_app("vendor/cache/foo-1.0")).not_to exist end - it "does not cache path gems by default", bundler: "< 3" do + it "does not cache path gems if cache_all is set to false" do build_lib "foo" install_gemfile <<-G source "https://gem.repo1" gem "foo", :path => '#{lib_path("foo-1.0")}' G + bundle_config "cache_all false" bundle :cache expect(err).to be_empty expect(bundled_app("vendor/cache/foo-1.0")).not_to exist end - it "caches path gems by default", bundler: "3" do + it "caches path gems by default" do build_lib "foo" install_gemfile <<-G @@ -122,48 +118,4 @@ RSpec.describe "bundle cache with path" do expect(err).to be_empty expect(bundled_app("vendor/cache/foo-1.0")).to exist end - - it "stores the given flag" do - build_lib "foo" - - install_gemfile <<-G - source "https://gem.repo1" - gem "foo", :path => '#{lib_path("foo-1.0")}' - G - - bundle "config set cache_all true" - bundle :cache - build_lib "bar" - - install_gemfile <<-G - source "https://gem.repo1" - gem "foo", :path => '#{lib_path("foo-1.0")}' - gem "bar", :path => '#{lib_path("bar-1.0")}' - G - - bundle :cache - expect(bundled_app("vendor/cache/bar-1.0")).to exist - end - - it "can rewind chosen configuration" do - build_lib "foo" - - install_gemfile <<-G - source "https://gem.repo1" - gem "foo", :path => '#{lib_path("foo-1.0")}' - G - - bundle "config set cache_all true" - bundle :cache - build_lib "baz" - - gemfile <<-G - source "https://gem.repo1" - gem "foo", :path => '#{lib_path("foo-1.0")}' - gem "baz", :path => '#{lib_path("baz-1.0")}' - G - - bundle "cache --no-all", raise_on_error: false - expect(bundled_app("vendor/cache/baz-1.0")).not_to exist - end end |
