summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-04-14 22:33:32 -0500
committerSamuel Giddins <segiddins@segiddins.me>2016-04-14 22:34:15 -0500
commit0fa0830658c04bf9c88ce0bbfffd02ad55ef8193 (patch)
treeb9777ae7ecf245e0121dc5cc43c290815e48be2d
parent3a09448d8b060f2688dbc73bfa1eb08e1bd126f3 (diff)
downloadbundler-0fa0830658c04bf9c88ce0bbfffd02ad55ef8193.tar.gz
[EnvironmentPreserver] Fix restoring environment
This allows a bundle exec after the path has been changed inside a bundle exec'd program to access the changes
-rw-r--r--lib/bundler/environment_preserver.rb2
-rw-r--r--spec/runtime/with_clean_env_spec.rb25
2 files changed, 24 insertions, 3 deletions
diff --git a/lib/bundler/environment_preserver.rb b/lib/bundler/environment_preserver.rb
index 0dd2c1ed61..0efd101bfe 100644
--- a/lib/bundler/environment_preserver.rb
+++ b/lib/bundler/environment_preserver.rb
@@ -11,7 +11,7 @@ module Bundler
# @return [Hash]
def backup
- env = restore.clone
+ env = @original.clone
@keys.each do |key|
value = env[key]
env[@prefix + key] = value unless value.nil? || value.empty?
diff --git a/spec/runtime/with_clean_env_spec.rb b/spec/runtime/with_clean_env_spec.rb
index 9939f1294e..5ab72ed1ce 100644
--- a/spec/runtime/with_clean_env_spec.rb
+++ b/spec/runtime/with_clean_env_spec.rb
@@ -10,9 +10,9 @@ describe "Bundler.with_env helpers" do
it "should return the PATH present before bundle was activated" do
code = "print Bundler.original_env['PATH']"
- path = `getconf PATH`.strip + ":/foo"
+ path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo"
with_path_as(path) do
- result = bundle("exec ruby -e #{code.inspect}")
+ result = bundle("exec ruby -e #{code.dump}")
expect(result).to eq(path)
end
end
@@ -25,6 +25,27 @@ describe "Bundler.with_env helpers" do
expect(result).to eq(gem_path)
end
end
+
+ it "works with nested bundle exec invocations" do
+ create_file("exe.rb", <<-'RB')
+ count = ARGV.first.to_i
+ exit if count < 0
+ STDERR.puts "#{count} #{ENV["PATH"].end_with?(":/foo")}"
+ if count == 2
+ ENV["PATH"] = "#{ENV["PATH"]}:/foo"
+ end
+ exec("ruby", __FILE__, (count - 1).to_s)
+ RB
+ path = `getconf PATH`.strip + File::PATH_SEPARATOR + File.dirname(Gem.ruby)
+ with_path_as(path) do
+ bundle!("exec ruby #{bundled_app("exe.rb")} 2", :expect_err => true)
+ end
+ expect(err).to eq <<-EOS.strip
+2 false
+1 true
+0 true
+ EOS
+ end
end
describe "Bundler.clean_env" do