summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-06-13 15:48:21 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-08-17 23:43:22 -0400
commit10fb9743f55354ceb72e445fed67b16555d879a2 (patch)
treeafb68f01bcdc0c5e66a251630a2e0424cb7b9eda
parentac7b13838aa1314964405a2586f2769d0cb041b4 (diff)
downloadbundler-10fb9743f55354ceb72e445fed67b16555d879a2.tar.gz
Add a compatibility guard that prints friendly errors on bundler 2+
-rw-r--r--lib/bundler.rb1
-rw-r--r--lib/bundler/compatibility_guard.rb14
-rw-r--r--lib/bundler/inline.rb1
-rw-r--r--lib/bundler/shared_helpers.rb1
-rw-r--r--spec/other/compatibility_guard_spec.rb23
5 files changed, 40 insertions, 0 deletions
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