diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-02-02 16:57:34 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 16:57:34 +0900 |
commit | 6794f8cf928ab8c009b301ec49a5a81e97e6eb2f (patch) | |
tree | 63f83daf2d1d2f57d6aaee9efa01e1c91ee8b021 /spec | |
parent | 69463805f0722d90a2049f43e852539b4532bf2e (diff) |
Merge pull request #5482 from hsbt/rubygems-3-3-bundler-2-3
Merge RubyGems 3.3.x and Bundler 2.3.x
Diffstat (limited to 'spec')
28 files changed, 553 insertions, 220 deletions
diff --git a/spec/bundler/bundler/cli_spec.rb b/spec/bundler/bundler/cli_spec.rb index c5de12c211..28ade90138 100644 --- a/spec/bundler/bundler/cli_spec.rb +++ b/spec/bundler/bundler/cli_spec.rb @@ -170,7 +170,7 @@ RSpec.describe "bundle executable" do bundle "fail", :env => { "BUNDLER_VERSION" => bundler_version }, :raise_on_error => false expect(err).to start_with(<<-EOS.strip) The latest bundler is #{latest_version}, but you are currently running #{bundler_version}. -To install the latest version, run `gem install bundler` +To update to the most recent version, run `bundle update --bundler` EOS end @@ -195,7 +195,7 @@ To install the latest version, run `gem install bundler` bundle "fail", :env => { "BUNDLER_VERSION" => bundler_version }, :raise_on_error => false expect(err).to start_with(<<-EOS.strip) The latest bundler is #{latest_version}, but you are currently running #{bundler_version}. -To install the latest version, run `gem install bundler --pre` +To update to the most recent version, run `bundle update --bundler` EOS end end diff --git a/spec/bundler/bundler/endpoint_specification_spec.rb b/spec/bundler/bundler/endpoint_specification_spec.rb index 2e2c16ec44..02a90d507a 100644 --- a/spec/bundler/bundler/endpoint_specification_spec.rb +++ b/spec/bundler/bundler/endpoint_specification_spec.rb @@ -5,9 +5,10 @@ RSpec.describe Bundler::EndpointSpecification do let(:version) { "1.0.0" } let(:platform) { Gem::Platform::RUBY } let(:dependencies) { [] } + let(:spec_fetcher) { double(:spec_fetcher) } let(:metadata) { nil } - subject(:spec) { described_class.new(name, version, platform, dependencies, metadata) } + subject(:spec) { described_class.new(name, version, platform, spec_fetcher, dependencies, metadata) } describe "#build_dependency" do let(:name) { "foo" } @@ -48,7 +49,9 @@ RSpec.describe Bundler::EndpointSpecification do end it "supports equality comparison" do - other_spec = described_class.new("bar", version, platform, dependencies, metadata) + remote_spec = double(:remote_spec, :required_ruby_version => nil, :required_rubygems_version => nil) + allow(spec_fetcher).to receive(:fetch_spec).and_return(remote_spec) + other_spec = described_class.new("bar", version, platform, spec_fetcher, dependencies, metadata) expect(spec).to eql(spec) expect(spec).to_not eql(other_spec) end diff --git a/spec/bundler/bundler/gem_helper_spec.rb b/spec/bundler/bundler/gem_helper_spec.rb index 2c43719aa1..5cd79de620 100644 --- a/spec/bundler/bundler/gem_helper_spec.rb +++ b/spec/bundler/bundler/gem_helper_spec.rb @@ -66,6 +66,10 @@ RSpec.describe Bundler::GemHelper do mock_confirm_message message end + def sha512_hexdigest(path) + Digest::SHA512.file(path).hexdigest + end + subject! { Bundler::GemHelper.new(app_path) } let(:app_version) { "0.1.0" } let(:app_gem_dir) { app_path.join("pkg") } @@ -169,12 +173,21 @@ RSpec.describe Bundler::GemHelper do end describe "#build_checksum" do + it "calculates SHA512 of the content" do + FileUtils.mkdir_p(app_gem_dir) + File.write(app_gem_path, "") + mock_checksum_message app_name, app_version + subject.build_checksum(app_gem_path) + expect(File.read(app_sha_path).chomp).to eql(Digest::SHA512.hexdigest("")) + end + context "when build was successful" do it "creates .sha512 file" do mock_build_message app_name, app_version mock_checksum_message app_name, app_version subject.build_checksum expect(app_sha_path).to exist + expect(File.read(app_sha_path).chomp).to eql(sha512_hexdigest(app_gem_path)) end end context "when building in the current working directory" do @@ -185,6 +198,7 @@ RSpec.describe Bundler::GemHelper do Bundler::GemHelper.new.build_checksum end expect(app_sha_path).to exist + expect(File.read(app_sha_path).chomp).to eql(sha512_hexdigest(app_gem_path)) end end context "when building in a location relative to the current working directory" do @@ -195,6 +209,7 @@ RSpec.describe Bundler::GemHelper do Bundler::GemHelper.new(File.basename(app_path)).build_checksum end expect(app_sha_path).to exist + expect(File.read(app_sha_path).chomp).to eql(sha512_hexdigest(app_gem_path)) end end end diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb index ceef07d36b..198226207b 100644 --- a/spec/bundler/commands/binstubs_spec.rb +++ b/spec/bundler/commands/binstubs_spec.rb @@ -182,30 +182,26 @@ RSpec.describe "bundle binstubs <gem>" do end context "and the version is older and the same major" do - let(:system_bundler_version) { "55.1" } + let(:system_bundler_version) { "2.999.999" } before do - lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 55.0") - - update_repo2 do - with_built_bundler("55.0") {|gem_path| FileUtils.mv(gem_path, gem_repo2("gems")) } - end + lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 2.3.0") end it "installs and runs the exact version of bundler", :rubygems => ">= 3.3.0.dev" do - sys_exec "bin/bundle install --verbose", :env => { "BUNDLER_SPEC_GEM_SOURCES" => file_uri_for(gem_repo2).to_s, "RUBYOPT" => "-r#{spec_dir}/support/hax.rb" } + sys_exec "bin/bundle install --verbose", :artifice => "vcr" expect(exitstatus).not_to eq(42) - expect(out).to include("Bundler 55.1 is running, but your lockfile was generated with 55.0. Installing Bundler 55.0 and restarting using that version.") - expect(out).to include("Using bundler 55.0") - expect(err).not_to include("Activating bundler (~> 55.0) failed:") + expect(out).to include("Bundler 2.999.999 is running, but your lockfile was generated with 2.3.0. Installing Bundler 2.3.0 and restarting using that version.") + expect(out).to include("Using bundler 2.3.0") + expect(err).not_to include("Activating bundler (~> 2.3.0) failed:") end it "runs the available version of bundler", :rubygems => "< 3.3.0.dev" do sys_exec "bin/bundle install --verbose" expect(exitstatus).not_to eq(42) - expect(out).not_to include("Bundler 55.1 is running, but your lockfile was generated with 55.0. Installing Bundler 55.0 and restarting using that version.") - expect(out).to include("Using bundler 55.1") - expect(err).not_to include("Activating bundler (~> 55.0) failed:") + expect(out).not_to include("Bundler 2.999.999 is running, but your lockfile was generated with 2.3.0. Installing Bundler 2.3.0 and restarting using that version.") + expect(out).to include("Using bundler 2.999.999") + expect(err).not_to include("Activating bundler (~> 2.3.0) failed:") end end diff --git a/spec/bundler/commands/cache_spec.rb b/spec/bundler/commands/cache_spec.rb index 4f9c1c26c4..356a658e7c 100644 --- a/spec/bundler/commands/cache_spec.rb +++ b/spec/bundler/commands/cache_spec.rb @@ -403,14 +403,14 @@ RSpec.describe "bundle install with gem sources" do simulate_new_machine - simulate_platform "ruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "platform_specific" - G - run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" - expect(out).to eq("1.0.0 RUBY") - end + bundle "config set --local force_ruby_platform true" + + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "platform_specific" + G + run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" + expect(out).to eq("1.0.0 RUBY") end it "does not update the cache if --no-cache is passed" do diff --git a/spec/bundler/commands/doctor_spec.rb b/spec/bundler/commands/doctor_spec.rb index 860b638f06..1eeb276105 100644 --- a/spec/bundler/commands/doctor_spec.rb +++ b/spec/bundler/commands/doctor_spec.rb @@ -49,8 +49,8 @@ RSpec.describe "bundle doctor" do doctor = Bundler::CLI::Doctor.new({}) expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/rack/rack.bundle"] expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/lib/libSystem.dylib"] - allow(File).to receive(:exist?).with("/usr/lib/libSystem.dylib").and_return(true) - expect { doctor.run }.not_to(raise_error, @stdout.string) + allow(Fiddle).to receive(:dlopen).with("/usr/lib/libSystem.dylib").and_return(true) + expect { doctor.run }.not_to raise_error expect(@stdout.string).to be_empty end @@ -58,7 +58,7 @@ RSpec.describe "bundle doctor" do doctor = Bundler::CLI::Doctor.new({}) expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/rack/rack.bundle"] expect(doctor).to receive(:dylibs).exactly(2).times.and_return ["/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib"] - allow(File).to receive(:exist?).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_return(false) + allow(Fiddle).to receive(:dlopen).with("/usr/local/opt/icu4c/lib/libicui18n.57.1.dylib").and_raise(Fiddle::DLError) expect { doctor.run }.to raise_error(Bundler::ProductionError, strip_whitespace(<<-E).strip), @stdout.string The following gems are missing OS dependencies: * bundler: /usr/local/opt/icu4c/lib/libicui18n.57.1.dylib diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index e00caa5315..ec1d9bcd02 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -499,20 +499,17 @@ RSpec.describe "bundle install with gem sources" do context "and using an unsupported Ruby version" do it "prints an error" do install_gemfile <<-G, :raise_on_error => false - ::RUBY_VERSION = '2.0.1' - ruby '~> 2.2' + ruby '~> 1.2' source "#{file_uri_for(gem_repo1)}" G - expect(err).to include("Your Ruby version is 2.0.1, but your Gemfile specified ~> 2.2") + expect(err).to include("Your Ruby version is #{RUBY_VERSION}, but your Gemfile specified ~> 1.2") end end context "and using a supported Ruby version" do before do install_gemfile <<-G - ::RUBY_VERSION = '2.1.3' - ::RUBY_PATCHLEVEL = 100 - ruby '~> 2.1.0' + ruby '~> #{RUBY_VERSION}' source "#{file_uri_for(gem_repo1)}" G end @@ -529,18 +526,16 @@ RSpec.describe "bundle install with gem sources" do DEPENDENCIES RUBY VERSION - ruby 2.1.3p100 + #{Bundler::RubyVersion.system} BUNDLED WITH #{Bundler::VERSION} L end - it "updates Gemfile.lock with updated incompatible ruby version" do + it "updates Gemfile.lock with updated yet still compatible ruby version" do install_gemfile <<-G - ::RUBY_VERSION = '2.2.3' - ::RUBY_PATCHLEVEL = 100 - ruby '~> 2.2.0' + ruby '~> #{RUBY_VERSION[0..2]}' source "#{file_uri_for(gem_repo1)}" G @@ -555,7 +550,7 @@ RSpec.describe "bundle install with gem sources" do DEPENDENCIES RUBY VERSION - ruby 2.2.3p100 + #{Bundler::RubyVersion.system} BUNDLED WITH #{Bundler::VERSION} diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb index 22709f4528..fd1446af0e 100644 --- a/spec/bundler/commands/lock_spec.rb +++ b/spec/bundler/commands/lock_spec.rb @@ -337,7 +337,8 @@ RSpec.describe "bundle lock" do #{Bundler::VERSION} G - simulate_platform(rb) { bundle :lock } + bundle "config set --local force_ruby_platform true" + bundle :lock expect(lockfile).to eq <<~G GEM diff --git a/spec/bundler/commands/newgem_spec.rb b/spec/bundler/commands/newgem_spec.rb index ddefe0ba25..55a04b69c5 100644 --- a/spec/bundler/commands/newgem_spec.rb +++ b/spec/bundler/commands/newgem_spec.rb @@ -28,6 +28,10 @@ RSpec.describe "bundle gem" do let(:require_path) { "mygem" } + let(:minitest_test_file_path) { "test/test_mygem.rb" } + + let(:minitest_test_class_name) { "class TestMygem < Minitest::Test" } + before do sys_exec("git config --global user.name 'Bundler User'") sys_exec("git config --global user.email user@example.com") @@ -702,7 +706,7 @@ RSpec.describe "bundle gem" do end it "builds spec skeleton" do - expect(bundled_app("#{gem_name}/test/test_#{require_path}.rb")).to exist + expect(bundled_app("#{gem_name}/#{minitest_test_file_path}")).to exist expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist end end @@ -722,7 +726,7 @@ RSpec.describe "bundle gem" do end it "builds spec skeleton" do - expect(bundled_app("#{gem_name}/test/test_#{require_path}.rb")).to exist + expect(bundled_app("#{gem_name}/#{minitest_test_file_path}")).to exist expect(bundled_app("#{gem_name}/test/test_helper.rb")).to exist end @@ -731,11 +735,15 @@ RSpec.describe "bundle gem" do end it "requires 'test_helper'" do - expect(bundled_app("#{gem_name}/test/test_#{require_path}.rb").read).to include(%(require "test_helper")) + expect(bundled_app("#{gem_name}/#{minitest_test_file_path}").read).to include(%(require "test_helper")) + end + + it "defines valid test class name" do + expect(bundled_app("#{gem_name}/#{minitest_test_file_path}").read).to include(minitest_test_class_name) end it "creates a default test which fails" do - expect(bundled_app("#{gem_name}/test/test_#{require_path}.rb").read).to include("assert false") + expect(bundled_app("#{gem_name}/#{minitest_test_file_path}").read).to include("assert false") end end @@ -1300,6 +1308,10 @@ RSpec.describe "bundle gem" do let(:require_relative_path) { "test_gem" } + let(:minitest_test_file_path) { "test/test_test_gem.rb" } + + let(:minitest_test_class_name) { "class TestTestGem < Minitest::Test" } + let(:flags) { nil } it "does not nest constants" do @@ -1355,6 +1367,10 @@ RSpec.describe "bundle gem" do let(:require_relative_path) { "gem" } + let(:minitest_test_file_path) { "test/test/test_gem.rb" } + + let(:minitest_test_class_name) { "class Test::TestGem < Minitest::Test" } + it "nests constants so they work" do bundle "gem #{gem_name}" expect(bundled_app("#{gem_name}/lib/#{require_path}/version.rb").read).to match(/module Test\n module Gem/) diff --git a/spec/bundler/commands/remove_spec.rb b/spec/bundler/commands/remove_spec.rb index 70dc09c9b6..95d6e75e9f 100644 --- a/spec/bundler/commands/remove_spec.rb +++ b/spec/bundler/commands/remove_spec.rb @@ -48,12 +48,14 @@ RSpec.describe "bundle remove" do context "when gem is specified in multiple lines" do it "shows success for removed gem" do + build_git "rack" + gemfile <<-G source '#{file_uri_for(gem_repo1)}' gem 'git' gem 'rack', - git: 'https://github.com/rack/rack', + git: "#{lib_path("rack-1.0")}", branch: 'master' gem 'nokogiri' G diff --git a/spec/bundler/commands/update_spec.rb b/spec/bundler/commands/update_spec.rb index 403a48a508..ee5d53c527 100644 --- a/spec/bundler/commands/update_spec.rb +++ b/spec/bundler/commands/update_spec.rb @@ -980,20 +980,14 @@ RSpec.describe "bundle update when a gem depends on a newer version of bundler" end RSpec.describe "bundle update --ruby" do - before do - install_gemfile <<-G - ::RUBY_VERSION = '2.1.3' - ::RUBY_PATCHLEVEL = 100 - ruby '~> 2.1.0' - source "#{file_uri_for(gem_repo1)}" - G - end - context "when the Gemfile removes the ruby" do before do + install_gemfile <<-G + ruby '~> #{RUBY_VERSION}' + source "#{file_uri_for(gem_repo1)}" + G + gemfile <<-G - ::RUBY_VERSION = '2.1.4' - ::RUBY_PATCHLEVEL = 222 source "#{file_uri_for(gem_repo1)}" G end @@ -1018,10 +1012,13 @@ RSpec.describe "bundle update --ruby" do context "when the Gemfile specified an updated Ruby version" do before do + install_gemfile <<-G + ruby '~> #{RUBY_VERSION}' + source "#{file_uri_for(gem_repo1)}" + G + gemfile <<-G - ::RUBY_VERSION = '2.1.4' - ::RUBY_PATCHLEVEL = 222 - ruby '~> 2.1.0' + ruby '~> #{RUBY_VERSION[0..2]}' source "#{file_uri_for(gem_repo1)}" G end @@ -1039,7 +1036,7 @@ RSpec.describe "bundle update --ruby" do DEPENDENCIES RUBY VERSION - ruby 2.1.4p222 + #{Bundler::RubyVersion.system} BUNDLED WITH #{Bundler::VERSION} @@ -1049,9 +1046,12 @@ RSpec.describe "bundle update --ruby" do context "when a different Ruby is being used than has been versioned" do before do + install_gemfile <<-G + ruby '~> #{RUBY_VERSION}' + source "#{file_uri_for(gem_repo1)}" + G + gemfile <<-G - ::RUBY_VERSION = '2.2.2' - ::RUBY_PATCHLEVEL = 505 ruby '~> 2.1.0' source "#{file_uri_for(gem_repo1)}" G @@ -1059,16 +1059,31 @@ RSpec.describe "bundle update --ruby" do it "shows a helpful error message" do bundle "update --ruby", :raise_on_error => false - expect(err).to include("Your Ruby version is 2.2.2, but your Gemfile specified ~> 2.1.0") + expect(err).to include("Your Ruby version is #{Bundler::RubyVersion.system.gem_version}, but your Gemfile specified ~> 2.1.0") end end context "when updating Ruby version and Gemfile `ruby`" do before do + lockfile <<~L + GEM + remote: #{file_uri_for(gem_repo1)}/ + specs: + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + + RUBY VERSION + ruby 2.1.4p222 + + BUNDLED WITH + #{Bundler::VERSION} + L + gemfile <<-G - ::RUBY_VERSION = '1.8.3' - ::RUBY_PATCHLEVEL = 55 - ruby '~> 1.8.0' + ruby '~> #{RUBY_VERSION}' source "#{file_uri_for(gem_repo1)}" G end @@ -1086,7 +1101,7 @@ RSpec.describe "bundle update --ruby" do DEPENDENCIES RUBY VERSION - ruby 1.8.3p55 + #{Bundler::RubyVersion.system} BUNDLED WITH #{Bundler::VERSION} @@ -1105,15 +1120,208 @@ RSpec.describe "bundle update --bundler" do source "#{file_uri_for(gem_repo4)}" gem "rack" G - allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2') FileUtils.rm_r gem_repo4 - bundle :update, :bundler => true, :verbose => true + bundle :update, :bundler => true, :artifice => "compact_index", :verbose => true + expect(out).to include("Using bundler #{Bundler::VERSION}") + + expect(lockfile).to eq <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + rack (1.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + rack + + BUNDLED WITH + #{Bundler::VERSION} + L + + expect(the_bundle).to include_gem "rack 1.0" + end + + it "updates the bundler version in the lockfile without re-resolving if the highest version is already installed" do + system_gems "bundler-2.3.3" + + build_repo4 do + build_gem "rack", "1.0" + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem "rack" + G + lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.3") + + bundle :update, :bundler => true, :artifice => "compact_index", :verbose => true + expect(out).to include("Using bundler #{Bundler::VERSION}") + + expect(lockfile).to eq <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + rack (1.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + rack + + BUNDLED WITH + #{Bundler::VERSION} + L + expect(the_bundle).to include_gem "rack 1.0" + end + + it "updates the bundler version in the lockfile even if the latest version is not installed", :ruby_repo, :realworld do + pristine_system_gems "bundler-2.3.3" + + build_repo4 do + build_gem "rack", "1.0" + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem "rack" + G + lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.3") + + bundle :update, :bundler => true, :artifice => "vcr", :verbose => true + + # Only updates properly on modern RubyGems. + + if Gem.rubygems_version >= Gem::Version.new("3.3.0.dev") + expect(out).to include("Updating bundler to 2.3.4") + expect(out).to include("Using bundler 2.3.4") + expect(out).not_to include("Installing Bundler 2.3.3 and restarting using that version.") + + expect(lockfile).to eq <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + rack (1.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + rack + + BUNDLED WITH + 2.3.4 + L + + expect(the_bundle).to include_gems "bundler 2.3.4" + end + + expect(the_bundle).to include_gems "rack 1.0" + end + + it "errors if the explicit target version does not exist", :realworld do + pristine_system_gems "bundler-2.3.3" + + build_repo4 do + build_gem "rack", "1.0" + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem "rack" + G + lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, "2.3.3") + + bundle :update, :bundler => "999.999.999", :artifice => "vcr", :raise_on_error => false - expect(the_bundle.locked_gems.bundler_version).to eq v(Bundler::VERSION) + # Only gives a meaningful error message on modern RubyGems. + + if Gem.rubygems_version >= Gem::Version.new("3.3.0.dev") + expect(last_command).to be_failure + expect(err).to include("The `bundle update --bundler` target version (999.999.999) does not exist") + end + end + + it "allows updating to development versions if already installed locally" do + system_gems "bundler-2.3.0.dev" + + build_repo4 do + build_gem "rack", "1.0" + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem "rack" + G + + bundle :update, :bundler => "2.3.0.dev" + + # Only updates properly on modern RubyGems. + + if Gem.rubygems_version >= Gem::Version.new("3.3.0.dev") + expect(lockfile).to eq <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + rack (1.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + rack + + BUNDLED WITH + 2.3.0.dev + L + + expect(out).to include("Using bundler 2.3.0.dev") + end + end + + it "does not touch the network if not necessary" do + system_gems "bundler-2.3.3" + + build_repo4 do + build_gem "rack", "1.0" + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gem "rack" + G + + bundle :update, :bundler => "2.3.3", :raise_on_error => false + + expect(out).not_to include("Fetching gem metadata from https://rubygems.org/") + + # Only updates properly on modern RubyGems. + + if Gem.rubygems_version >= Gem::Version.new("3.3.0.dev") + expect(lockfile).to eq <<~L + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + rack (1.0) + + PLATFORMS + #{lockfile_platforms} + + DEPENDENCIES + rack + + BUNDLED WITH + 2.3.3 + L + + expect(out).to include("Using bundler 2.3.3") + end end end diff --git a/spec/bundler/install/gemfile/gemspec_spec.rb b/spec/bundler/install/gemfile/gemspec_spec.rb index 6d9cd2daff..6bcfadab7e 100644 --- a/spec/bundler/install/gemfile/gemspec_spec.rb +++ b/spec/bundler/install/gemfile/gemspec_spec.rb @@ -179,7 +179,7 @@ RSpec.describe "bundle install from an existing gemspec" do gemspec :path => '#{tmp.join("foo")}' G - bundle "update --bundler", :verbose => true + bundle "update --bundler", :artifice => "compact_index", :verbose => true expect(the_bundle).to include_gems "foo 1.0", "platform_specific 1.0 JAVA" end @@ -429,13 +429,16 @@ RSpec.describe "bundle install from an existing gemspec" do gemspec G - simulate_platform("ruby") { bundle "install" } + bundle "config set --local force_ruby_platform true" + bundle "install" + + simulate_new_machine simulate_platform("jruby") { bundle "install" } end context "on ruby" do before do - simulate_platform("ruby") + bundle "config set --local force_ruby_platform true" bundle :install end @@ -546,7 +549,7 @@ RSpec.describe "bundle install from an existing gemspec" do end it "installs the ruby platform gemspec" do - simulate_platform "ruby" + bundle "config set --local force_ruby_platform true" install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -557,7 +560,7 @@ RSpec.describe "bundle install from an existing gemspec" do end it "installs the ruby platform gemspec and skips dev deps with `without development` configured" do - simulate_platform "ruby" + bundle "config set --local force_ruby_platform true" bundle "config set --local without development" install_gemfile <<-G @@ -622,4 +625,64 @@ RSpec.describe "bundle install from an existing gemspec" do expect(lockfile).to eq initial_lockfile end end + + context "with multiple locked platforms" do + before do + build_lib("activeadmin", :path => tmp.join("activeadmin")) do |s| + s.version = "2.9.0" + s.add_dependency "railties", ">= 5.2", "< 6.2" + end + + build_repo4 do + build_gem "railties", "6.1.4" + + build_gem "jruby-openssl", "0.10.7" do |s| + s.platform = "java" + end + end + + install_gemfile <<-G + source "#{file_uri_for(gem_repo4)}" + gemspec :path => "../activeadmin" + gem "jruby-openssl", :platform => :jruby + G + + bundle "lock --add-platform java" + end + + it "does not remove the platform specific specs from the lockfile when re-resolving due to gemspec changes" do + expect(lockfile).to eq <<~L + PATH + remote: ../activeadmin + specs: + activeadmin (2.9.0) + railties (>= 5.2, < 6.2) + + GEM + remote: #{file_uri_for(gem_repo4)}/ + specs: + jruby-openssl (0.10.7-java) + railties (6.1.4) + + PLATFORMS + #{lockfile_platforms_for(["java"] + local_platforms)} + + DEPENDENCIES + activeadmin! + jruby-openssl + + BUNDLED WITH + #{Bundler::VERSION} + L + + gemspec = tmp.join("activeadmin/activeadmin.gemspec") + File.write(gemspec, File.read(gemspec).sub(">= 5.2", ">= 6.0")) + + previous_lockfile = lockfile + + bundle "install --local" + + expect(lockfile).to eq(previous_lockfile.sub(">= 5.2", ">= 6.0")) + end + end end diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index a0fb4a3cea..365a84f39e 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -92,9 +92,7 @@ RSpec.describe "bundle install with git sources" do expect(err).to include("The source contains the following gems matching 'foo':\n * foo-1.0") end - it "complains with version and platform if pinned specs don't exist in the git repo" do - simulate_platform "java" - + it "complains with version and platform if pinned specs don't exist in the git repo", :jruby do build_git "only_java" do |s| s.platform = "java" end @@ -109,9 +107,7 @@ RSpec.describe "bundle install with git sources" do expect(err).to include("The source contains the following gems matching 'only_java':\n * only_java-1.0-java") end - it "complains with multiple versions and platforms if pinned specs don't exist in the git repo" do - simulate_platform "java" - + it "complains with multiple versions and platforms if pinned specs don't exist in the git repo", :jruby do build_git "only_java", "1.0" do |s| s.platform = "java" end @@ -418,9 +414,6 @@ RSpec.describe "bundle install with git sources" do describe "when specifying local override" do it "uses the local repository instead of checking a new one out" do - # We don't generate it because we actually don't need it - # build_git "rack", "0.8" - build_git "rack", "0.8", :path => lib_path("local-rack") do |s| s.write "lib/rack.rb", "puts :LOCAL" end diff --git a/spec/bundler/install/gemfile/platform_spec.rb b/spec/bundler/install/gemfile/platform_spec.rb index 35a3872c03..839db0089e 100644 --- a/spec/bundler/install/gemfile/platform_spec.rb +++ b/spec/bundler/install/gemfile/platform_spec.rb @@ -86,13 +86,13 @@ RSpec.describe "bundle install across platforms" do expect(the_bundle).to include_gems "nokogiri 1.4.2 JAVA", "weakling 0.0.3" simulate_new_machine - - simulate_platform "ruby" + bundle "config set --local force_ruby_platform true" bundle "install" expect(the_bundle).to include_gems "nokogiri 1.4.2" expect(the_bundle).not_to include_gems "weakling" + simulate_new_machine simulate_platform "java" bundle "install" @@ -453,7 +453,7 @@ RSpec.describe "bundle install with platform conditionals" do end it "does not attempt to install gems from :rbx when using --local" do - simulate_platform "ruby" + bundle "config set --local force_ruby_platform true" gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -465,7 +465,7 @@ RSpec.describe "bundle install with platform conditionals" do end it "does not attempt to install gems from other rubies when using --local" do - simulate_platform "ruby" + bundle "config set --local force_ruby_platform true" other_ruby_version_tag = RUBY_VERSION =~ /^1\.8/ ? :ruby_19 : :ruby_18 gemfile <<-G @@ -478,7 +478,7 @@ RSpec.describe "bundle install with platform conditionals" do end it "does not print a warning when a dependency is unused on a platform different from the current one" do - simulate_platform "ruby" + bundle "config set --local force_ruby_platform true" gemfile <<-G source "#{file_uri_for(gem_repo1)}" diff --git a/spec/bundler/install/gemfile/ruby_spec.rb b/spec/bundler/install/gemfile/ruby_spec.rb index fd4300c042..ba250acfdd 100644 --- a/spec/bundler/install/gemfile/ruby_spec.rb +++ b/spec/bundler/install/gemfile/ruby_spec.rb @@ -46,18 +46,16 @@ RSpec.describe "ruby requirement" do it "allows changing the ruby version requirement to something compatible" do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby ">= 1.0.0" + ruby ">= #{RUBY_VERSION[0..2]}.0" gem "rack" G allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) - simulate_ruby_version "5100" - install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby ">= 1.0.1" + ruby ">= #{RUBY_VERSION}" gem "rack" G @@ -72,19 +70,35 @@ RSpec.describe "ruby requirement" do gem "rack" G - allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) - expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) + lockfile <<~L + GEM + remote: #{file_uri_for(gem_repo1)}/ + specs: + rack (1.0.0) + + PLATFORMS + #{lockfile_platforms} - simulate_ruby_version "5100" + DEPENDENCIES + rack + + RUBY VERSION + ruby 2.1.4p422 + + BUNDLED WITH + #{Bundler::VERSION} + L + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" - ruby ">= 5000.0" + ruby ">= #{RUBY_VERSION[0..2]}.0" gem "rack" G expect(the_bundle).to include_gems "rack 1.0.0" - expect(locked_ruby_version.versions).to eq(["5100"]) + expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) end it "allows requirements with trailing whitespace" do diff --git a/spec/bundler/install/gemfile/sources_spec.rb b/spec/bundler/install/gemfile/sources_spec.rb index 5456e95f33..26ecb840c7 100644 --- a/spec/bundler/install/gemfile/sources_spec.rb +++ b/spec/bundler/install/gemfile/sources_spec.rb @@ -1443,4 +1443,57 @@ RSpec.describe "bundle install with gems on multiple sources" do L end end + + context "when default source includes old gems with nil required_rubygems_version" do + before do + build_repo2 do + build_gem "ruport", "1.7.0.3" do |s| + s.add_dependency "pdf-writer", "1.1.8" + end + end + + build_repo gem_repo4 do + build_gem "pdf-writer", "1.1.8" + end + + path = "#{gem_repo4}/#{Gem::MARSHAL_SPEC_DIR}/pdf-writer-1.1.8.gemspec.rz" + spec = Marshal.load(Bundler.rubygems.inflate(File.binread(path))) + spec.instance_variable_set(:@required_rubygems_version, nil) + File.open(path, "wb") do |f| + f.write Gem.deflate(Marshal.dump(spec)) + end + + gemfile <<~G + source "https://localgemserver.test" + + gem "ruport", "= 1.7.0.3", :source => "https://localgemserver.test/extra" + G + end + + it "handles that fine" do + bundle "install", :artifice => "compact_index_extra", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo4.to_s } + + expect(lockfile).to eq <<~L + GEM + remote: https://localgemserver.test/ + specs: + pdf-writer (1.1.8) + + GEM + remote: https://localgemserver.test/extra/ + specs: + ruport (1.7.0.3) + pdf-writer (= 1.1.8) + + PLATFORMS + #{specific_local_platform} + + DEPENDENCIES + ruport (= 1.7.0.3)! + + BUNDLED WITH + #{Bundler::VERSION} + L + end + end end diff --git a/spec/bundler/install/gems/dependency_api_spec.rb b/spec/bundler/install/gems/dependency_api_spec.rb index 9738a75474..79317a7fad 100644 --- a/spec/bundler/install/gems/dependency_api_spec.rb +++ b/spec/bundler/install/gems/dependency_api_spec.rb @@ -402,17 +402,6 @@ RSpec.describe "gemcutter's dependency API" do expect(the_bundle).to include_gems "back_deps 1.0" end - it "uses the endpoint if all sources support it" do - gemfile <<-G - source "#{source_uri}" - - gem 'foo' - G - - bundle :install, :artifice => "endpoint_api_missing" - expect(the_bundle).to include_gems "foo 1.0" - end - it "fetches again when more dependencies are found in subsequent sources using deployment mode", :bundler => "< 3" do build_repo2 do build_gem "back_deps" do |s| diff --git a/spec/bundler/install/gems/resolving_spec.rb b/spec/bundler/install/gems/resolving_spec.rb index 94fac0052c..b0209489b9 100644 --- a/spec/bundler/install/gems/resolving_spec.rb +++ b/spec/bundler/install/gems/resolving_spec.rb @@ -101,8 +101,6 @@ RSpec.describe "bundle install with install-time dependencies" do end it "installs gems with a dependency with no type" do - skip "incorrect data check error" if Gem.win_platform? - build_repo2 path = "#{gem_repo2}/#{Gem::MARSHAL_SPEC_DIR}/actionpack-2.3.2.gemspec.rz" @@ -110,7 +108,7 @@ RSpec.describe "bundle install with install-time dependencies" do spec.dependencies.each do |d| d.instance_variable_set(:@type, :fail) end - File.open(path, "w") do |f| + File.open(path, "wb") do |f| f.write Gem.deflate(Marshal.dump(spec)) end @@ -226,6 +224,27 @@ RSpec.describe "bundle install with install-time dependencies" do expect(the_bundle).to include_gems("rack 1.2") end + it "installs the older version when using servers not implementing the compact index API" do + build_repo2 do + build_gem "rack", "1.2" do |s| + s.executables = "rackup" + end + + build_gem "rack", "9001.0.0" do |s| + s.required_ruby_version = "> 9000" + end + end + + install_gemfile <<-G, :artifice => "endpoint", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s } + ruby "#{RUBY_VERSION}" + source "http://localgemserver.test/" + gem 'rack' + G + + expect(out).to_not include("rack-9001.0.0 requires ruby version > 9000") + expect(the_bundle).to include_gems("rack 1.2") + end + it "installs the older version under rate limiting conditions" do build_repo4 do build_gem "rack", "9001.0.0" do |s| @@ -286,8 +305,6 @@ RSpec.describe "bundle install with install-time dependencies" do shared_examples_for "ruby version conflicts" do it "raises an error during resolution" do - skip "ruby requirement includes platform and it shouldn't" if Gem.win_platform? - install_gemfile <<-G, :artifice => "compact_index", :env => { "BUNDLER_SPEC_GEM_REPO" => gem_repo2.to_s }, :raise_on_error => false source "http://localgemserver.test/" ruby #{ruby_requirement} @@ -303,8 +320,6 @@ RSpec.describe "bundle install with install-time dependencies" do require_ruby was resolved to 1.0, which depends on Ruby\0 (> 9000) - - Ruby\0 (> 9000), which is required by gem 'require_ruby', is not available in the local ruby installation E expect(err).to end_with(nice_error) end @@ -343,7 +358,15 @@ RSpec.describe "bundle install with install-time dependencies" do G expect(err).to_not include("Gem::InstallError: require_rubygems requires RubyGems version > 9000") - expect(err).to include("require_rubygems-1.0 requires rubygems version > 9000, which is incompatible with the current version, #{Gem::VERSION}") + nice_error = strip_whitespace(<<-E).strip + Bundler found conflicting requirements for the RubyGems\0 version: + In Gemfile: + RubyGems\0 (= #{Gem::VERSION}) + + require_rubygems was resolved to 1.0, which depends on + RubyGems\0 (> 9000) + E + expect(err).to end_with(nice_error) end end end diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb index b9ef6e885a..561de9f3bc 100644 --- a/spec/bundler/lock/lockfile_spec.rb +++ b/spec/bundler/lock/lockfile_spec.rb @@ -1,18 +1,8 @@ # frozen_string_literal: true RSpec.describe "the lockfile format" do - include Bundler::GemHelpers - before do - build_repo2 do - # Capistrano did this (at least until version 2.5.10) - # RubyGems 2.2 doesn't allow the specifying of a dependency twice - # See https://github.com/rubygems/rubygems/commit/03dbac93a3396a80db258d9bc63500333c25bd2f - build_gem "double_deps", "1.0", :skip_validation => true do |s| - s.add_dependency "net-ssh", ">= 1.0.0" - s.add_dependency "net-ssh" - end - end + build_repo2 end it "generates a simple lockfile for a single source, gem" do @@ -90,12 +80,8 @@ RSpec.describe "the lockfile format" do G end - it "does not update the lockfile's bundler version if nothing changed during bundle install, but uses the locked version", :rubygems => ">= 3.3.0.a" do - version = "#{Bundler::VERSION.split(".").first}.0.0.a" - - update_repo2 do - with_built_bundler(version) {|gem_path| FileUtils.mv(gem_path, gem_repo2("gems")) } - end + it "does not update the lockfile's bundler version if nothing changed during bundle install, but uses the locked version", :rubygems => ">= 3.3.0.a", :realworld => true do + version = "2.3.0" lockfile <<-L GEM @@ -113,7 +99,7 @@ RSpec.describe "the lockfile format" do #{version} L - install_gemfile <<-G, :verbose => true, :env => { "BUNDLER_SPEC_GEM_SOURCES" => file_uri_for(gem_repo2).to_s } + install_gemfile <<-G, :verbose => true, :artifice => "vcr" source "#{file_uri_for(gem_repo2)}" gem "rack" @@ -142,10 +128,6 @@ RSpec.describe "the lockfile format" do it "does not update the lockfile's bundler version if nothing changed during bundle install, and uses the latest version", :rubygems => "< 3.3.0.a" do version = "#{Bundler::VERSION.split(".").first}.0.0.a" - update_repo2 do - with_built_bundler(version) {|gem_path| FileUtils.mv(gem_path, gem_repo2("gems")) } - end - lockfile <<-L GEM remote: #{file_uri_for(gem_repo2)}/ @@ -162,7 +144,7 @@ RSpec.describe "the lockfile format" do #{version} L - install_gemfile <<-G, :verbose => true, :env => { "BUNDLER_SPEC_GEM_SOURCES" => file_uri_for(gem_repo2).to_s } + install_gemfile <<-G, :verbose => true source "#{file_uri_for(gem_repo2)}" gem "rack" @@ -761,6 +743,16 @@ RSpec.describe "the lockfile format" do end it "orders dependencies by version" do + update_repo2 do + # Capistrano did this (at least until version 2.5.10) + # RubyGems 2.2 doesn't allow the specifying of a dependency twice + # See https://github.com/rubygems/rubygems/commit/03dbac93a3396a80db258d9bc63500333c25bd2f + build_gem "double_deps", "1.0", :skip_validation => true do |s| + s.add_dependency "net-ssh", ">= 1.0.0" + s.add_dependency "net-ssh" + end + end + install_gemfile <<-G source "#{file_uri_for(gem_repo2)}/" gem 'double_deps' diff --git a/spec/bundler/other/platform_spec.rb b/spec/bundler/other/platform_spec.rb index 5693d6bce6..bf38a05646 100644 --- a/spec/bundler/other/platform_spec.rb +++ b/spec/bundler/other/platform_spec.rb @@ -17,7 +17,7 @@ RSpec.describe "bundle platform" do bundle "platform" expect(out).to eq(<<-G.chomp) -Your platform is: #{RUBY_PLATFORM} +Your platform is: #{Gem::Platform.local} Your app has gems that work on these platforms: #{bundle_platform_platforms_string} @@ -40,7 +40,7 @@ G bundle "platform" expect(out).to eq(<<-G.chomp) -Your platform is: #{RUBY_PLATFORM} +Your platform is: #{Gem::Platform.local} Your app has gems that work on these platforms: #{bundle_platform_platforms_string} @@ -61,7 +61,7 @@ G bundle "platform" expect(out).to eq(<<-G.chomp) -Your platform is: #{RUBY_PLATFORM} +Your platform is: #{Gem::Platform.local} Your app has gems that work on these platforms: #{bundle_platform_platforms_string} @@ -81,7 +81,7 @@ G bundle "platform" expect(out).to eq(<<-G.chomp) -Your platform is: #{RUBY_PLATFORM} +Your platform is: #{Gem::Platform.local} Your app has gems that work on these platforms: #{bundle_platform_platforms_string} diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index 2ffadebf55..24df758619 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -309,7 +309,7 @@ RSpec.describe "bundler/inline#gemfile" do end it "skips platform warnings" do - simulate_platform "ruby" + bundle "config set --local force_ruby_platform true" script <<-RUBY gemfile(true) do diff --git a/spec/bundler/runtime/platform_spec.rb b/spec/bundler/runtime/platform_spec.rb index b937de8059..f7159635e6 100644 --- a/spec/bundler/runtime/platform_spec.rb +++ b/spec/bundler/runtime/platform_spec.rb @@ -232,6 +232,20 @@ RSpec.describe "Bundler.setup with multi platform stuff" do expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 RUBY" end + it "allows specifying only-ruby-platform even if the lockfile is locked to a specific compatible platform" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "nokogiri" + gem "platform_specific" + G + + bundle "config set force_ruby_platform true" + + bundle "install" + + expect(the_bundle).to include_gems "nokogiri 1.4.2", "platform_specific 1.0 RUBY" + end + it "doesn't pull platform specific gems on truffleruby", :truffleruby do install_gemfile <<-G source "#{file_uri_for(gem_repo1)}" diff --git a/spec/bundler/runtime/self_management_spec.rb b/spec/bundler/runtime/self_management_spec.rb index 7746a6ffa9..0032c6aef6 100644 --- a/spec/bundler/runtime/self_management_spec.rb +++ b/spec/bundler/runtime/self_management_spec.rb @@ -1,15 +1,13 @@ # frozen_string_literal: true -RSpec.describe "Self management", :rubygems => ">= 3.3.0.dev" do +RSpec.describe "Self management", :rubygems => ">= 3.3.0.dev", :realworld => true do describe "auto switching" do - let(:next_minor) do - Bundler::VERSION.split(".").map.with_index {|s, i| i == 1 ? s.to_i + 1 : s }[0..2].join(".") + let(:previous_minor) do + "2.3.0" end before do - build_repo2 do - with_built_bundler(next_minor) {|gem_path| FileUtils.mv(gem_path, gem_repo2("gems")) } - end + build_repo2 gemfile <<-G source "#{file_uri_for(gem_repo2)}" @@ -19,11 +17,11 @@ RSpec.describe "Self management", :rubygems => ">= 3.3.0.dev" do end it "installs locked version when using system path and uses it" do - lockfile_bundled_with(next_minor) + lockfile_bundled_with(previous_minor) bundle "config set --local path.system true" - bundle "install", :env => { "BUNDLER_SPEC_GEM_SOURCES" => file_uri_for(gem_repo2).to_s } - expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{next_minor}. Installing Bundler #{next_minor} and restarting using that version.") + bundle "install", :artifice => "vcr" + expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") # It uninstalls the older system bundler bundle "clean --force" @@ -31,21 +29,21 @@ RSpec.describe "Self management", :rubygems => ">= 3.3.0.dev" do # App now uses locked version bundle "-v" - expect(out).to end_with(next_minor[0] == "2" ? "Bundler version #{next_minor}" : next_minor) + expect(out).to end_with(previous_minor[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor) # Subsequent installs use the locked version without reinstalling bundle "install --verbose" - expect(out).to include("Using bundler #{next_minor}") - expect(out).not_to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{next_minor}. Installing Bundler #{next_minor} and restarting using that version.") + expect(out).to include("Using bundler #{previous_minor}") + expect(out).not_to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") end it "installs locked version when using local path and uses it" do - lockfile_bundled_with(next_minor) + lockfile_bundled_with(previous_minor) bundle "config set --local path vendor/bundle" - bundle "install", :env => { "BUNDLER_SPEC_GEM_SOURCES" => file_uri_for(gem_repo2).to_s } - expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{next_minor}. Installing Bundler #{next_minor} and restarting using that version.") - expect(vendored_gems("gems/bundler-#{next_minor}")).to exist + bundle "install", :artifice => "vcr" + expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") + expect(vendored_gems("gems/bundler-#{previous_minor}")).to exist # It does not uninstall the locked bundler bundle "clean" @@ -53,21 +51,21 @@ RSpec.describe "Self management", :rubygems => ">= 3.3.0.dev" do # App now uses locked version bundle "-v" - expect(out).to end_with(next_minor[0] == "2" ? "Bundler version #{next_minor}" : next_minor) + expect(out).to end_with(previous_minor[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor) # Subsequent installs use the locked version without reinstalling bundle "install --verbose" - expect(out).to include("Using bundler #{next_minor}") - expect(out).not_to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{next_minor}. Installing Bundler #{next_minor} and restarting using that version.") + expect(out).to include("Using bundler #{previous_minor}") + expect(out).not_to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") end it "installs locked version when using deployment option and uses it" do - lockfile_bundled_with(next_minor) + lockfile_bundled_with(previous_minor) bundle "config set --local deployment true" - bundle "install", :env => { "BUNDLER_SPEC_GEM_SOURCES" => file_uri_for(gem_repo2).to_s } - expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{next_minor}. Installing Bundler #{next_minor} and restarting using that version.") - expect(vendored_gems("gems/bundler-#{next_minor}")).to exist + bundle "install", :artifice => "vcr" + expect(out).to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") + expect(vendored_gems("gems/bundler-#{previous_minor}")).to exist # It does not uninstall the locked bundler bundle "clean" @@ -75,16 +73,16 @@ RSpec.describe "Self management", :rubygems => ">= 3.3.0.dev" do # App now uses locked version bundle "-v" - expect(out).to end_with(next_minor[0] == "2" ? "Bundler version #{next_minor}" : next_minor) + expect(out).to end_with(previous_minor[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor) # Subsequent installs use the locked version without reinstalling bundle "install --verbose" - expect(out).to include("Using bundler #{next_minor}") - expect(out).not_to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{next_minor}. Installing Bundler #{next_minor} and restarting using that version.") + expect(out).to include("Using bundler #{previous_minor}") + expect(out).not_to include("Bundler #{Bundler::VERSION} is running, but your lockfile was generated with #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.") end it "does not try to install a development version" do - lockfile_bundled_with("#{next_minor}.dev") + lockfile_bundled_with("#{previous_minor}.dev") bundle "install --verbose" expect(out).not_to match(/restarting using that version/) @@ -93,17 +91,13 @@ RSpec.describe "Self management", :rubygems => ">= 3.3.0.dev" do expect(out).to eq(Bundler::VERSION[0] == "2" ? "Bundler version #{Bundler::VERSION}" : Bundler::VERSION) end - it "shows a discreet message if locked bundler does not exist, and something more complete in `--verbose` mode" do + it "shows a discreet message if locked bundler does not exist" do missing_minor ="#{Bundler::VERSION[0]}.999.999" lockfile_bundled_with(missing_minor) - bundle "install" - expect(err).to eq("There was an error installing the locked bundler version (#{missing_minor}), rerun with the `--verbose` flag for more details. Going on using bundler #{Bundler::VERSION}.") - - bundle "install --verbose" - expect(err).to include("There was an error installing the locked bundler version (#{missing_minor}), rerun with the `--verbose` flag for more details. Going on using bundler #{Bundler::VERSION}.") - expect(err).to include("Gem::UnsatisfiableDependencyError") + bundle "install", :artifice => "vcr" + expect(err).to eq("Your lockfile is locked to a version of bundler (#{missing_minor}) that doesn't exist at https://rubygems.org/. Going on using #{Bundler::VERSION}") bundle "-v" expect(out).to eq(Bundler::VERSION[0] == "2" ? "Bundler version #{Bundler::VERSION}" : Bundler::VERSION) diff --git a/spec/bundler/support/artifice/endpoint_api_missing.rb b/spec/bundler/support/artifice/endpoint_api_missing.rb deleted file mode 100644 index 755c42e836..0000000000 --- a/spec/bundler/support/artifice/endpoint_api_missing.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require_relative "endpoint" - -Artifice.deactivate - -class EndpointApiMissing < Endpoint - get "/fetch/actual/gem/:id" do - warn params[:id] - if params[:id] == "rack-1.0.gemspec.rz" - halt 404 - else - File.binread("#{gem_repo2}/quick/Marshal.4.8/#{params[:id]}") - end - end -end - -Artifice.activate_with(EndpointApiMissing) diff --git a/spec/bundler/support/artifice/vcr.rb b/spec/bundler/support/artifice/vcr.rb index 0d51201bef..ceb133346f 100644 --- a/spec/bundler/support/artifice/vcr.rb +++ b/spec/bundler/support/artifice/vcr.rb @@ -69,7 +69,7 @@ class BundlerVCRHTTP < Net::HTTP end def file_name_for_key(key) - key.join("/").gsub(/[\:*?"<>|]/, "-") + File.join(*key).gsub(/[\:*?"<>|]/, "-") end def request_pair_paths diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb index 4a49ffb49f..3d97b93c5a 100644 --- a/spec/bundler/support/hax.rb +++ b/spec/bundler/support/hax.rb @@ -19,16 +19,6 @@ module Gem @local = new(ENV["BUNDLER_SPEC_PLATFORM"]) end @platforms = [Gem::Platform::RUBY, Gem::Platform.local] - - if ENV["BUNDLER_SPEC_PLATFORM"] == "ruby" - class << self - remove_method :finish_resolve - - def finish_resolve - [] - end - end - end end if ENV["BUNDLER_SPEC_GEM_SOURCES"] diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index 99baec24d4..c27096a0cf 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -88,7 +88,6 @@ module Spec requires = options.delete(:requires) || [] realworld = RSpec.current_example.metadata[:realworld] - options[:verbose] = true if options[:verbose].nil? && realworld artifice = options.delete(:artifice) do if realworld @@ -448,15 +447,6 @@ module Spec ENV["BUNDLER_SPEC_PLATFORM"] = old if block_given? end - def simulate_ruby_version(version) - return if version == RUBY_VERSION - old = ENV["BUNDLER_SPEC_RUBY_VERSION"] - ENV["BUNDLER_SPEC_RUBY_VERSION"] = version - yield if block_given? - ensure - ENV["BUNDLER_SPEC_RUBY_VERSION"] = old if block_given? - end - def simulate_windows(platform = mswin) simulate_platform platform do simulate_bundler_version_when_missing_prerelease_default_gem_activation do diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index 62ba4d56c4..fd5f06b14f 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -119,7 +119,7 @@ module Spec ENV["BUNDLE_PATH__SYSTEM"] = "true" end - output = `#{Gem.ruby} #{File.expand_path("support/bundle.rb", Path.spec_dir)} install` + output = `#{Gem.ruby} #{File.expand_path("support/bundle.rb", Path.spec_dir)} install --verbose` raise "Error when installing gems in #{gemfile}: #{output}" unless $?.success? ensure if path |