summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-01-30 19:57:30 -0600
committerAndre Arko <andre@arko.net>2016-01-31 14:05:00 -0800
commitd713762416079b862d287b5806c4e6f5e7b4146c (patch)
treeb54603bdfca5be26ed07532747b7ddf462cbef65
parent6c2664fe442209d84d8b6954e7eba2b2fe034a21 (diff)
downloadbundler-d713762416079b862d287b5806c4e6f5e7b4146c.tar.gz
Preserve PATH in with_clean_env
-rw-r--r--lib/bundler.rb1
-rw-r--r--lib/bundler/gem_path_manipulation.rb7
-rw-r--r--spec/runtime/with_clean_env_spec.rb15
3 files changed, 23 insertions, 0 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index a9145cf92b..d6af64052e 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -13,6 +13,7 @@ require "bundler/errors"
module Bundler
preserve_gem_path
+ preserve_path
ORIGINAL_ENV = ENV.to_hash
SUDO_MUTEX = Mutex.new
diff --git a/lib/bundler/gem_path_manipulation.rb b/lib/bundler/gem_path_manipulation.rb
index 628d954c35..3a89b91e50 100644
--- a/lib/bundler/gem_path_manipulation.rb
+++ b/lib/bundler/gem_path_manipulation.rb
@@ -5,4 +5,11 @@ module Bundler
ENV["_ORIGINAL_GEM_PATH"] = gem_path if original_gem_path.nil? || original_gem_path == ""
ENV["GEM_PATH"] = original_gem_path if gem_path.nil? || gem_path == ""
end
+
+ def self.preserve_path
+ original_path = ENV["_ORIGINAL_PATH"]
+ path = ENV["PATH"]
+ ENV["_ORIGINAL_PATH"] = path if original_path.nil? || original_path == ""
+ ENV["PATH"] = original_path if path.nil? || path == ""
+ end
end
diff --git a/spec/runtime/with_clean_env_spec.rb b/spec/runtime/with_clean_env_spec.rb
index 0ceb4adf05..55c6ed98ed 100644
--- a/spec/runtime/with_clean_env_spec.rb
+++ b/spec/runtime/with_clean_env_spec.rb
@@ -4,12 +4,15 @@ describe "Bundler.with_env helpers" do
shared_examples_for "Bundler.with_*_env" do
it "should reset and restore the environment" do
gem_path = ENV["GEM_PATH"]
+ path = ENV["PATH"]
Bundler.with_clean_env do
expect(`echo $GEM_PATH`.strip).not_to eq(gem_path)
+ expect(`echo $PATH`.strip).not_to eq(path)
end
expect(ENV["GEM_PATH"]).to eq(gem_path)
+ expect(ENV["PATH"]).to eq(path)
end
end
@@ -35,6 +38,18 @@ describe "Bundler.with_env helpers" do
expect(result).to eq("true")
end
+ it "should keep the original PATH even in sub processes" do
+ gemfile ""
+ bundle "install --path vendor/bundle"
+
+ code = "Bundler.with_clean_env do;" \
+ " print ENV['PATH'] != '';" \
+ "end"
+
+ result = bundle "exec ruby -e #{code.inspect}"
+ expect(result).to eq("true")
+ end
+
it "should not pass any bundler environment variables" do
Bundler.with_clean_env do
expect(`echo $BUNDLE_PATH`.strip).not_to eq("./Gemfile")