summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-07-20 12:23:16 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-07-21 09:33:01 -0500
commit39898f4c8de84304c3755ec602ec39d5fd8a7184 (patch)
tree09dde4eaf30e169d29b4da3880a8db889d170539
parent01fe509b27b317dd4d640beb9140ab31331ea349 (diff)
downloadbundler-39898f4c8de84304c3755ec602ec39d5fd8a7184.tar.gz
Handle when Bundler is only available on the load path
-rw-r--r--lib/bundler/templates/Executable.bundler19
-rw-r--r--spec/install/binstubs_spec.rb2
-rw-r--r--spec/runtime/executable_spec.rb6
3 files changed, 20 insertions, 7 deletions
diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler
index 351eca7427..a9103ff6bd 100644
--- a/lib/bundler/templates/Executable.bundler
+++ b/lib/bundler/templates/Executable.bundler
@@ -57,11 +57,24 @@ m = Module.new do
end
def activate_bundler(bundler_version)
- gem "bundler", bundler_version
- rescue StandardError, LoadError => e
- warn "Activating bundler (#{bundler_version}) failed:\n#{e.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
+ gem_error = activation_error_handling do
+ gem "bundler", bundler_version
+ end
+ return if gem_error.nil?
+ require_error = activation_error_handling do
+ require "bundler/version"
+ end
+ return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
+ warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
exit 42
end
+
+ def activation_error_handling
+ yield
+ nil
+ rescue StandardError, LoadError => e
+ e
+ end
end
m.load_bundler!
diff --git a/spec/install/binstubs_spec.rb b/spec/install/binstubs_spec.rb
index e5acc84e6a..9f361035e0 100644
--- a/spec/install/binstubs_spec.rb
+++ b/spec/install/binstubs_spec.rb
@@ -38,7 +38,7 @@ RSpec.describe "bundle install" do
it "prints a deprecation notice" do
bundle "config major_deprecations true"
gembin("rackup")
- expect(out).to include("Bundler is using a binstub that was created for a different gem.")
+ expect(out).to include("Bundler is using a binstub that was created for a different gem (rack).")
end
it "loads the correct spec's executable" do
diff --git a/spec/runtime/executable_spec.rb b/spec/runtime/executable_spec.rb
index 545fc97330..388ee049d0 100644
--- a/spec/runtime/executable_spec.rb
+++ b/spec/runtime/executable_spec.rb
@@ -78,7 +78,7 @@ RSpec.describe "Running bin/* commands" do
expect(out).to eq("1.0")
end
- it "don't bundle da bundla" do
+ it "creates a bundle binstub" do
build_gem "bundler", Bundler::VERSION, :to_system => true do |s|
s.executables = "bundle"
end
@@ -88,9 +88,9 @@ RSpec.describe "Running bin/* commands" do
gem "bundler"
G
- bundle "binstubs bundler"
+ bundle! "binstubs bundler"
- expect(bundled_app("bin/bundle")).not_to exist
+ expect(bundled_app("bin/bundle")).to exist
end
it "does not generate bin stubs if the option was not specified" do