diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-07-13 14:36:57 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2022-09-03 15:54:07 +0900 |
commit | d7862a5de43f7412ab41cdae6709c8a30b988621 (patch) | |
tree | 9380b0239b29f05fbdc1b0aff66caae066b5e71f /spec | |
parent | ffd3d83ea8ccf111061a0f03036e5a093bb03674 (diff) |
Merge RubyGems-3.3.14 and Bundler-2.3.14
Diffstat (limited to 'spec')
-rw-r--r-- | spec/bundler/bundler/installer/gem_installer_spec.rb | 15 | ||||
-rw-r--r-- | spec/bundler/bundler/source_spec.rb | 38 | ||||
-rw-r--r-- | spec/bundler/commands/lock_spec.rb | 10 | ||||
-rw-r--r-- | spec/bundler/install/gems/resolving_spec.rb | 37 | ||||
-rw-r--r-- | spec/bundler/install/yanked_spec.rb | 4 | ||||
-rw-r--r-- | spec/bundler/runtime/inline_spec.rb | 36 | ||||
-rw-r--r-- | spec/bundler/support/helpers.rb | 8 | ||||
-rw-r--r-- | spec/bundler/support/rubygems_ext.rb | 20 |
8 files changed, 122 insertions, 46 deletions
diff --git a/spec/bundler/bundler/installer/gem_installer_spec.rb b/spec/bundler/bundler/installer/gem_installer_spec.rb index 8f8d1c6d15..14a6a19a86 100644 --- a/spec/bundler/bundler/installer/gem_installer_spec.rb +++ b/spec/bundler/bundler/installer/gem_installer_spec.rb @@ -3,7 +3,8 @@ require "bundler/installer/gem_installer" RSpec.describe Bundler::GemInstaller do - let(:installer) { instance_double("Installer") } + let(:definition) { instance_double("Definition", :locked_gems => nil) } + let(:installer) { instance_double("Installer", :definition => definition) } let(:spec_source) { instance_double("SpecSource") } let(:spec) { instance_double("Specification", :name => "dummy", :version => "0.0.1", :loaded_from => "dummy", :source => spec_source) } @@ -11,7 +12,7 @@ RSpec.describe Bundler::GemInstaller do context "spec_settings is nil" do it "invokes install method with empty build_args" do - allow(spec_source).to receive(:install).with(spec, :force => false, :ensure_builtin_gems_cached => false, :build_args => []) + allow(spec_source).to receive(:install).with(spec, :force => false, :ensure_builtin_gems_cached => false, :build_args => [], :previous_spec => nil) subject.install_from_spec end end @@ -22,7 +23,7 @@ RSpec.describe Bundler::GemInstaller do allow(Bundler.settings).to receive(:[]).with(:inline) allow(Bundler.settings).to receive(:[]).with(:forget_cli_options) allow(Bundler.settings).to receive(:[]).with("build.dummy").and_return("--with-dummy-config=dummy") - expect(spec_source).to receive(:install).with(spec, :force => false, :ensure_builtin_gems_cached => false, :build_args => ["--with-dummy-config=dummy"]) + expect(spec_source).to receive(:install).with(spec, :force => false, :ensure_builtin_gems_cached => false, :build_args => ["--with-dummy-config=dummy"], :previous_spec => nil) subject.install_from_spec end end @@ -33,7 +34,13 @@ RSpec.describe Bundler::GemInstaller do allow(Bundler.settings).to receive(:[]).with(:inline) allow(Bundler.settings).to receive(:[]).with(:forget_cli_options) allow(Bundler.settings).to receive(:[]).with("build.dummy").and_return("--with-dummy-config=dummy --with-another-dummy-config") - expect(spec_source).to receive(:install).with(spec, :force => false, :ensure_builtin_gems_cached => false, :build_args => ["--with-dummy-config=dummy", "--with-another-dummy-config"]) + expect(spec_source).to receive(:install).with( + spec, + :force => false, + :ensure_builtin_gems_cached => false, + :build_args => ["--with-dummy-config=dummy", "--with-another-dummy-config"], + :previous_spec => nil + ) subject.install_from_spec end end diff --git a/spec/bundler/bundler/source_spec.rb b/spec/bundler/bundler/source_spec.rb index af370bb45c..ceb369ecdb 100644 --- a/spec/bundler/bundler/source_spec.rb +++ b/spec/bundler/bundler/source_spec.rb @@ -30,17 +30,7 @@ RSpec.describe Bundler::Source do end context "when there are locked gems" do - let(:locked_gems) { double(:locked_gems) } - - before { allow(Bundler).to receive(:locked_gems).and_return(locked_gems) } - context "that contain the relevant gem spec" do - before do - specs = double(:specs) - allow(locked_gems).to receive(:specs).and_return(specs) - allow(specs).to receive(:find).and_return(locked_gem) - end - context "without a version" do let(:locked_gem) { double(:locked_gem, :name => "nokogiri", :version => nil) } @@ -62,7 +52,7 @@ RSpec.describe Bundler::Source do end it "should return a string with the spec name and version and locked spec version" do - expect(subject.version_message(spec)).to eq("nokogiri >= 1.6\e[32m (was < 1.5)\e[0m") + expect(subject.version_message(spec, locked_gem)).to eq("nokogiri >= 1.6\e[32m (was < 1.5)\e[0m") end end @@ -74,7 +64,7 @@ RSpec.describe Bundler::Source do end it "should return a string with the spec name and version and locked spec version" do - expect(subject.version_message(spec)).to eq("nokogiri >= 1.6 (was < 1.5)") + expect(subject.version_message(spec, locked_gem)).to eq("nokogiri >= 1.6 (was < 1.5)") end end end @@ -89,7 +79,7 @@ RSpec.describe Bundler::Source do end it "should return a string with the locked spec version in yellow" do - expect(subject.version_message(spec)).to eq("nokogiri 1.6.1\e[33m (was 1.7.0)\e[0m") + expect(subject.version_message(spec, locked_gem)).to eq("nokogiri 1.6.1\e[33m (was 1.7.0)\e[0m") end end @@ -101,7 +91,7 @@ RSpec.describe Bundler::Source do end it "should return a string with the locked spec version in yellow" do - expect(subject.version_message(spec)).to eq("nokogiri 1.6.1 (was 1.7.0)") + expect(subject.version_message(spec, locked_gem)).to eq("nokogiri 1.6.1 (was 1.7.0)") end end end @@ -116,7 +106,7 @@ RSpec.describe Bundler::Source do end it "should return a string with the locked spec version in green" do - expect(subject.version_message(spec)).to eq("nokogiri 1.7.1\e[32m (was 1.7.0)\e[0m") + expect(subject.version_message(spec, locked_gem)).to eq("nokogiri 1.7.1\e[32m (was 1.7.0)\e[0m") end end @@ -128,27 +118,11 @@ RSpec.describe Bundler::Source do end it "should return a string with the locked spec version in yellow" do - expect(subject.version_message(spec)).to eq("nokogiri 1.7.1 (was 1.7.0)") + expect(subject.version_message(spec, locked_gem)).to eq("nokogiri 1.7.1 (was 1.7.0)") end end end end - - context "that do not contain the relevant gem spec" do - before do - specs = double(:specs) - allow(locked_gems).to receive(:specs).and_return(specs) - allow(specs).to receive(:find).and_return(nil) - end - - it_behaves_like "the lockfile specs are not relevant" - end - end - - context "when there are no locked gems" do - before { allow(Bundler).to receive(:locked_gems).and_return(nil) } - - it_behaves_like "the lockfile specs are not relevant" end end diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb index 9c5240157f..11f96315ca 100644 --- a/spec/bundler/commands/lock_spec.rb +++ b/spec/bundler/commands/lock_spec.rb @@ -493,27 +493,25 @@ RSpec.describe "bundle lock" do end it "does not conflict on ruby requirements when adding new platforms" do - next_minor = Gem.ruby_version.segments[0..1].map.with_index {|s, i| i == 1 ? s + 1 : s }.join(".") - build_repo4 do build_gem "raygun-apm", "1.0.78" do |s| s.platform = "x86_64-linux" - s.required_ruby_version = "< #{next_minor}.dev" + s.required_ruby_version = "< #{next_ruby_minor}.dev" end build_gem "raygun-apm", "1.0.78" do |s| s.platform = "universal-darwin" - s.required_ruby_version = "< #{next_minor}.dev" + s.required_ruby_version = "< #{next_ruby_minor}.dev" end build_gem "raygun-apm", "1.0.78" do |s| s.platform = "x64-mingw32" - s.required_ruby_version = "< #{next_minor}.dev" + s.required_ruby_version = "< #{next_ruby_minor}.dev" end build_gem "raygun-apm", "1.0.78" do |s| s.platform = "x64-mingw-ucrt" - s.required_ruby_version = "< #{next_minor}.dev" + s.required_ruby_version = "< #{next_ruby_minor}.dev" end end diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb index 83f1e60806..469ecd412f 100644 --- a/spec/bundler/install/gems/resolving_spec.rb +++ b/spec/bundler/install/gems/resolving_spec.rb @@ -245,6 +245,43 @@ RSpec.describe "bundle install with install-time dependencies" do expect(the_bundle).to include_gems("rack 1.2") end + it "gives a meaningful error if there's a lockfile using the newer incompatible version" do + build_repo2 do + build_gem "parallel_tests", "3.7.0" do |s| + s.required_ruby_version = ">= #{current_ruby_minor}" + end + + build_gem "parallel_tests", "3.8.0" do |s| + s.required_ruby_version = ">= #{next_ruby_minor}" + end + end + + gemfile <<-G + source "http://localgemserver.test/" + gem 'parallel_tests' + G + + lockfile <<~L + GEM + remote: http://localgemserver.test/ + specs: + parallel_tests (3.8.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + parallel_tests + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "install --verbose", :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }, :raise_on_error => false + expect(err).to include("parallel_tests-3.8.0 requires ruby version >= #{next_ruby_minor}") + expect(err).not_to include("That means the author of parallel_tests (3.8.0) has removed it.") + end + it "installs the older version under rate limiting conditions" do build_repo4 do build_gem "rack", "9001.0.0" do |s| diff --git a/spec/bundler/install/yanked_spec.rb b/spec/bundler/install/yanked_spec.rb index c5f3d788ba..b53c15be69 100644 --- a/spec/bundler/install/yanked_spec.rb +++ b/spec/bundler/install/yanked_spec.rb @@ -66,7 +66,7 @@ RSpec.context "when using gem before installing" do bundle :list, :raise_on_error => false expect(err).to include("Could not find rack-0.9.1 in any of the sources") - expect(err).to_not include("Your bundle is locked to rack (0.9.1), but that version could not be found in any of the sources listed in your Gemfile.") + expect(err).to_not include("Your bundle is locked to rack (0.9.1) from") expect(err).to_not include("If you haven't changed sources, that means the author of rack (0.9.1) has removed it.") expect(err).to_not include("You'll need to update your bundle to a different version of rack (0.9.1) that hasn't been removed in order to install.") end @@ -97,7 +97,7 @@ RSpec.context "when using gem before installing" do expect(err).to include("Could not find rack-0.9.1, rack_middleware-1.0 in any of the sources") expect(err).to include("Install missing gems with `bundle install`.") - expect(err).to_not include("Your bundle is locked to rack (0.9.1), but that version could not be found in any of the sources listed in your Gemfile.") + expect(err).to_not include("Your bundle is locked to rack (0.9.1) from") expect(err).to_not include("If you haven't changed sources, that means the author of rack (0.9.1) has removed it.") expect(err).to_not include("You'll need to update your bundle to a different version of rack (0.9.1) that hasn't been removed in order to install.") end diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index 24df758619..dd22c86f90 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -89,7 +89,7 @@ RSpec.describe "bundler/inline#gemfile" do expect(out).to include("Installing activesupport") err_lines = err.split("\n") - err_lines.reject!{|line| line =~ /\.rb:\d+: warning: / } unless RUBY_VERSION < "2.7" + err_lines.reject! {|line| line =~ /\.rb:\d+: warning: / } unless RUBY_VERSION < "2.7" expect(err_lines).to be_empty end @@ -239,6 +239,40 @@ RSpec.describe "bundler/inline#gemfile" do expect(err).to be_empty end + it "does not leak Gemfile.lock versions to the installation output" do + gemfile <<-G + source "https://notaserver.com" + gem "rake" + G + + lockfile <<-G + GEM + remote: https://rubygems.org/ + specs: + rake (11.3.0) + + PLATFORMS + ruby + + DEPENDENCIES + rake + + BUNDLED WITH + #{Bundler::VERSION} + G + + script <<-RUBY + gemfile(true) do + source "#{file_uri_for(gem_repo1)}" + gem "rake", "~> 13.0" + end + RUBY + + expect(out).to include("Installing rake 13.0") + expect(out).not_to include("was 11.3.0") + expect(err).to be_empty + end + it "installs inline gems when frozen is set" do script <<-RUBY, :env => { "BUNDLE_FROZEN" => "true" } gemfile do diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index d7556102b4..e995418a4e 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -471,6 +471,14 @@ module Spec end end + def current_ruby_minor + Gem.ruby_version.segments[0..1].join(".") + end + + def next_ruby_minor + Gem.ruby_version.segments[0..1].map.with_index {|s, i| i == 1 ? s + 1 : s }.join(".") + end + # versions providing a bundler version finder but not including # https://github.com/rubygems/rubygems/commit/929e92d752baad3a08f3ac92eaec162cb96aedd1 def rubygems_version_failing_to_activate_bundler_prereleases diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index fd5f06b14f..eb7e321080 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -18,6 +18,12 @@ module Spec gem_load_and_activate(gem_name, bin_container) end + def gem_load_and_possibly_install(gem_name, bin_container) + require_relative "switch_rubygems" + + gem_load_activate_and_possibly_install(gem_name, bin_container) + end + def gem_require(gem_name) gem_activate(gem_name) require gem_name @@ -99,9 +105,21 @@ module Spec abort "We couldn't activate #{gem_name} (#{e.requirement}). Run `gem install #{gem_name}:'#{e.requirement}'`" end + def gem_load_activate_and_possibly_install(gem_name, bin_container) + gem_activate_and_possibly_install(gem_name) + load Gem.bin_path(gem_name, bin_container) + end + + def gem_activate_and_possibly_install(gem_name) + gem_activate(gem_name) + rescue Gem::LoadError => e + Gem.install(gem_name, e.requirement) + retry + end + def gem_activate(gem_name) require "bundler" - gem_requirement = Bundler::LockfileParser.new(File.read(dev_lockfile)).dependencies[gem_name]&.requirement + gem_requirement = Bundler::LockfileParser.new(File.read(dev_lockfile)).specs.find {|spec| spec.name == gem_name }.version gem gem_name, gem_requirement end |