From ac7b13838aa1314964405a2586f2769d0cb041b4 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Tue, 13 Jun 2017 15:47:57 -0500 Subject: Allow simulating different RubyGems versions in the specs --- spec/support/hax.rb | 5 +++++ spec/support/helpers.rb | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/spec/support/hax.rb b/spec/support/hax.rb index a3fe041c82..d1cea40922 100644 --- a/spec/support/hax.rb +++ b/spec/support/hax.rb @@ -3,6 +3,11 @@ require "rubygems" module Gem + if version = ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] + remove_const(:VERSION) if const_defined?(:VERSION) + VERSION = version + end + class Platform @local = new(ENV["BUNDLER_SPEC_PLATFORM"]) if ENV["BUNDLER_SPEC_PLATFORM"] end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index a0b46bfad7..08c3c5e921 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -481,6 +481,14 @@ module Spec ENV["BUNDLER_SPEC_VERSION"] = old if block_given? end + def simulate_rubygems_version(version) + old = ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] + ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] = version.to_s + yield if block_given? + ensure + ENV["BUNDLER_SPEC_RUBYGEMS_VERSION"] = old if block_given? + end + def simulate_windows old = ENV["BUNDLER_SPEC_WINDOWS"] ENV["BUNDLER_SPEC_WINDOWS"] = "true" -- cgit v1.2.1 From 10fb9743f55354ceb72e445fed67b16555d879a2 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Tue, 13 Jun 2017 15:48:21 -0500 Subject: Add a compatibility guard that prints friendly errors on bundler 2+ --- lib/bundler.rb | 1 + lib/bundler/compatibility_guard.rb | 14 ++++++++++++++ lib/bundler/inline.rb | 1 + lib/bundler/shared_helpers.rb | 1 + spec/other/compatibility_guard_spec.rb | 23 +++++++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 lib/bundler/compatibility_guard.rb create mode 100644 spec/other/compatibility_guard_spec.rb diff --git a/lib/bundler.rb b/lib/bundler.rb index 2da2db29c9..a587f1e430 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +require "bundler/compatibility_guard" require "bundler/vendored_fileutils" require "pathname" diff --git a/lib/bundler/compatibility_guard.rb b/lib/bundler/compatibility_guard.rb new file mode 100644 index 0000000000..6e40a119d1 --- /dev/null +++ b/lib/bundler/compatibility_guard.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require "rubygems" +require "bundler/version" + +if Bundler::VERSION.split(".").first.to_i >= 2 + if Gem::Version.new(Object::RUBY_VERSION) < Gem::Version.new("2.0.0") + abort "Bundler 2 requires Ruby 2+. Either install bundler 1 or update to a supported Ruby version." + end + + if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0.0") + abort "Bundler 2 requires RubyGems 2+. Either install bundler 1 or update to a supported RubyGems version." + end +end diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb index 8462dd9cc1..f5e3a8c157 100644 --- a/lib/bundler/inline.rb +++ b/lib/bundler/inline.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +require "bundler/compatibility_guard" # Allows for declaring a Gemfile inline in a ruby script, optionally installing # any gems that aren't already installed on the user's system. diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 5d3956abc1..bc4c1c1d88 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +require "bundler/compatibility_guard" require "pathname" require "rubygems" diff --git a/spec/other/compatibility_guard_spec.rb b/spec/other/compatibility_guard_spec.rb new file mode 100644 index 0000000000..abe70741a1 --- /dev/null +++ b/spec/other/compatibility_guard_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +RSpec.describe "bundler compatibility guard" do + context "when the bundler version is 2+" do + before { simulate_bundler_version "2.0.a" } + + context "when running on Ruby < 2", :ruby => "< 2.a" do + it "raises a friendly error" do + bundle :version + expect(err).to eq("Bundler 2 requires Ruby 2+. Either install bundler 1 or update to a supported Ruby version.") + end + end + + context "when running on RubyGems < 2" do + before { simulate_rubygems_version "1.3.6" } + + it "raises a friendly error" do + bundle :version + expect(err).to eq("Bundler 2 requires RubyGems 2+. Either install bundler 1 or update to a supported RubyGems version.") + end + end + end +end -- cgit v1.2.1 From d759b899fc8d062c4b7682817536a068d3224731 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Fri, 11 Aug 2017 23:01:21 -0300 Subject: Update supported versions according to https://github.com/bundler/bundler/issues/5789 --- lib/bundler.rb | 1 + lib/bundler/compatibility_guard.rb | 10 +++++----- lib/bundler/inline.rb | 1 + lib/bundler/shared_helpers.rb | 1 + spec/other/compatibility_guard_spec.rb | 6 +++--- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/bundler.rb b/lib/bundler.rb index a587f1e430..e4b9313401 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "bundler/compatibility_guard" require "bundler/vendored_fileutils" diff --git a/lib/bundler/compatibility_guard.rb b/lib/bundler/compatibility_guard.rb index 6e40a119d1..8904d014f5 100644 --- a/lib/bundler/compatibility_guard.rb +++ b/lib/bundler/compatibility_guard.rb @@ -1,14 +1,14 @@ -# frozen_string_literal: true +# frozen_string_literal: false require "rubygems" require "bundler/version" if Bundler::VERSION.split(".").first.to_i >= 2 - if Gem::Version.new(Object::RUBY_VERSION) < Gem::Version.new("2.0.0") - abort "Bundler 2 requires Ruby 2+. Either install bundler 1 or update to a supported Ruby version." + if Gem::Version.new(Object::RUBY_VERSION) < Gem::Version.new("2.3") + abort "Bundler 2 requires Ruby 2.3 or later. Either install bundler 1 or update to a supported Ruby version." end - if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.0.0") - abort "Bundler 2 requires RubyGems 2+. Either install bundler 1 or update to a supported RubyGems version." + if Gem::Version.new(Gem::VERSION.dup) < Gem::Version.new("2.5") + abort "Bundler 2 requires RubyGems 2.5 or later. Either install bundler 1 or update to a supported RubyGems version." end end diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb index f5e3a8c157..9d25f3261a 100644 --- a/lib/bundler/inline.rb +++ b/lib/bundler/inline.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "bundler/compatibility_guard" # Allows for declaring a Gemfile inline in a ruby script, optionally installing diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index bc4c1c1d88..ce3286cc28 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "bundler/compatibility_guard" require "pathname" diff --git a/spec/other/compatibility_guard_spec.rb b/spec/other/compatibility_guard_spec.rb index abe70741a1..8f458b18e5 100644 --- a/spec/other/compatibility_guard_spec.rb +++ b/spec/other/compatibility_guard_spec.rb @@ -4,10 +4,10 @@ RSpec.describe "bundler compatibility guard" do context "when the bundler version is 2+" do before { simulate_bundler_version "2.0.a" } - context "when running on Ruby < 2", :ruby => "< 2.a" do + context "when running on Ruby < 2", :ruby => "< 2.3" do it "raises a friendly error" do bundle :version - expect(err).to eq("Bundler 2 requires Ruby 2+. Either install bundler 1 or update to a supported Ruby version.") + expect(err).to eq("Bundler 2 requires Ruby 2.3 or later. Either install bundler 1 or update to a supported Ruby version.") end end @@ -16,7 +16,7 @@ RSpec.describe "bundler compatibility guard" do it "raises a friendly error" do bundle :version - expect(err).to eq("Bundler 2 requires RubyGems 2+. Either install bundler 1 or update to a supported RubyGems version.") + expect(err).to eq("Bundler 2 requires RubyGems 2.5 or later. Either install bundler 1 or update to a supported RubyGems version.") end end end -- cgit v1.2.1 From be9677f439fedf1027afa707b33086bffc9e279b Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Fri, 11 Aug 2017 23:03:50 -0300 Subject: Always bundle exec to Gem.ruby in the specs --- spec/runtime/with_clean_env_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/runtime/with_clean_env_spec.rb b/spec/runtime/with_clean_env_spec.rb index b05e894484..5cd9f264c2 100644 --- a/spec/runtime/with_clean_env_spec.rb +++ b/spec/runtime/with_clean_env_spec.rb @@ -11,7 +11,7 @@ RSpec.describe "Bundler.with_env helpers" do code = "print Bundler.original_env['PATH']" path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo" with_path_as(path) do - result = bundle("exec ruby -e #{code.dump}") + result = bundle("exec '#{Gem.ruby}' -e #{code.dump}") expect(result).to eq(path) end end @@ -20,7 +20,7 @@ RSpec.describe "Bundler.with_env helpers" do code = "print Bundler.original_env['GEM_PATH']" gem_path = ENV["GEM_PATH"] + ":/foo" with_gem_path_as(gem_path) do - result = bundle("exec ruby -e #{code.inspect}") + result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") expect(result).to eq(gem_path) end end @@ -33,11 +33,11 @@ RSpec.describe "Bundler.with_env helpers" do if count == 2 ENV["PATH"] = "#{ENV["PATH"]}:/foo" end - exec("ruby", __FILE__, (count - 1).to_s) + exec(Gem.ruby, __FILE__, (count - 1).to_s) RB path = `getconf PATH`.strip + File::PATH_SEPARATOR + File.dirname(Gem.ruby) with_path_as(path) do - bundle!("exec ruby #{bundled_app("exe.rb")} 2") + bundle!("exec '#{Gem.ruby}' #{bundled_app("exe.rb")} 2") end expect(err).to eq <<-EOS.strip 2 false @@ -50,7 +50,7 @@ RSpec.describe "Bundler.with_env helpers" do system_gems :bundler original = ruby!('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")') code = 'puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n")' - bundle!("exec ruby -e #{code.inspect}", :system_bundler => true) + bundle!("exec '#{Gem.ruby}' -e #{code.inspect}", :system_bundler => true) expect(out).to eq original end end @@ -64,21 +64,21 @@ RSpec.describe "Bundler.with_env helpers" do it "should delete BUNDLE_PATH" do code = "print Bundler.clean_env.has_key?('BUNDLE_PATH')" ENV["BUNDLE_PATH"] = "./foo" - result = bundle("exec ruby -e #{code.inspect}") + result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") expect(result).to eq("false") end it "should remove '-rbundler/setup' from RUBYOPT" do code = "print Bundler.clean_env['RUBYOPT']" ENV["RUBYOPT"] = "-W2 -rbundler/setup" - result = bundle("exec ruby -e #{code.inspect}") + result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") expect(result).not_to include("-rbundler/setup") end it "should clean up RUBYLIB" do code = "print Bundler.clean_env['RUBYLIB']" ENV["RUBYLIB"] = File.expand_path("../../../lib", __FILE__) + File::PATH_SEPARATOR + "/foo" - result = bundle("exec ruby -e #{code.inspect}") + result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") expect(result).to eq("/foo") end @@ -86,7 +86,7 @@ RSpec.describe "Bundler.with_env helpers" do code = "print Bundler.clean_env['MANPATH']" ENV["MANPATH"] = "/foo" ENV["BUNDLER_ORIG_MANPATH"] = "/foo-original" - result = bundle("exec ruby -e #{code.inspect}") + result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") expect(result).to eq("/foo-original") end end -- cgit v1.2.1 From 66e5907e9830bc7de270e1699313d73877ba4f17 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Sat, 12 Aug 2017 10:53:01 -0300 Subject: [Gemspec] Set 2.0 required ruby/rubygems versions --- bundler.gemspec | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bundler.gemspec b/bundler.gemspec index 921671ece5..3de9c4db74 100644 --- a/bundler.gemspec +++ b/bundler.gemspec @@ -28,8 +28,13 @@ Gem::Specification.new do |s| } end - s.required_ruby_version = ">= 1.8.7" - s.required_rubygems_version = ">= 1.3.6" + if s.version >= Gem::Version.new("2.a".dup) + s.required_ruby_version = ">= 2.3.0" + s.required_rubygems_version = ">= 2.5.0" + else + s.required_ruby_version = ">= 1.8.7" + s.required_rubygems_version = ">= 1.3.6" + end s.add_development_dependency "automatiek", "~> 0.1.0" s.add_development_dependency "mustache", "0.99.6" -- cgit v1.2.1 From e18c7b597916ebeaecb4e9addcff878494bbc720 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Sun, 18 Jun 2017 21:14:07 -0500 Subject: Allow ignoring the compatibilty guard in specs # Conflicts: # spec/install/bundler_spec.rb # spec/other/compatibility_guard_spec.rb --- spec/install/bundler_spec.rb | 4 ++-- spec/lock/lockfile_bundler_1_spec.rb | 2 ++ spec/lock/lockfile_spec.rb | 2 ++ spec/other/compatibility_guard_spec.rb | 6 ++++-- spec/support/hax.rb | 8 ++++++++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/spec/install/bundler_spec.rb b/spec/install/bundler_spec.rb index fd7d44d664..3c5ae0a84f 100644 --- a/spec/install/bundler_spec.rb +++ b/spec/install/bundler_spec.rb @@ -134,7 +134,7 @@ RSpec.describe "bundle install" do simulate_bundler_version "99999999.99.1" - bundle! "check" + bundle! "check", :env => { "BUNDLER_SPEC_IGNORE_COMPATIBILITY_GUARD" => "1" } expect(out).to include("The Gemfile's dependencies are satisfied") end @@ -147,7 +147,7 @@ RSpec.describe "bundle install" do simulate_bundler_version "99999999.99.1" - bundle! "check" + bundle! "check", :env => { "BUNDLER_SPEC_IGNORE_COMPATIBILITY_GUARD" => "1" } expect(out).to include("The Gemfile's dependencies are satisfied") end diff --git a/spec/lock/lockfile_bundler_1_spec.rb b/spec/lock/lockfile_bundler_1_spec.rb index cf283d50fd..1aab5e7750 100644 --- a/spec/lock/lockfile_bundler_1_spec.rb +++ b/spec/lock/lockfile_bundler_1_spec.rb @@ -3,6 +3,8 @@ RSpec.describe "the lockfile format", :bundler => "< 2" do include Bundler::GemHelpers + before { ENV["BUNDLER_SPEC_IGNORE_COMPATIBILITY_GUARD"] = "TRUE" } + it "generates a simple lockfile for a single source, gem" do install_gemfile <<-G source "file://#{gem_repo1}" diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index 14cf94bdb7..bcf31d9f2c 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -3,6 +3,8 @@ RSpec.describe "the lockfile format", :bundler => "2" do include Bundler::GemHelpers + before { ENV["BUNDLER_SPEC_IGNORE_COMPATIBILITY_GUARD"] = "TRUE" } + it "generates a simple lockfile for a single source, gem" do install_gemfile <<-G source "file://#{gem_repo1}" diff --git a/spec/other/compatibility_guard_spec.rb b/spec/other/compatibility_guard_spec.rb index 8f458b18e5..ac05ebd918 100644 --- a/spec/other/compatibility_guard_spec.rb +++ b/spec/other/compatibility_guard_spec.rb @@ -4,14 +4,16 @@ RSpec.describe "bundler compatibility guard" do context "when the bundler version is 2+" do before { simulate_bundler_version "2.0.a" } - context "when running on Ruby < 2", :ruby => "< 2.3" do + context "when running on Ruby < 2.3", :ruby => "< 2.3" do + before { simulate_rubygems_version "2.6.11" } + it "raises a friendly error" do bundle :version expect(err).to eq("Bundler 2 requires Ruby 2.3 or later. Either install bundler 1 or update to a supported Ruby version.") end end - context "when running on RubyGems < 2" do + context "when running on RubyGems < 2.5", :ruby => ">= 2.5" do before { simulate_rubygems_version "1.3.6" } it "raises a friendly error" do diff --git a/spec/support/hax.rb b/spec/support/hax.rb index d1cea40922..aee55a0ac9 100644 --- a/spec/support/hax.rb +++ b/spec/support/hax.rb @@ -51,3 +51,11 @@ class Object end end end + +if ENV["BUNDLER_SPEC_IGNORE_COMPATIBILITY_GUARD"] + $LOADED_FEATURES << File.expand_path("../../../bundler/compatibility_guard.rb", __FILE__) + $LOADED_FEATURES << File.expand_path("../../../bundler/compatibility_guard", __FILE__) + $LOADED_FEATURES << "bundler/compatibility_guard.rb" + $LOADED_FEATURES << "bundler/compatibility_guard" + require "bundler/compatibility_guard" +end -- cgit v1.2.1 From f0bbb6be4f6e699666b44f00c627b81d3184faa3 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Thu, 17 Aug 2017 23:44:45 -0400 Subject: Ensure versions are unfrozen for super old RG --- lib/bundler/compatibility_guard.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bundler/compatibility_guard.rb b/lib/bundler/compatibility_guard.rb index 8904d014f5..750a1db04f 100644 --- a/lib/bundler/compatibility_guard.rb +++ b/lib/bundler/compatibility_guard.rb @@ -4,7 +4,7 @@ require "rubygems" require "bundler/version" if Bundler::VERSION.split(".").first.to_i >= 2 - if Gem::Version.new(Object::RUBY_VERSION) < Gem::Version.new("2.3") + if Gem::Version.new(Object::RUBY_VERSION.dup) < Gem::Version.new("2.3") abort "Bundler 2 requires Ruby 2.3 or later. Either install bundler 1 or update to a supported Ruby version." end -- cgit v1.2.1