diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 7ff391ab601..dca17885dd4 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -300,7 +300,12 @@ def set_env(key, value) def set_bundle_variables begin - Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", Bundler.rubygems.bin_path("bundler", "bundle", VERSION) + exe_file = Bundler.rubygems.bin_path("bundler", "bundle", VERSION) + unless File.exist?(exe_file) + exe_file = File.expand_path("../../../exe/bundle", __FILE__) + end + + Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file rescue Gem::GemNotFoundException Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", File.expand_path("../../../exe/bundle", __FILE__) end diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index b8f099d5ba5..72b1c2a51fc 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/bundler/shared_helpers_spec.rb @@ -378,6 +378,16 @@ it_behaves_like "ENV['RUBYLIB'] gets set correctly" end + context "bundle executable in ENV['BUNDLE_BIN_PATH'] does not exist" do + before { ENV["BUNDLE_BIN_PATH"] = "/does/not/exist" } + before { Bundler.rubygems.replace_bin_path [], [] } + + it "sets BUNDLE_BIN_PATH to the bundle executable file" do + subject.set_bundle_environment + expect(ENV["BUNDLE_BIN_PATH"]).to eq(File.expand_path("../../../exe/bundle", __FILE__)) + end + end + context "ENV['RUBYLIB'] already contains the bundler's ruby version lib path" do let(:ruby_lib_path) { "stubbed_ruby_lib_dir" }