diff options
author | Jonathan Dance <jd@wuputah.com> | 2011-02-23 22:29:11 -0600 |
---|---|---|
committer | Jonathan Dance <jd@wuputah.com> | 2011-02-25 15:55:21 -0600 |
commit | 5cf3fde78c2660ff8a815f376921438fd641c67d (patch) | |
tree | fe996f0570add648dac32355bb8747aeda5c3e89 | |
parent | 782a11ee9cc20183593f174d73364e0b4efd5dc7 (diff) | |
download | bundler-5cf3fde78c2660ff8a815f376921438fd641c67d.tar.gz |
with_clean_env clears bundler env vars
old behavior is at Bundler.with_original_env
-rw-r--r-- | lib/bundler.rb | 9 | ||||
-rw-r--r-- | spec/runtime/with_clean_env_spec.rb | 38 |
2 files changed, 43 insertions, 4 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 5e3b601f16..0ee8aceb86 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -185,7 +185,7 @@ module Bundler @settings ||= Settings.new(app_config_path) end - def with_clean_env + def with_original_env bundled_env = ENV.to_hash ENV.replace(ORIGINAL_ENV) yield @@ -193,6 +193,13 @@ module Bundler ENV.replace(bundled_env.to_hash) end + def with_clean_env + with_original_env do + ENV.delete_if { |k,_| k[0,7] == 'BUNDLE_' } + yield + end + end + def default_gemfile SharedHelpers.default_gemfile end diff --git a/spec/runtime/with_clean_env_spec.rb b/spec/runtime/with_clean_env_spec.rb index 51ecc29e53..b0d4094b28 100644 --- a/spec/runtime/with_clean_env_spec.rb +++ b/spec/runtime/with_clean_env_spec.rb @@ -1,7 +1,6 @@ require "spec_helper" -describe "Bundler.with_clean_env" do - +shared_examples_for "Bundler.with_*_env" do it "should reset and restore the environment" do gem_path = ENV['GEM_PATH'] @@ -11,5 +10,38 @@ describe "Bundler.with_clean_env" do ENV['GEM_PATH'].should == gem_path end +end + +describe "Bundler.with_clean_env" do + + it_should_behave_like "Bundler.with_*_env" + + it "should not pass any bundler environment variables" do + bundle_path = Bundler::ORIGINAL_ENV['BUNDLE_PATH'] + Bundler::ORIGINAL_ENV['BUNDLE_PATH'] = "./Gemfile" + + Bundler.with_clean_env do + `echo $BUNDLE_PATH`.strip.should_not == './Gemfile' + end + + Bundler::ORIGINAL_ENV['BUNDLE_PATH'] = bundle_path + end + +end + +describe "Bundler.with_original_env" do + + it_should_behave_like "Bundler.with_*_env" + + it "should pass bundler environment variables set before Bundler was run" do + bundle_path = Bundler::ORIGINAL_ENV['BUNDLE_PATH'] + Bundler::ORIGINAL_ENV['BUNDLE_PATH'] = "./Gemfile" + + Bundler.with_original_env do + `echo $BUNDLE_PATH`.strip.should == './Gemfile' + end + + Bundler::ORIGINAL_ENV['BUNDLE_PATH'] = bundle_path + end -end
\ No newline at end of file +end |