Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Bundler.with_clean_env for blocks of ruby without a bundled env

e.g. if you are in a bundled Rakefile but need to shell out to
something on your system that uses ruby like Homebrew

Fixes #225
  • Loading branch information...
commit 33154fd6865d5006a91381c92b7b83ba1c3b59cd 1 parent 5b9b2c3
@joshbuddy joshbuddy authored indirect committed
Showing with 25 additions and 0 deletions.
  1. +10 −0 lib/bundler.rb
  2. +15 −0 spec/runtime/with_clean_env_spec.rb
View
10 lib/bundler.rb
@@ -3,8 +3,10 @@
require 'yaml'
require 'bundler/rubygems_ext'
+
module Bundler
VERSION = "0.10.pre"
+ ORIGINAL_ENV = ENV.to_hash
autoload :Definition, 'bundler/definition'
autoload :Dependency, 'bundler/dependency'
@@ -109,6 +111,14 @@ def settings
@settings ||= Settings.new(root)
end
+ def with_clean_env
+ bundled_env = ENV.to_hash
+ ENV.replace(ORIGINAL_ENV)
+ yield
+ ensure
+ ENV.replace(bundled_env.to_hash)
+ end
+
private
def default_gemfile
View
15 spec/runtime/with_clean_env_spec.rb
@@ -0,0 +1,15 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+describe "Bundler.with_clean_env" do
+
+ it "should reset and restore the environment" do
+ gem_path = ENV['GEM_PATH']
+
+ Bundler.with_clean_env do
+ `echo $GEM_PATH`.strip.should_not == gem_path
+ end
+
+ ENV['GEM_PATH'].should == gem_path
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.