diff --git a/lib/spring/application.rb b/lib/spring/application.rb index e19b8b5b..d41917df 100644 --- a/lib/spring/application.rb +++ b/lib/spring/application.rb @@ -134,16 +134,19 @@ def run end def with_env_vars(env) - # Delete all env vars which are unchanged from before spring started - original_env.each { |k, v| ENV.delete k if ENV[k] == v } + # Allowed are keys currently not in ENV... + allowed_keys = env.keys - ENV.keys + # ...and ENV-keys whose values have not changed since the start of spring + allowed_keys += original_env.select {|k, v| ENV[k] == v }.keys + # never allowed: + allowed_keys -= %w(RUBYOPT RUBY_ROOT BUNDLE_GEMFILE GEM_ROOT GEM_HOME GEM_PATH) + allowed_keys.uniq! - changed_keys = env.keys - ENV.keys - # Load in the current env vars, except those which *were* changed when spring started - env.each { |k, v| ENV[k] ||= v } + allowed_keys.each{|k| ENV[k] = env[k] } yield ensure - changed_keys.each do |k| + allowed_keys.each do |k| original_env.has_key?(k) ? ENV[k] = original_env[k] : ENV.delete(k) end end