From 896bbb9fadd10e1ad06ff3fd7d0608acda01ac06 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 13 Jul 2021 20:58:08 +0900 Subject: Merge RubyGems/Bundler master from 8459ebd6ad65ce3397233416dc64083ae7572bb9 --- spec/bundler/bundler/bundler_spec.rb | 21 ++--- spec/bundler/bundler/settings_spec.rb | 9 +- spec/bundler/commands/check_spec.rb | 28 +++++++ spec/bundler/commands/exec_spec.rb | 10 +++ spec/bundler/commands/install_spec.rb | 96 +++++++++++++--------- spec/bundler/commands/newgem_spec.rb | 12 +-- .../install/gemfile/specific_platform_spec.rb | 32 ++++++++ spec/bundler/plugins/install_spec.rb | 7 ++ spec/bundler/realworld/edgecases_spec.rb | 15 ---- spec/bundler/runtime/setup_spec.rb | 19 +++++ spec/bundler/support/artifice/vcr.rb | 13 +++ spec/bundler/support/hax.rb | 4 + 12 files changed, 185 insertions(+), 81 deletions(-) (limited to 'spec/bundler') diff --git a/spec/bundler/bundler/bundler_spec.rb b/spec/bundler/bundler/bundler_spec.rb index 56ef4ce75a..d164b5d3c6 100644 --- a/spec/bundler/bundler/bundler_spec.rb +++ b/spec/bundler/bundler/bundler_spec.rb @@ -249,11 +249,8 @@ EOF allow(Bundler.rubygems).to receive(:user_home).and_return(path) allow(File).to receive(:directory?).with(path).and_return false allow(Bundler).to receive(:tmp).and_return(Pathname.new("/tmp/trulyrandom")) - message = <= 1.0" + end + build_gem "also_depends_on_rack" do |s| + s.add_dependency "rack", "~> 1.0" + end + build_gem "rack" + end + + gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem "depends_on_rack" + gem "also_depends_on_rack" + G + + bundle "lock" + end + + it "shows what is missing with the current Gemfile without duplications" do + bundle :check, :raise_on_error => false + expect(err).to match(/The following gems are missing/) + expect(err).to include("* rack (1.0").once + end + end + describe "when using only scoped rubygems sources" do before do gemfile <<~G diff --git a/spec/bundler/commands/exec_spec.rb b/spec/bundler/commands/exec_spec.rb index 0d104ad304..39430d52a4 100644 --- a/spec/bundler/commands/exec_spec.rb +++ b/spec/bundler/commands/exec_spec.rb @@ -24,6 +24,16 @@ RSpec.describe "bundle exec" do expect(out).to eq("0.9.1") end + it "works and prints no warnings when HOME is not writable" do + gemfile <<-G + gem "rack", "0.9.1" + G + + bundle "exec rackup", :env => { "HOME" => "/" } + expect(out).to eq("0.9.1") + expect(err).to be_empty + end + it "works when the bins are in ~/.bundle" do install_gemfile <<-G gem "rack" diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index c91864dbb8..3c0c35d844 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -344,54 +344,72 @@ RSpec.describe "bundle install with gem sources" do expect(File.exist?(bundled_app_lock)).to eq(true) end - context "throws a warning if a gem is added twice in Gemfile" do - it "without version requirements" do - install_gemfile <<-G, :raise_on_error => false - source "#{file_uri_for(gem_repo2)}" - gem "rack" - gem "rack" - G + it "throws a warning if a gem is added twice in Gemfile without version requirements" do + install_gemfile <<-G, :raise_on_error => false + source "#{file_uri_for(gem_repo2)}" + gem "rack" + gem "rack" + G - expect(err).to include("Your Gemfile lists the gem rack (>= 0) more than once.") - expect(err).to include("Remove any duplicate entries and specify the gem only once.") - expect(err).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.") - end + expect(err).to include("Your Gemfile lists the gem rack (>= 0) more than once.") + expect(err).to include("Remove any duplicate entries and specify the gem only once.") + expect(err).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.") + end - it "with same versions" do - install_gemfile <<-G, :raise_on_error => false - source "#{file_uri_for(gem_repo2)}" - gem "rack", "1.0" - gem "rack", "1.0" - G + it "throws a warning if a gem is added twice in Gemfile with same versions" do + install_gemfile <<-G, :raise_on_error => false + source "#{file_uri_for(gem_repo2)}" + gem "rack", "1.0" + gem "rack", "1.0" + G - expect(err).to include("Your Gemfile lists the gem rack (= 1.0) more than once.") - expect(err).to include("Remove any duplicate entries and specify the gem only once.") - expect(err).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.") - end + expect(err).to include("Your Gemfile lists the gem rack (= 1.0) more than once.") + expect(err).to include("Remove any duplicate entries and specify the gem only once.") + expect(err).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.") end - context "throws an error if a gem is added twice in Gemfile" do - it "when version of one dependency is not specified" do - install_gemfile <<-G, :raise_on_error => false - source "#{file_uri_for(gem_repo2)}" - gem "rack" - gem "rack", "1.0" - G + it "does not throw a warning if a gem is added once in Gemfile and also inside a gemspec as a development dependency" do + build_lib "my-gem", :path => bundled_app do |s| + s.add_development_dependency "my-private-gem" + end - expect(err).to include("You cannot specify the same gem twice with different version requirements") - expect(err).to include("You specified: rack (>= 0) and rack (= 1.0).") + build_repo2 do + build_gem "my-private-gem" end - it "when different versions of both dependencies are specified" do - install_gemfile <<-G, :raise_on_error => false - source "#{file_uri_for(gem_repo2)}" - gem "rack", "1.0" - gem "rack", "1.1" - G + gemfile <<~G + source "#{file_uri_for(gem_repo2)}" - expect(err).to include("You cannot specify the same gem twice with different version requirements") - expect(err).to include("You specified: rack (= 1.0) and rack (= 1.1).") - end + gemspec + + gem "my-private-gem", :group => :development + G + + bundle :install + + expect(err).to be_empty + end + + it "throws an error if a gem is added twice in Gemfile when version of one dependency is not specified" do + install_gemfile <<-G, :raise_on_error => false + source "#{file_uri_for(gem_repo2)}" + gem "rack" + gem "rack", "1.0" + G + + expect(err).to include("You cannot specify the same gem twice with different version requirements") + expect(err).to include("You specified: rack (>= 0) and rack (= 1.0).") + end + + it "throws an error if a gem is added twice in Gemfile when different versions of both dependencies are specified" do + install_gemfile <<-G, :raise_on_error => false + source "#{file_uri_for(gem_repo2)}" + gem "rack", "1.0" + gem "rack", "1.1" + G + + expect(err).to include("You cannot specify the same gem twice with different version requirements") + expect(err).to include("You specified: rack (= 1.0) and rack (= 1.1).") end it "gracefully handles error when rubygems server is unavailable" do diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index 00bd009c5a..56fea008ec 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -307,42 +307,42 @@ RSpec.describe "bundle gem" do skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? bundle "gem #{gem_name} --linter=rubocop" bundle_exec_rubocop - expect(err).to be_empty + expect(last_command).to be_success end it "has no rubocop offenses when using --ext and --linter=rubocop flag", :readline do skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? bundle "gem #{gem_name} --ext --linter=rubocop" bundle_exec_rubocop - expect(err).to be_empty + expect(last_command).to be_success end it "has no rubocop offenses when using --ext, --test=minitest, and --linter=rubocop flag", :readline do skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? bundle "gem #{gem_name} --ext --test=minitest --linter=rubocop" bundle_exec_rubocop - expect(err).to be_empty + expect(last_command).to be_success end it "has no rubocop offenses when using --ext, --test=rspec, and --linter=rubocop flag", :readline do skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? bundle "gem #{gem_name} --ext --test=rspec --linter=rubocop" bundle_exec_rubocop - expect(err).to be_empty + expect(last_command).to be_success end it "has no rubocop offenses when using --ext, --ext=test-unit, and --linter=rubocop flag", :readline do skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? bundle "gem #{gem_name} --ext --test=test-unit --linter=rubocop" bundle_exec_rubocop - expect(err).to be_empty + expect(last_command).to be_success end it "has no standard offenses when using --linter=standard flag", :readline do skip "ruby_core has an 'ast.rb' file that gets in the middle and breaks this spec" if ruby_core? bundle "gem #{gem_name} --linter=standard" bundle_exec_standardrb - expect(err).to be_empty + expect(last_command).to be_success end shared_examples_for "CI config is absent" do diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb index c6e526a95e..a6d8318fe4 100644 --- a/spec/bundler/install/gemfile/specific_platform_spec.rb +++ b/spec/bundler/install/gemfile/specific_platform_spec.rb @@ -249,6 +249,38 @@ RSpec.describe "bundle install with specific platforms" do end end + it "installs sorbet-static, which does not provide a pure ruby variant, just fine on truffleruby", :truffleruby do + build_repo2 do + build_gem("sorbet-static", "0.5.6403") {|s| s.platform = "x86_64-linux" } + build_gem("sorbet-static", "0.5.6403") {|s| s.platform = "universal-darwin-20" } + end + + gemfile <<~G + source "#{file_uri_for(gem_repo2)}" + + gem "sorbet-static", "0.5.6403" + G + + lockfile <<~L + GEM + remote: #{file_uri_for(gem_repo2)}/ + specs: + sorbet-static (0.5.6403-universal-darwin-20) + sorbet-static (0.5.6403-x86_64-linux) + + PLATFORMS + ruby + + DEPENDENCIES + sorbet-static (= 0.5.6403) + + BUNDLED WITH + #{Bundler::VERSION} + L + + bundle "install --verbose" + end + private def setup_multiplatform_gem diff --git a/spec/bundler/plugins/install_spec.rb b/spec/bundler/plugins/install_spec.rb index 308f9c79fc..2175610b10 100644 --- a/spec/bundler/plugins/install_spec.rb +++ b/spec/bundler/plugins/install_spec.rb @@ -22,6 +22,13 @@ RSpec.describe "bundler plugin install" do plugin_should_be_installed("foo") end + it "installs from sources configured as Gem.sources without any flags" do + bundle "plugin install foo", :env => { "BUNDLER_SPEC_GEM_SOURCES" => file_uri_for(gem_repo2).to_s } + + expect(out).to include("Installed plugin foo") + plugin_should_be_installed("foo") + end + context "plugin is already installed" do before do bundle "plugin install foo --source #{file_uri_for(gem_repo2)}" diff --git a/spec/bundler/realworld/edgecases_spec.rb b/spec/bundler/realworld/edgecases_spec.rb index 556a11d2f3..f031e2f354 100644 --- a/spec/bundler/realworld/edgecases_spec.rb +++ b/spec/bundler/realworld/edgecases_spec.rb @@ -196,21 +196,6 @@ RSpec.describe "real world edgecases", :realworld => true do expect(lockfile).to include(rubygems_version("paperclip", "~> 5.1.0")) end - # https://github.com/rubygems/bundler/issues/1500 - it "does not fail install because of gem plugins" do - realworld_system_gems("open_gem --version 1.4.2", "rake --version 0.9.2") - gemfile <<-G - source "https://rubygems.org" - - gem 'rack', '1.0.1' - G - - bundle "config set --local path vendor/bundle" - bundle :install - expect(err).not_to include("Could not find rake") - expect(err).to be_empty - end - it "outputs a helpful error message when gems have invalid gemspecs" do install_gemfile <<-G, :standalone => true, :raise_on_error => false source 'https://rubygems.org' diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index d8ba569f0a..380db99136 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -644,6 +644,25 @@ RSpec.describe "Bundler.setup" do expect(err).to be_empty end + it "doesn't re-resolve when a pre-release bundler is used and a dependency includes a dependency on bundler" do + system_gems "bundler-9.99.9.beta1" + + build_repo4 do + build_gem "depends_on_bundler", "1.0" do |s| + s.add_dependency "bundler", ">= 1.5.0" + end + end + + install_gemfile <<~G + source "#{file_uri_for(gem_repo4)}" + gem "depends_on_bundler" + G + + ruby "require '#{system_gem_path("gems/bundler-9.99.9.beta1/lib/bundler.rb")}'; Bundler.setup", :env => { "DEBUG" => "1" } + expect(out).to include("Found no changes, using resolution from the lockfile") + expect(err).to be_empty + end + it "remembers --without and does not include groups passed to Bundler.setup" do bundle "config set --local without rails" install_gemfile <<-G diff --git a/spec/bundler/support/artifice/vcr.rb b/spec/bundler/support/artifice/vcr.rb index 88c33d93dc..0d51201bef 100644 --- a/spec/bundler/support/artifice/vcr.rb +++ b/spec/bundler/support/artifice/vcr.rb @@ -133,6 +133,19 @@ class BundlerVCRHTTP < Net::HTTP end end + def start_with_vcr + if ENV["BUNDLER_SPEC_PRE_RECORDED"] + raise IOError, "HTTP session already opened" if @started + @socket = nil + @started = true + else + start_without_vcr + end + end + + alias_method :start_without_vcr, :start + alias_method :start, :start_with_vcr + def request_with_vcr(request, *args, &block) handler = request.instance_eval do remove_instance_variable(:@__vcr_request_handler) if defined?(@__vcr_request_handler) diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb index ddb62f7d53..aaf8c74894 100644 --- a/spec/bundler/support/hax.rb +++ b/spec/bundler/support/hax.rb @@ -28,6 +28,10 @@ module Gem end end + if ENV["BUNDLER_SPEC_GEM_SOURCES"] + @sources = [ENV["BUNDLER_SPEC_GEM_SOURCES"]] + end + # We only need this hack for rubygems versions without the BundlerVersionFinder if Gem.rubygems_version < Gem::Version.new("2.7.0") @path_to_default_spec_map.delete_if do |_path, spec| -- cgit v1.2.3