summaryrefslogtreecommitdiff
path: root/spec/bundler/cache
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/cache')
-rw-r--r--spec/bundler/cache/cache_path_spec.rb24
-rw-r--r--spec/bundler/cache/gems_spec.rb341
-rw-r--r--spec/bundler/cache/git_spec.rb574
-rw-r--r--spec/bundler/cache/path_spec.rb189
-rw-r--r--spec/bundler/cache/platform_spec.rb23
5 files changed, 778 insertions, 373 deletions
diff --git a/spec/bundler/cache/cache_path_spec.rb b/spec/bundler/cache/cache_path_spec.rb
index ec6d6e312a..2a280ea858 100644
--- a/spec/bundler/cache/cache_path_spec.rb
+++ b/spec/bundler/cache/cache_path_spec.rb
@@ -1,34 +1,32 @@
# frozen_string_literal: true
-require "spec_helper"
RSpec.describe "bundle package" do
before do
gemfile <<-G
- source "file://#{gem_repo1}"
- gem "rack"
+ source "https://gem.repo1"
+ gem "myrack"
G
end
context "with --cache-path" do
it "caches gems at given path" do
- bundle :package, "cache-path" => "vendor/cache-foo"
- expect(bundled_app("vendor/cache-foo/rack-1.0.0.gem")).to exist
+ bundle :cache, "cache-path" => "vendor/cache-foo"
+ expect(bundled_app("vendor/cache-foo/myrack-1.0.0.gem")).to exist
end
end
context "with config cache_path" do
it "caches gems at given path" do
- bundle "config cache_path vendor/cache-foo"
- bundle :package
- expect(bundled_app("vendor/cache-foo/rack-1.0.0.gem")).to exist
+ bundle_config "cache_path vendor/cache-foo"
+ bundle :cache
+ expect(bundled_app("vendor/cache-foo/myrack-1.0.0.gem")).to exist
end
end
- context "when given an absolute path" do
- it "exits with non-zero status" do
- bundle :package, "cache-path" => "/tmp/cache-foo"
- expect(out).to match(/must be relative/)
- expect(exitstatus).to eq(15) if exitstatus
+ context "with absolute --cache-path" do
+ it "caches gems at given path" do
+ bundle :cache, "cache-path" => bundled_app("vendor/cache-foo")
+ expect(bundled_app("vendor/cache-foo/myrack-1.0.0.gem")).to exist
end
end
end
diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb
index 7828c87fec..198279d84c 100644
--- a/spec/bundler/cache/gems_spec.rb
+++ b/spec/bundler/cache/gems_spec.rb
@@ -1,26 +1,26 @@
# frozen_string_literal: true
-require "spec_helper"
RSpec.describe "bundle cache" do
- describe "when there are only gemsources" do
+ shared_examples_for "when there are only gemsources" do
before :each do
gemfile <<-G
- gem 'rack'
+ source "https://gem.repo1"
+ gem 'myrack'
G
- system_gems "rack-1.0.0"
+ system_gems "myrack-1.0.0", path: path
bundle :cache
end
it "copies the .gem file to vendor/cache" do
- expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist
+ expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist
end
it "uses the cache as a source when installing gems" do
- build_gem "omg", :path => bundled_app("vendor/cache")
+ build_gem "omg", path: bundled_app("vendor/cache")
install_gemfile <<-G
- source "file://#{gem_repo1}"
+ source "https://gem.repo1"
gem "omg"
G
@@ -28,118 +28,167 @@ RSpec.describe "bundle cache" do
end
it "uses the cache as a source when installing gems with --local" do
- system_gems []
+ system_gems [], path: default_bundle_path
bundle "install --local"
- expect(the_bundle).to include_gems("rack 1.0.0")
+ expect(the_bundle).to include_gems("myrack 1.0.0")
end
it "does not reinstall gems from the cache if they exist on the system" do
- build_gem "rack", "1.0.0", :path => bundled_app("vendor/cache") do |s|
- s.write "lib/rack.rb", "RACK = 'FAIL'"
+ build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") do |s|
+ s.write "lib/myrack.rb", "MYRACK = 'FAIL'"
end
install_gemfile <<-G
- gem "rack"
+ source "https://gem.repo1"
+ gem "myrack"
G
- expect(the_bundle).to include_gems("rack 1.0.0")
+ expect(the_bundle).to include_gems("myrack 1.0.0")
end
it "does not reinstall gems from the cache if they exist in the bundle" do
- system_gems "rack-1.0.0"
+ system_gems "myrack-1.0.0", path: default_bundle_path
gemfile <<-G
- gem "rack"
+ source "https://gem.repo1"
+ gem "myrack"
G
- build_gem "rack", "1.0.0", :path => bundled_app("vendor/cache") do |s|
- s.write "lib/rack.rb", "RACK = 'FAIL'"
+ build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache") do |s|
+ s.write "lib/myrack.rb", "MYRACK = 'FAIL'"
end
- bundle "install --local"
- expect(the_bundle).to include_gems("rack 1.0.0")
+ bundle :install, local: true
+ expect(the_bundle).to include_gems("myrack 1.0.0")
end
it "creates a lockfile" do
- cache_gems "rack-1.0.0"
+ cache_gems "myrack-1.0.0"
gemfile <<-G
- gem "rack"
+ source "https://gem.repo1"
+ gem "myrack"
G
bundle "cache"
- expect(bundled_app("Gemfile.lock")).to exist
+ expect(bundled_app_lock).to exist
end
end
- describe "when there is a built-in gem", :ruby => "2.0" do
+ context "using system gems" do
+ 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 "path ./.bundle" }
+ let(:path) { local_gem_path }
+ it_behaves_like "when there are only gemsources"
+ end
+
+ describe "when there is a built-in gem", :ruby_repo do
+ let(:default_json_version) { ruby "gem 'json'; require 'json'; puts JSON::VERSION" }
+
before :each do
- build_repo2 do
- build_gem "builtin_gem", "1.0.2"
+ build_gem "json", default_json_version, to_system: true, default: true
+ end
+
+ context "when a remote gem is available for caching" do
+ before do
+ build_repo2 do
+ build_gem "json", default_json_version
+ end
end
- build_gem "builtin_gem", "1.0.2", :to_system => true do |s|
- s.summary = "This builtin_gem is bundled with Ruby"
+ it "uses remote gems when installing" do
+ install_gemfile %(source "https://gem.repo2"; gem 'json', '#{default_json_version}'), verbose: true
+ expect(out).to include("Installing json #{default_json_version}")
end
- FileUtils.rm("#{system_gem_path}/cache/builtin_gem-1.0.2.gem")
- end
+ it "does not use remote gems when installing with --local flag" do
+ install_gemfile %(source "https://gem.repo2"; gem 'json', '#{default_json_version}'), verbose: true, local: true
+ expect(out).to include("Using json #{default_json_version}")
+ end
- it "uses builtin gems" do
- install_gemfile %(gem 'builtin_gem', '1.0.2')
- expect(the_bundle).to include_gems("builtin_gem 1.0.2")
- end
+ it "does not use remote gems when installing with --prefer-local flag" do
+ install_gemfile %(source "https://gem.repo2"; gem 'json', '#{default_json_version}'), verbose: true, "prefer-local": true
+ expect(out).to include("Using json #{default_json_version}")
+ end
- it "caches remote and builtin gems" do
- install_gemfile <<-G
- source "file://#{gem_repo2}"
- gem 'builtin_gem', '1.0.2'
- gem 'rack', '1.0.0'
- G
+ it "caches remote and builtin gems" do
+ install_gemfile <<-G
+ source "https://gem.repo2"
+ gem 'json', '#{default_json_version}'
+ gem 'myrack', '1.0.0'
+ G
- bundle :cache
- expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist
- expect(bundled_app("vendor/cache/builtin_gem-1.0.2.gem")).to exist
- end
+ bundle :cache
+ expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist
+ expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist
+ end
- it "doesn't make remote request after caching the gem" do
- build_gem "builtin_gem_2", "1.0.2", :path => bundled_app("vendor/cache") do |s|
- s.summary = "This builtin_gem is bundled with Ruby"
+ it "caches builtin gems when cache_all_platforms is set" do
+ gemfile <<-G
+ source "https://gem.repo2"
+ gem "json"
+ G
+
+ bundle_config "cache_all_platforms true"
+
+ bundle :cache
+ expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist
end
- install_gemfile <<-G
- source "file://#{gem_repo2}"
- gem 'builtin_gem_2', '1.0.2'
- G
+ it "doesn't make remote request after caching the gem" do
+ build_gem "builtin_gem_2", "1.0.2", path: bundled_app("vendor/cache"), default: true
- bundle "install --local"
- expect(the_bundle).to include_gems("builtin_gem_2 1.0.2")
+ install_gemfile <<-G
+ source "https://gem.repo2"
+ gem 'builtin_gem_2', '1.0.2'
+ G
+
+ bundle "install --local"
+ expect(the_bundle).to include_gems("builtin_gem_2 1.0.2")
+ end
end
- it "errors if the builtin gem isn't available to cache" do
- install_gemfile <<-G
- gem 'builtin_gem', '1.0.2'
- G
+ 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 "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
- bundle :cache
- expect(exitstatus).to_not eq(0) if exitstatus
- expect(out).to include("builtin_gem-1.0.2 is built in to Ruby, and can't be cached")
+ it "errors when explicitly caching" do
+ bundle_config "path.system true"
+
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem 'json', '#{default_json_version}'
+ G
+
+ bundle :cache, raise_on_error: false
+ expect(last_command).to be_failure
+ expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached")
+ end
end
end
describe "when there are also git sources" do
before do
build_git "foo"
- system_gems "rack-1.0.0"
+ system_gems "myrack-1.0.0"
install_gemfile <<-G
- source "file://#{gem_repo1}"
+ source "https://gem.repo1"
git "#{lib_path("foo-1.0")}" do
gem 'foo'
end
- gem 'rack'
+ gem 'myrack'
G
end
@@ -149,49 +198,57 @@ RSpec.describe "bundle cache" do
system_gems []
bundle "install --local"
- expect(the_bundle).to include_gems("rack 1.0.0", "foo 1.0")
+ expect(the_bundle).to include_gems("myrack 1.0.0", "foo 1.0")
end
it "should not explode if the lockfile is not present" do
- FileUtils.rm(bundled_app("Gemfile.lock"))
+ FileUtils.rm(bundled_app_lock)
bundle :cache
- expect(bundled_app("Gemfile.lock")).to exist
+ expect(bundled_app_lock).to exist
end
end
describe "when previously cached" do
- before :each do
+ let :setup_main_repo do
build_repo2
install_gemfile <<-G
- source "file://#{gem_repo2}"
- gem "rack"
+ source "https://gem.repo2"
+ gem "myrack"
gem "actionpack"
G
bundle :cache
- expect(cached_gem("rack-1.0.0")).to exist
+ expect(cached_gem("myrack-1.0.0")).to exist
expect(cached_gem("actionpack-2.3.2")).to exist
expect(cached_gem("activesupport-2.3.2")).to exist
end
it "re-caches during install" do
- cached_gem("rack-1.0.0").rmtree
+ setup_main_repo
+ FileUtils.rm_rf cached_gem("myrack-1.0.0")
bundle :install
expect(out).to include("Updating files in vendor/cache")
- expect(cached_gem("rack-1.0.0")).to exist
+ expect(cached_gem("myrack-1.0.0")).to exist
end
it "adds and removes when gems are updated" do
- update_repo2
- bundle "update"
- expect(cached_gem("rack-1.2")).to exist
- expect(cached_gem("rack-1.0.0")).not_to exist
+ setup_main_repo
+ update_repo2 do
+ build_gem "myrack", "1.2" do |s|
+ s.executables = "myrackup"
+ end
+ end
+
+ bundle "update", all: true
+ expect(cached_gem("myrack-1.2")).to exist
+ expect(cached_gem("myrack-1.0.0")).not_to exist
end
it "adds new gems and dependencies" do
+ setup_main_repo
install_gemfile <<-G
- source "file://#{gem_repo2}"
+ source "https://gem.repo2"
gem "rails"
G
expect(cached_gem("rails-2.3.2")).to exist
@@ -199,24 +256,26 @@ RSpec.describe "bundle cache" do
end
it "removes .gems for removed gems and dependencies" do
+ setup_main_repo
install_gemfile <<-G
- source "file://#{gem_repo2}"
- gem "rack"
+ source "https://gem.repo2"
+ gem "myrack"
G
- expect(cached_gem("rack-1.0.0")).to exist
+ expect(cached_gem("myrack-1.0.0")).to exist
expect(cached_gem("actionpack-2.3.2")).not_to exist
expect(cached_gem("activesupport-2.3.2")).not_to exist
end
it "removes .gems when gem changes to git source" do
- build_git "rack"
+ setup_main_repo
+ build_git "myrack"
install_gemfile <<-G
- source "file://#{gem_repo2}"
- gem "rack", :git => "#{lib_path("rack-1.0")}"
+ source "https://gem.repo2"
+ gem "myrack", :git => "#{lib_path("myrack-1.0")}"
gem "actionpack"
G
- expect(cached_gem("rack-1.0.0")).not_to exist
+ expect(cached_gem("myrack-1.0.0")).not_to exist
expect(cached_gem("actionpack-2.3.2")).to exist
expect(cached_gem("activesupport-2.3.2")).to exist
end
@@ -224,7 +283,7 @@ RSpec.describe "bundle cache" do
it "doesn't remove gems that are for another platform" do
simulate_platform "java" do
install_gemfile <<-G
- source "file://#{gem_repo1}"
+ source "https://gem.repo1"
gem "platform_specific"
G
@@ -232,37 +291,111 @@ RSpec.describe "bundle cache" do
expect(cached_gem("platform_specific-1.0-java")).to exist
end
- simulate_new_machine
- install_gemfile <<-G
- source "file://#{gem_repo1}"
- gem "platform_specific"
- G
+ pristine_system_gems
+
+ simulate_platform "x86-darwin-100" do
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "platform_specific"
+ G
- expect(cached_gem("platform_specific-1.0-#{Bundler.local_platform}")).to exist
- expect(cached_gem("platform_specific-1.0-java")).to exist
+ expect(cached_gem("platform_specific-1.0-x86-darwin-100")).to exist
+ expect(cached_gem("platform_specific-1.0-java")).to exist
+ end
end
- it "doesn't remove gems with mismatched :rubygems_version or :date" do
- cached_gem("rack-1.0.0").rmtree
- build_gem "rack", "1.0.0",
- :path => bundled_app("vendor/cache"),
- :rubygems_version => "1.3.2"
- simulate_new_machine
+ 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")
+ FileUtils.rm_rf cached_myrack
+ build_gem "myrack", "1.0.0",
+ path: cached_myrack.parent,
+ rubygems_version: "1.3.2"
+
+ FileUtils.rm_r default_bundle_path
+ default_system_gems
+
+ FileUtils.rm bundled_app_lock
+ bundle :install, raise_on_error: false
+
+ expect(err).to eq <<~E.strip
+ Bundler found mismatched checksums. This is a potential security risk.
+ #{checksum_to_lock(gem_repo2, "myrack", "1.0.0")}
+ from the API at https://gem.repo2/
+ #{checksum_from_package(cached_myrack, "myrack", "1.0.0")}
+ from the gem at #{cached_myrack}
+
+ If you trust the API at https://gem.repo2/, to resolve this issue you can:
+ 1. remove the gem at #{cached_myrack}
+ 2. run `bundle install`
+
+ To ignore checksum security warnings, disable checksum validation with
+ `bundle config set --local disable_checksum_validation true`
+ E
+
+ expect(cached_gem("myrack-1.0.0")).to exist
+ end
+ it "raises an error when a cached gem is altered and produces a different checksum than the remote gem" do
+ setup_main_repo
+ 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
+
+ FileUtils.rm_r default_bundle_path
+ default_system_gems
+
+ lockfile <<-L
+ GEM
+ remote: https://gem.repo2/
+ specs:
+ myrack (1.0.0)
+ #{checksums}
+ L
+
+ bundle :install, raise_on_error: false
+ expect(exitstatus).to eq(37)
+ expect(err).to include("Bundler found mismatched checksums.")
+ expect(err).to include("1. remove the gem at #{cached_gem("myrack-1.0.0")}")
+
+ expect(cached_gem("myrack-1.0.0")).to exist
+ FileUtils.rm_rf cached_gem("myrack-1.0.0")
bundle :install
- expect(cached_gem("rack-1.0.0")).to exist
+ 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
+ FileUtils.rm_rf cached_gem("myrack-1.0.0")
+ build_gem "myrack", "1.0.0", path: bundled_app("vendor/cache")
+ pristine_system_gems
+
+ lockfile <<-L
+ GEM
+ remote: https://gem.repo2/
+ specs:
+ myrack (1.0.0)
+ L
+
+ bundle :install, artifice: "endpoint", env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }
+ expect(cached_gem("myrack-1.0.0")).to exist
end
it "handles directories and non .gem files in the cache" do
+ setup_main_repo
bundled_app("vendor/cache/foo").mkdir
File.open(bundled_app("vendor/cache/bar"), "w") {|f| f.write("not a gem") }
bundle :cache
end
it "does not say that it is removing gems when it isn't actually doing so" do
+ setup_main_repo
install_gemfile <<-G
- source "file://#{gem_repo1}"
- gem "rack"
+ source "https://gem.repo1"
+ gem "myrack"
G
bundle "cache"
bundle "install"
@@ -270,9 +403,10 @@ RSpec.describe "bundle cache" do
end
it "does not warn about all if it doesn't have any git/path dependency" do
+ setup_main_repo
install_gemfile <<-G
- source "file://#{gem_repo1}"
- gem "rack"
+ source "https://gem.repo1"
+ gem "myrack"
G
bundle "cache"
expect(out).not_to match(/\-\-all/)
@@ -280,9 +414,10 @@ RSpec.describe "bundle cache" do
it "should install gems with the name bundler in them (that aren't bundler)" do
build_gem "foo-bundler", "1.0",
- :path => bundled_app("vendor/cache")
+ path: bundled_app("vendor/cache")
install_gemfile <<-G
+ source "https://gem.repo1"
gem "foo-bundler"
G
diff --git a/spec/bundler/cache/git_spec.rb b/spec/bundler/cache/git_spec.rb
index 31b3816a3b..f0976ecac7 100644
--- a/spec/bundler/cache/git_spec.rb
+++ b/spec/bundler/cache/git_spec.rb
@@ -1,5 +1,4 @@
# frozen_string_literal: true
-require "spec_helper"
RSpec.describe "git base name" do
it "base_name should strip private repo uris" do
@@ -13,203 +12,500 @@ RSpec.describe "git base name" do
end
end
-%w(cache package).each do |cmd|
- RSpec.describe "bundle #{cmd} with git" do
- it "copies repository to vendor cache and uses it" do
- git = build_git "foo"
- ref = git.ref_for("master", 11)
+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
- gem "foo", :git => '#{lib_path("foo-1.0")}'
- G
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
- bundle "#{cmd} --all"
- 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
+ bundle_config "cache_all false"
+ bundle :cache
+ expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).not_to exist
- FileUtils.rm_rf lib_path("foo-1.0")
- expect(the_bundle).to include_gems "foo 1.0"
- end
+ expect(the_bundle).to include_gems "foo 1.0"
+ end
- it "copies repository to vendor cache and uses it even when installed with bundle --path" do
- git = build_git "foo"
- ref = git.ref_for("master", 11)
+ it "copies repository to vendor cache and uses it" do
+ git = build_git "foo"
+ ref = git.ref_for("main", 11)
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}'
- G
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
- bundle "install --path vendor/bundle"
- bundle "#{cmd} --all"
+ 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
- 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_r lib_path("foo-1.0")
+ expect(the_bundle).to include_gems "foo 1.0"
+ end
+
+ it "copies repository to vendor cache and uses it even when configured with `path`" 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 "path vendor/bundle"
+ bundle "install"
+ 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_r lib_path("foo-1.0")
+ expect(the_bundle).to include_gems "foo 1.0"
+ end
- FileUtils.rm_rf lib_path("foo-1.0")
- expect(the_bundle).to include_gems "foo 1.0"
+ it "runs twice without exploding" do
+ build_git "foo"
+
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+
+ bundle :cache
+ bundle :cache
+
+ expect(out).to include "Updating files in vendor/cache"
+ FileUtils.rm_r lib_path("foo-1.0")
+ expect(the_bundle).to include_gems "foo 1.0"
+ end
+
+ it "tracks updates" do
+ git = build_git "foo"
+ old_ref = git.ref_for("main", 11)
+
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+
+ bundle :cache
+
+ update_git "foo" do |s|
+ s.write "lib/foo.rb", "puts :CACHE"
end
- it "runs twice without exploding" do
- build_git "foo"
+ ref = git.ref_for("main", 11)
+ expect(ref).not_to eq(old_ref)
+
+ bundle "update", all: true
+ bundle :cache
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}'
- G
+ 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_r lib_path("foo-1.0")
+ run "require 'foo'"
+ expect(out).to eq("CACHE")
+ end
- bundle "#{cmd} --all"
- bundle "#{cmd} --all"
+ it "tracks updates when specifying the gem" do
+ git = build_git "foo"
+ old_ref = git.ref_for("main", 11)
- expect(err).to lack_errors
- FileUtils.rm_rf lib_path("foo-1.0")
- expect(the_bundle).to include_gems "foo 1.0"
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+
+ bundle :cache
+
+ update_git "foo" do |s|
+ s.write "lib/foo.rb", "puts :CACHE"
end
- it "tracks updates" do
- git = build_git "foo"
- old_ref = git.ref_for("master", 11)
+ ref = git.ref_for("main", 11)
+ expect(ref).not_to eq(old_ref)
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}'
- G
+ bundle "update foo"
- bundle "#{cmd} --all"
+ expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist
+ expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist
- update_git "foo" do |s|
- s.write "lib/foo.rb", "puts :CACHE"
- end
+ FileUtils.rm_r lib_path("foo-1.0")
+ run "require 'foo'"
+ expect(out).to eq("CACHE")
+ end
- ref = git.ref_for("master", 11)
- expect(ref).not_to eq(old_ref)
+ it "uses the local repository to generate the cache" do
+ git = build_git "foo"
+ ref = git.ref_for("main", 11)
- bundle "update"
- bundle "#{cmd} --all"
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-invalid")}', :branch => :main
+ G
- expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist
- expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist
+ bundle %(config set local.foo #{lib_path("foo-1.0")})
+ bundle "install"
+ bundle :cache
+
+ expect(bundled_app("vendor/cache/foo-invalid-#{ref}")).to exist
- FileUtils.rm_rf lib_path("foo-1.0")
- run "require 'foo'"
- expect(out).to eq("CACHE")
+ # Updating the local still uses the local.
+ update_git "foo" do |s|
+ s.write "lib/foo.rb", "puts :LOCAL"
end
- it "tracks updates when specifying the gem" do
- git = build_git "foo"
- old_ref = git.ref_for("master", 11)
+ run "require 'foo'"
+ expect(out).to eq("LOCAL")
+ end
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}'
- G
+ it "can use gems after copying install folder to a different machine with git not installed" do
+ build_git "foo"
+
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+ bundle_config "path vendor/bundle"
+ bundle :install
+
+ pristine_system_gems
+ with_path_as "" do
+ bundle_config "deployment true"
+ bundle "install --local"
+ expect(the_bundle).to include_gem "foo 1.0"
+ end
+ end
- bundle "#{cmd} --all"
+ it "can install after bundle cache without cloning remote repositories" do
+ build_git "foo"
- update_git "foo" do |s|
- s.write "lib/foo.rb", "puts :CACHE"
- end
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+ bundle :cache, "all-platforms" => true
- ref = git.ref_for("master", 11)
- expect(ref).not_to eq(old_ref)
+ 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"
+ end
- bundle "update foo"
+ it "can install after bundle cache without cloning remote repositories even without the original cache" do
+ build_git "foo"
- expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist
- expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+ bundle :cache, "all-platforms" => 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"
+ end
+
+ it "can install after bundle cache without cloning remote repositories with only git tracked files" do
+ build_git "foo"
+
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+ bundle :cache, "all-platforms" => true
- FileUtils.rm_rf lib_path("foo-1.0")
- run "require 'foo'"
- expect(out).to eq("CACHE")
+ pristine_system_gems
+ bundle_config "frozen true"
+
+ # Remove untracked files (including the empty refs dir in the cache)
+ Dir.chdir(bundled_app) do
+ system(*%W[git init --quiet])
+ system(*%W[git add --all])
+ system(*%W[git clean -d --force --quiet])
end
- it "uses the local repository to generate the cache" do
- git = build_git "foo"
- ref = git.ref_for("master", 11)
+ bundle "install --local --verbose"
+ expect(out).to_not include("Fetching")
+ expect(the_bundle).to include_gem "foo 1.0"
+ end
- gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-invalid")}', :branch => :master
- G
+ it "installs properly a bundler 2.5.17-2.5.23 cache as a bare repository without cloning remote repositories" do
+ git = build_git "foo"
- bundle %(config local.foo #{lib_path("foo-1.0")})
- bundle "install"
- bundle "#{cmd} --all"
+ short_ref = git.ref_for("main", 11)
+ cache_dir = bundled_app("vendor/cache/foo-1.0-#{short_ref}")
- expect(bundled_app("vendor/cache/foo-invalid-#{ref}")).to exist
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+ bundle_config "global_gem_cache false"
+ bundle_config "path vendor/bundle"
+ bundle :install
- # Updating the local still uses the local.
- update_git "foo" do |s|
- s.write "lib/foo.rb", "puts :LOCAL"
- end
+ # 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_r bundled_app("vendor/bundle")
+
+ bundle "install --local --verbose"
+ expect(err).to include("Installing from cache in old \"bare repository\" format for compatibility")
+
+ expect(out).to_not include("Fetching")
- run "require 'foo'"
- expect(out).to eq("LOCAL")
+ # leaves old cache alone
+ expect(cache_dir.join("lib/foo.rb")).not_to exist
+ expect(cache_dir.join("HEAD")).to exist
+
+ expect(the_bundle).to include_gem "foo 1.0"
+ end
+
+ it "migrates a bundler 2.5.17-2.5.23 cache as a bare repository when not running with --local" do
+ git = build_git "foo"
+
+ short_ref = git.ref_for("main", 11)
+ cache_dir = bundled_app("vendor/cache/foo-1.0-#{short_ref}")
+
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+ 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_r bundled_app("vendor/bundle")
+
+ bundle "install --verbose"
+ expect(out).to include("Fetching")
+
+ # migrates old cache alone
+ expect(cache_dir.join("lib/foo.rb")).to exist
+ expect(cache_dir.join("HEAD")).not_to exist
+
+ expect(the_bundle).to include_gem "foo 1.0"
+ end
+
+ it "migrates a bundler 2.5.17-2.5.23 cache as a bare repository when running `bundle cache`, even if gems already installed" do
+ git = build_git "foo"
+
+ short_ref = git.ref_for("main", 11)
+ cache_dir = bundled_app("vendor/cache/foo-1.0-#{short_ref}")
+
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+ 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
+
+ bundle "cache"
+
+ # migrates old cache alone
+ expect(cache_dir.join("lib/foo.rb")).to exist
+ expect(cache_dir.join("HEAD")).not_to exist
+
+ expect(the_bundle).to include_gem "foo 1.0"
+ end
+
+ it "copies repository to vendor cache, including submodules" do
+ # CVE-2022-39253: https://lore.kernel.org/lkml/xmqq4jw1uku5.fsf@gitster.g/
+ system(*%W[git config --global protocol.file.allow always])
+
+ build_git "submodule", "1.0"
+
+ git = build_git "has_submodule", "1.0" do |s|
+ s.add_dependency "submodule"
end
- it "copies repository to vendor cache, including submodules" do
- build_git "submodule", "1.0"
+ git "submodule add #{lib_path("submodule-1.0")} submodule-1.0", lib_path("has_submodule-1.0")
+ git "commit -m \"submodulator\"", lib_path("has_submodule-1.0")
- git = build_git "has_submodule", "1.0" do |s|
- s.add_dependency "submodule"
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ git "#{lib_path("has_submodule-1.0")}", :submodules => true do
+ gem "has_submodule"
end
+ G
- Dir.chdir(lib_path("has_submodule-1.0")) do
- sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0"
- `git commit -m "submodulator"`
- end
+ ref = git.ref_for("main", 11)
+ bundle :cache
- install_gemfile <<-G
- git "#{lib_path("has_submodule-1.0")}", :submodules => true do
- gem "has_submodule"
- end
- G
+ expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist
+ expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0")).to exist
+ expect(the_bundle).to include_gems "has_submodule 1.0"
+ end
- ref = git.ref_for("master", 11)
- bundle "#{cmd} --all"
+ it "caches pre-evaluated gemspecs" do
+ git = build_git "foo"
- expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist
- expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0")).to exist
- expect(the_bundle).to include_gems "has_submodule 1.0"
- end
+ # Insert a gemspec method that shells out
+ spec_lines = lib_path("foo-1.0/foo.gemspec").read.split("\n")
+ spec_lines.insert(-2, "s.description = `echo bob`")
+ update_git("foo") {|s| s.write "foo.gemspec", spec_lines.join("\n") }
+
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+ bundle :cache
- it "displays warning message when detecting git repo in Gemfile" do
- build_git "foo"
+ ref = git.ref_for("main", 11)
+ gemspec = bundled_app("vendor/cache/foo-1.0-#{ref}/foo.gemspec").read
+ expect(gemspec).to_not match("`echo bob`")
+ end
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}'
- G
+ it "can install after bundle cache with git not installed" do
+ build_git "foo"
- bundle "#{cmd}"
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+ bundle :cache, "all-platforms" => true, :install => false
- expect(out).to include("Your Gemfile contains path and git dependencies.")
+ pristine_system_gems
+ with_path_as "" do
+ bundle_config "deployment true"
+ bundle :install, local: true
+ expect(the_bundle).to include_gem "foo 1.0"
end
+ end
- it "does not display warning message if cache_all is set in bundle config" do
- build_git "foo"
+ it "can install after bundle cache generated with an older Bundler that kept checkouts in the cache" do
+ git = build_git("foo")
+ locked_revision = git.ref_for("main")
+ path_revision = git.ref_for("main", 11)
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}'
- G
+ git_path = lib_path("foo-1.0")
- bundle "#{cmd} --all"
- bundle "#{cmd}"
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{git_path}'
+ G
+ lockfile <<~L
+ GIT
+ remote: #{git_path}/
+ revision: #{locked_revision}
+ specs:
+ foo (1.0)
- expect(out).not_to include("Your Gemfile contains path and git dependencies.")
- end
+ GEM
+ remote: https://gem.repo1/
+ specs:
+
+ PLATFORMS
+ #{lockfile_platforms}
- it "caches pre-evaluated gemspecs" do
- git = build_git "foo"
+ DEPENDENCIES
+ foo!
- # Insert a gemspec method that shells out
- spec_lines = lib_path("foo-1.0/foo.gemspec").read.split("\n")
- spec_lines.insert(-2, "s.description = `echo bob`")
- update_git("foo") {|s| s.write "foo.gemspec", spec_lines.join("\n") }
+ BUNDLED WITH
+ #{Bundler::VERSION}
+ L
- install_gemfile <<-G
- gem "foo", :git => '#{lib_path("foo-1.0")}'
- G
- bundle "#{cmd} --all"
+ # 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_r bundled_app("vendor/cache/foo-1.0-#{path_revision}/.git")
+
+ bundle :install, env: { "BUNDLE_DEPLOYMENT" => "true", "BUNDLE_CACHE_ALL" => "true" }
+ end
- ref = git.ref_for("master", 11)
- gemspec = bundled_app("vendor/cache/foo-1.0-#{ref}/foo.gemspec").read
- expect(gemspec).to_not match("`echo bob`")
+ it "respects the --no-install flag" do
+ git = build_git "foo", &:add_c_extension
+ ref = git.ref_for("main", 11)
+
+ gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :git => '#{lib_path("foo-1.0")}'
+ G
+
+ # The algorithm for the cache location for a git checkout is
+ # in Bundle::Source::Git#cache_path
+ cache_path_name = "foo-1.0-#{Digest(:SHA1).hexdigest(lib_path("foo-1.0").to_s)}"
+
+ # Run this test twice. This is because materially different codepaths
+ # will get hit the second time around.
+ # The first time, Bundler::Sources::Git#install_path is set to the system
+ # wide cache directory bundler/gems; the second time, it's set to the
+ # vendor/cache directory. We don't want the native extension to appear in
+ # either of these places, so run the `bundle cache` command twice.
+ 2.times 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 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
+ # it did _NOT_ build the gems extensions in the vendor/ dir
+ expect(Dir[bundled_app("vendor/cache/foo-1.0-#{ref}/lib/foo_c*")]).to be_empty
+ # it _did_ cache the git checkout
+ expect(default_cache_path("git", cache_path_name)).to exist
+ # And the checkout is a bare checkout
+ expect(default_cache_path("git", cache_path_name, "HEAD")).to exist
+ end
+
+ # Subsequently installing the gem should compile it.
+ # _currently_, the gem gets compiled in vendor/cache, and vendor/cache is added
+ # to the $LOAD_PATH for git extensions, so it all kind of "works". However, in the
+ # future we would like to stop adding vendor/cache to the $LOAD_PATH for git extensions
+ # and instead treat them identically to normal gems (where the gem install location,
+ # not the cache location, is added to $LOAD_PATH).
+ # Verify that the compilation worked and the result is in $LOAD_PATH by simply attempting
+ # to require it; that should make sure this spec does not break if the load path behaviour
+ # is changed.
+ bundle :install, local: true
+ ruby <<~R, raise_on_error: false
+ require 'bundler/setup'
+ require 'foo_c'
+ R
+ expect(last_command).to_not be_failure
+ end
+
+ it "doesn't fail when git gem has extensions and an empty cache folder is present before bundle install" do
+ build_git "puma" do |s|
+ s.add_dependency "rake"
+ s.extensions << "Rakefile"
+ s.executables = "puma"
+ s.write "Rakefile", <<-RUBY
+ task :default do
+ path = File.expand_path("../lib", __FILE__)
+ FileUtils.mkdir_p(path)
+ File.open("\#{path}/puma.rb", "w") do |f|
+ f.puts "PUMA = 'YES'"
+ end
+ end
+ RUBY
end
+
+ FileUtils.mkdir_p(bundled_app("vendor/cache"))
+
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "puma", :git => "#{lib_path("puma-1.0")}"
+ G
+
+ bundle "exec puma"
+
+ expect(out).to eq("YES")
end
end
diff --git a/spec/bundler/cache/path_spec.rb b/spec/bundler/cache/path_spec.rb
index bbce448759..42648aea1f 100644
--- a/spec/bundler/cache/path_spec.rb
+++ b/spec/bundler/cache/path_spec.rb
@@ -1,140 +1,121 @@
# frozen_string_literal: true
-require "spec_helper"
-%w(cache package).each do |cmd|
- RSpec.describe "bundle #{cmd} with path" do
- it "is no-op when the path is within the bundle" do
- build_lib "foo", :path => bundled_app("lib/foo")
+RSpec.describe "bundle cache with path" do
+ it "is no-op when the path is within the bundle" do
+ build_lib "foo", path: bundled_app("lib/foo")
- install_gemfile <<-G
- gem "foo", :path => '#{bundled_app("lib/foo")}'
- G
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :path => '#{bundled_app("lib/foo")}'
+ G
- bundle "#{cmd} --all"
- expect(bundled_app("vendor/cache/foo-1.0")).not_to exist
- expect(the_bundle).to include_gems "foo 1.0"
- end
-
- it "copies when the path is outside the bundle " do
- build_lib "foo"
-
- install_gemfile <<-G
- gem "foo", :path => '#{lib_path("foo-1.0")}'
- G
+ bundle :cache
+ expect(bundled_app("vendor/cache/foo-1.0")).not_to exist
+ expect(the_bundle).to include_gems "foo 1.0"
+ end
- bundle "#{cmd} --all"
- expect(bundled_app("vendor/cache/foo-1.0")).to exist
- expect(bundled_app("vendor/cache/foo-1.0/.bundlecache")).to be_file
+ it "copies when the path is outside the bundle " do
+ build_lib "foo"
- FileUtils.rm_rf lib_path("foo-1.0")
- expect(the_bundle).to include_gems "foo 1.0"
- end
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :path => '#{lib_path("foo-1.0")}'
+ G
- it "copies when the path is outside the bundle and the paths intersect" do
- libname = File.basename(Dir.pwd) + "_gem"
- libpath = File.join(File.dirname(Dir.pwd), libname)
+ bundle :cache
+ expect(bundled_app("vendor/cache/foo-1.0")).to exist
+ expect(bundled_app("vendor/cache/foo-1.0/.bundlecache")).to be_file
- build_lib libname, :path => libpath
-
- install_gemfile <<-G
- gem "#{libname}", :path => '#{libpath}'
- G
+ expect(the_bundle).to include_gems "foo 1.0"
+ end
- bundle "#{cmd} --all"
- expect(bundled_app("vendor/cache/#{libname}")).to exist
- expect(bundled_app("vendor/cache/#{libname}/.bundlecache")).to be_file
+ it "copies when the path is outside the bundle and the paths intersect" do
+ libname = File.basename(bundled_app) + "_gem"
+ libpath = File.join(File.dirname(bundled_app), libname)
- FileUtils.rm_rf libpath
- expect(the_bundle).to include_gems "#{libname} 1.0"
- end
+ build_lib libname, path: libpath
- it "updates the path on each cache" do
- build_lib "foo"
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "#{libname}", :path => '#{libpath}'
+ G
- install_gemfile <<-G
- gem "foo", :path => '#{lib_path("foo-1.0")}'
- G
+ bundle :cache
+ expect(bundled_app("vendor/cache/#{libname}")).to exist
+ expect(bundled_app("vendor/cache/#{libname}/.bundlecache")).to be_file
- bundle "#{cmd} --all"
+ expect(the_bundle).to include_gems "#{libname} 1.0"
+ end
- build_lib "foo" do |s|
- s.write "lib/foo.rb", "puts :CACHE"
- end
+ it "updates the path on each cache" do
+ build_lib "foo"
- bundle "#{cmd} --all"
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :path => '#{lib_path("foo-1.0")}'
+ G
- expect(bundled_app("vendor/cache/foo-1.0")).to exist
- FileUtils.rm_rf lib_path("foo-1.0")
+ bundle :cache
- run "require 'foo'"
- expect(out).to eq("CACHE")
+ build_lib "foo" do |s|
+ s.write "lib/foo.rb", "puts :CACHE"
end
- it "removes stale entries cache" do
- build_lib "foo"
+ bundle :cache
- install_gemfile <<-G
- gem "foo", :path => '#{lib_path("foo-1.0")}'
- G
+ expect(bundled_app("vendor/cache/foo-1.0")).to exist
- bundle "#{cmd} --all"
-
- install_gemfile <<-G
- gem "bar", :path => '#{lib_path("bar-1.0")}'
- G
-
- bundle "#{cmd} --all"
- expect(bundled_app("vendor/cache/bar-1.0")).not_to exist
- end
+ run "require 'foo'"
+ expect(out).to eq("CACHE")
+ end
- it "raises a warning without --all" do
- build_lib "foo"
+ it "removes stale entries cache" do
+ build_lib "foo"
- install_gemfile <<-G
- gem "foo", :path => '#{lib_path("foo-1.0")}'
- G
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :path => '#{lib_path("foo-1.0")}'
+ G
- bundle cmd
- expect(out).to match(/please pass the \-\-all flag/)
- expect(bundled_app("vendor/cache/foo-1.0")).not_to exist
- end
+ bundle :cache
- it "stores the given flag" do
- build_lib "foo"
+ expect(bundled_app("vendor/cache/foo-1.0")).to exist
- install_gemfile <<-G
- gem "foo", :path => '#{lib_path("foo-1.0")}'
- G
+ build_lib "bar"
- bundle "#{cmd} --all"
- build_lib "bar"
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "bar", :path => '#{lib_path("bar-1.0")}'
+ G
- install_gemfile <<-G
- gem "foo", :path => '#{lib_path("foo-1.0")}'
- gem "bar", :path => '#{lib_path("bar-1.0")}'
- G
+ bundle :cache
+ expect(bundled_app("vendor/cache/foo-1.0")).not_to exist
+ end
- bundle cmd
- expect(bundled_app("vendor/cache/bar-1.0")).to exist
- end
+ it "does not cache path gems if cache_all is set to false" do
+ build_lib "foo"
- 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 "cache_all false"
- install_gemfile <<-G
- gem "foo", :path => '#{lib_path("foo-1.0")}'
- G
+ bundle :cache
+ expect(err).to be_empty
+ expect(bundled_app("vendor/cache/foo-1.0")).not_to exist
+ end
- bundle "#{cmd} --all"
- build_lib "baz"
+ it "caches path gems by default" do
+ build_lib "foo"
- gemfile <<-G
- gem "foo", :path => '#{lib_path("foo-1.0")}'
- gem "baz", :path => '#{lib_path("baz-1.0")}'
- G
+ install_gemfile <<-G
+ source "https://gem.repo1"
+ gem "foo", :path => '#{lib_path("foo-1.0")}'
+ G
- bundle "#{cmd} --no-all"
- expect(bundled_app("vendor/cache/baz-1.0")).not_to exist
- end
+ bundle :cache
+ expect(err).to be_empty
+ expect(bundled_app("vendor/cache/foo-1.0")).to exist
end
end
diff --git a/spec/bundler/cache/platform_spec.rb b/spec/bundler/cache/platform_spec.rb
index ed80c949aa..71c0eaee8e 100644
--- a/spec/bundler/cache/platform_spec.rb
+++ b/spec/bundler/cache/platform_spec.rb
@@ -1,13 +1,12 @@
# frozen_string_literal: true
-require "spec_helper"
RSpec.describe "bundle cache with multiple platforms" do
before :each do
gemfile <<-G
- source "file://#{gem_repo1}"
+ source "https://gem.repo1"
platforms :mri, :rbx do
- gem "rack", "1.0.0"
+ gem "myrack", "1.0.0"
end
platforms :jruby do
@@ -17,9 +16,9 @@ RSpec.describe "bundle cache with multiple platforms" do
lockfile <<-G
GEM
- remote: file:#{gem_repo1}/
+ remote: https://gem.repo1/
specs:
- rack (1.0.0)
+ myrack (1.0.0)
activesupport (2.3.5)
PLATFORMS
@@ -27,28 +26,24 @@ RSpec.describe "bundle cache with multiple platforms" do
java
DEPENDENCIES
- rack (1.0.0)
+ myrack (1.0.0)
activesupport (2.3.5)
G
- cache_gems "rack-1.0.0", "activesupport-2.3.5"
+ cache_gems "myrack-1.0.0", "activesupport-2.3.5"
end
it "ensures that a successful bundle install does not delete gems for other platforms" do
bundle "install"
- expect(exitstatus).to eq 0 if exitstatus
-
- expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist
+ expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist
expect(bundled_app("vendor/cache/activesupport-2.3.5.gem")).to exist
end
it "ensures that a successful bundle update does not delete gems for other platforms" do
- bundle "update"
-
- expect(exitstatus).to eq 0 if exitstatus
+ bundle "update", all: true
- expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist
+ expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist
expect(bundled_app("vendor/cache/activesupport-2.3.5.gem")).to exist
end
end