diff options
Diffstat (limited to 'spec/bundler/cache/gems_spec.rb')
-rw-r--r-- | spec/bundler/cache/gems_spec.rb | 109 |
1 files changed, 83 insertions, 26 deletions
diff --git a/spec/bundler/cache/gems_spec.rb b/spec/bundler/cache/gems_spec.rb index 72e372fb41..abbc2c3cf2 100644 --- a/spec/bundler/cache/gems_spec.rb +++ b/spec/bundler/cache/gems_spec.rb @@ -8,7 +8,7 @@ RSpec.describe "bundle cache" do gem 'rack' G - system_gems "rack-1.0.0", :path => path + system_gems "rack-1.0.0", path: path bundle :cache end @@ -17,7 +17,7 @@ RSpec.describe "bundle cache" do 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_uri_for(gem_repo1)}" @@ -28,14 +28,14 @@ RSpec.describe "bundle cache" do end it "uses the cache as a source when installing gems with --local" do - system_gems [], :path => default_bundle_path + system_gems [], path: default_bundle_path bundle "install --local" expect(the_bundle).to include_gems("rack 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| + build_gem "rack", "1.0.0", path: bundled_app("vendor/cache") do |s| s.write "lib/rack.rb", "RACK = 'FAIL'" end @@ -48,18 +48,18 @@ RSpec.describe "bundle cache" do end it "does not reinstall gems from the cache if they exist in the bundle" do - system_gems "rack-1.0.0", :path => default_bundle_path + system_gems "rack-1.0.0", path: default_bundle_path gemfile <<-G source "#{file_uri_for(gem_repo1)}" gem "rack" G - build_gem "rack", "1.0.0", :path => bundled_app("vendor/cache") do |s| + build_gem "rack", "1.0.0", path: bundled_app("vendor/cache") do |s| s.write "lib/rack.rb", "RACK = 'FAIL'" end - bundle :install, :local => true + bundle :install, local: true expect(the_bundle).to include_gems("rack 1.0.0") end @@ -89,39 +89,49 @@ RSpec.describe "bundle cache" do it_behaves_like "when there are only gemsources" end - describe "when there is a built-in gem" do + 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 end - build_gem "builtin_gem", "1.0.2", :to_system => true do |s| - s.summary = "This builtin_gem is bundled with Ruby" - end - - FileUtils.rm("#{system_gem_path}/cache/builtin_gem-1.0.2.gem") + build_gem "json", default_json_version, to_system: true, default: true end it "uses builtin gems when installing to system gems" do bundle "config set path.system true" - install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'builtin_gem', '1.0.2') - expect(the_bundle).to include_gems("builtin_gem 1.0.2") + install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'json', '#{default_json_version}'), verbose: true + expect(out).to include("Using json #{default_json_version}") end it "caches remote and builtin gems" do install_gemfile <<-G source "#{file_uri_for(gem_repo2)}" - gem 'builtin_gem', '1.0.2' + gem 'json', '#{default_json_version}' gem 'rack', '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 + expect(bundled_app("vendor/cache/json-#{default_json_version}.gem")).to exist + end + + it "caches builtin gems when cache_all_platforms is set" do + gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "json" + G + + bundle "config set cache_all_platforms true" + + bundle :cache + 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| + build_gem "builtin_gem_2", "1.0.2", path: bundled_app("vendor/cache") do |s| s.summary = "This builtin_gem is bundled with Ruby" end @@ -139,12 +149,12 @@ RSpec.describe "bundle cache" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - gem 'builtin_gem', '1.0.2' + gem 'json', '#{default_json_version}' G - bundle :cache, :raise_on_error => false + bundle :cache, raise_on_error: false expect(exitstatus).to_not eq(0) - expect(err).to include("builtin_gem-1.0.2 is built in to Ruby, and can't be cached") + expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached") end end @@ -208,7 +218,7 @@ RSpec.describe "bundle cache" do end end - bundle "update", :all => true + bundle "update", all: true expect(cached_gem("rack-1.2")).to exist expect(cached_gem("rack-1.0.0")).not_to exist end @@ -269,10 +279,57 @@ RSpec.describe "bundle cache" do 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" + path: bundled_app("vendor/cache"), + rubygems_version: "1.3.2" + # This test is only really valid if the checksum isn't saved. It otherwise can't be the same gem. Tested below. + bundled_app_lock.write remove_checksums_from_lockfile(bundled_app_lock.read, "rack (1.0.0)") + simulate_new_machine + + bundle :install + expect(cached_gem("rack-1.0.0")).to exist + end + + it "raises an error when the gem is altered and produces a different checksum" do + cached_gem("rack-1.0.0").rmtree + build_gem "rack", "1.0.0", path: bundled_app("vendor/cache") + + checksums = checksums_section do |c| + c.checksum gem_repo1, "rack", "1.0.0" + end + simulate_new_machine + lockfile <<-L + GEM + remote: #{file_uri_for(gem_repo2)}/ + specs: + rack (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("rack-1.0.0")}") + + expect(cached_gem("rack-1.0.0")).to exist + cached_gem("rack-1.0.0").rmtree + bundle :install + expect(cached_gem("rack-1.0.0")).to exist + end + + it "installs a modified gem with a non-matching checksum when checksums is not opted in" do + cached_gem("rack-1.0.0").rmtree + build_gem "rack", "1.0.0", path: bundled_app("vendor/cache") + simulate_new_machine + + lockfile <<-L + GEM + remote: #{file_uri_for(gem_repo2)}/ + specs: + rack (1.0.0) + L + bundle :install expect(cached_gem("rack-1.0.0")).to exist end @@ -304,7 +361,7 @@ 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 "#{file_uri_for(gem_repo1)}" |