diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index e09e5e8b745..6a0da52e1ed 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -3,6 +3,7 @@ require "bundler/compatibility_guard" require "pathname" +require "rbconfig" require "rubygems" require "bundler/version" @@ -341,7 +342,7 @@ def set_rubyopt def set_rubylib rubylib = (ENV["RUBYLIB"] || "").split(File::PATH_SEPARATOR) - rubylib.unshift bundler_ruby_lib + rubylib.unshift bundler_ruby_lib unless RbConfig::CONFIG["rubylibdir"] == bundler_ruby_lib Bundler::SharedHelpers.set_env "RUBYLIB", rubylib.uniq.join(File::PATH_SEPARATOR) end diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index b66c43fd928..fcac37b3986 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/bundler/shared_helpers_spec.rb @@ -261,6 +261,15 @@ subject.set_bundle_environment end + it "ignores if bundler_ruby_lib is same as rubylibdir" do + allow(Bundler::SharedHelpers).to receive(:bundler_ruby_lib).and_return(RbConfig::CONFIG["rubylibdir"]) + + subject.set_bundle_environment + + paths = (ENV["RUBYLIB"]).split(File::PATH_SEPARATOR) + expect(paths.count(RbConfig::CONFIG["rubylibdir"])).to eq(0) + end + it "exits if bundle path contains the unix-like path separator" do if Gem.respond_to?(:path_separator) allow(Gem).to receive(:path_separator).and_return(":")