diff options
author | Bundlerbot <bot@bundler.io> | 2019-07-23 15:37:39 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2019-07-23 15:37:39 +0000 |
commit | 708bb7b6088cff9cb5cfd82f2424b50f8b1d49bd (patch) | |
tree | 4309cacbfeb6b7b51522ef3a25ed7241d6ae825b | |
parent | a9beb66ed23d9ea5bb1b07256400b503fad80a62 (diff) | |
parent | 6d0a8f4128dbfe855a33421c85419d09d1311d01 (diff) | |
download | bundler-708bb7b6088cff9cb5cfd82f2424b50f8b1d49bd.tar.gz |
Merge #7255
7255: Improve environment backup and restore r=hsbt a=deivid-rodriguez
### What was the end-user problem that led to this PR?
The problem was that the specs were removing some environment variables for every tests, but not all of them, causing problems on some environments (see #7251).
### What was your diagnosis of the problem?
My diagnosis was that we don't really need to do this.
### What is your fix for the problem, implemented in this PR?
My fix is to stop doing it, and fix the very few specs that failed after the change. One of the failures actually led to a bug fix (I think), see 6c27ebb.
### Why did you choose this fix out of the possible options?
I chose this fix because I think it's cleaner than adding a public constant in `lib/` only to fix a problem with the specs, like it's done in #7251.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
-rw-r--r-- | lib/bundler/environment_preserver.rb | 1 | ||||
-rw-r--r-- | spec/runtime/with_unbundled_env_spec.rb | 8 | ||||
-rw-r--r-- | spec/spec_helper.rb | 8 |
3 files changed, 10 insertions, 7 deletions
diff --git a/lib/bundler/environment_preserver.rb b/lib/bundler/environment_preserver.rb index af7c1ef0a4..c9014badad 100644 --- a/lib/bundler/environment_preserver.rb +++ b/lib/bundler/environment_preserver.rb @@ -6,7 +6,6 @@ module Bundler BUNDLER_KEYS = %w[ BUNDLE_BIN_PATH BUNDLE_GEMFILE - BUNDLER_ORIG_MANPATH BUNDLER_VERSION GEM_HOME GEM_PATH diff --git a/spec/runtime/with_unbundled_env_spec.rb b/spec/runtime/with_unbundled_env_spec.rb index b901f28c8b..d5eed096c2 100644 --- a/spec/runtime/with_unbundled_env_spec.rb +++ b/spec/runtime/with_unbundled_env_spec.rb @@ -54,6 +54,9 @@ RSpec.describe "Bundler.with_env helpers" do end it "removes variables that bundler added", :ruby_repo do + # Simulate bundler has not yet been loaded + ENV.replace(ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) }) + original = ruby!('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")') code = 'puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n")' bundle_exec_ruby! code.dump @@ -76,11 +79,12 @@ RSpec.describe "Bundler.with_env helpers" do expect(last_command.stdboth).not_to include("-rbundler/setup") end - it "should clean up RUBYLIB", :ruby_repo do + it "should restore RUBYLIB", :ruby_repo do code = "print #{modified_env}['RUBYLIB']" ENV["RUBYLIB"] = root.join("lib").to_s + File::PATH_SEPARATOR + "/foo" + ENV["BUNDLER_ORIG_RUBYLIB"] = root.join("lib").to_s + File::PATH_SEPARATOR + "/foo-original" bundle_exec_ruby! code.dump - expect(last_command.stdboth).to include("/foo") + expect(last_command.stdboth).to include("/foo-original") end it "should restore the original MANPATH" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a90d8e9885..e3af0f55d2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -78,7 +78,7 @@ RSpec.configure do |config| config.filter_run_when_matching :focus unless ENV["CI"] original_wd = Dir.pwd - original_env = ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) } + original_env = ENV.to_hash config.expect_with :rspec do |c| c.syntax = :expect @@ -99,13 +99,13 @@ RSpec.configure do |config| config.before :suite do Spec::Rubygems.setup - ENV["RUBYOPT"] = original_env["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb" - ENV["BUNDLE_SPEC_RUN"] = original_env["BUNDLE_SPEC_RUN"] = "true" + ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb" + ENV["BUNDLE_SPEC_RUN"] = "true" # Don't wrap output in tests ENV["THOR_COLUMNS"] = "10000" - original_env = ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) } + original_env = ENV.to_hash if ENV["BUNDLE_RUBY"] FileUtils.cp_r Spec::Path.bindir, File.join(Spec::Path.root, "lib", "exe") |