diff options
Diffstat (limited to 'spec/bundler/runtime/with_clean_env_spec.rb')
-rw-r--r-- | spec/bundler/runtime/with_clean_env_spec.rb | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/spec/bundler/runtime/with_clean_env_spec.rb b/spec/bundler/runtime/with_clean_env_spec.rb index d18a0de485..55e45460db 100644 --- a/spec/bundler/runtime/with_clean_env_spec.rb +++ b/spec/bundler/runtime/with_clean_env_spec.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "Bundler.with_env helpers" do describe "Bundler.original_env" do before do + bundle "config path vendor/bundle" gemfile "" - bundle "install --path vendor/bundle" + bundle "install" end it "should return the PATH present before bundle was activated", :ruby_repo do code = "print Bundler.original_env['PATH']" path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo" with_path_as(path) do - result = bundle("exec ruby -e #{code.dump}") + result = bundle("exec '#{Gem.ruby}' -e #{code.dump}") expect(result).to eq(path) end end @@ -21,7 +21,7 @@ RSpec.describe "Bundler.with_env helpers" do code = "print Bundler.original_env['GEM_PATH']" gem_path = ENV["GEM_PATH"] + ":/foo" with_gem_path_as(gem_path) do - result = bundle("exec ruby -e #{code.inspect}") + result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") expect(result).to eq(gem_path) end end @@ -34,11 +34,11 @@ RSpec.describe "Bundler.with_env helpers" do if count == 2 ENV["PATH"] = "#{ENV["PATH"]}:/foo" end - exec("ruby", __FILE__, (count - 1).to_s) + exec(Gem.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") + bundle!("exec '#{Gem.ruby}' #{bundled_app("exe.rb")} 2") end expect(err).to eq <<-EOS.strip 2 false @@ -46,25 +46,34 @@ RSpec.describe "Bundler.with_env helpers" do 0 true EOS end + + it "removes variables that bundler added", :ruby_repo do + system_gems :bundler + 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 '#{Gem.ruby}' -e #{code.inspect}", :system_bundler => true) + expect(out).to eq original + end end - describe "Bundler.clean_env" do + describe "Bundler.clean_env", :bundler => "< 2" do before do + bundle "config path vendor/bundle" gemfile "" - bundle "install --path vendor/bundle" + bundle "install" end it "should delete BUNDLE_PATH" do code = "print Bundler.clean_env.has_key?('BUNDLE_PATH')" ENV["BUNDLE_PATH"] = "./foo" - result = bundle("exec ruby -e #{code.inspect}") + result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") expect(result).to eq("false") end it "should remove '-rbundler/setup' from RUBYOPT" do code = "print Bundler.clean_env['RUBYOPT']" ENV["RUBYOPT"] = "-W2 -rbundler/setup" - result = bundle("exec ruby -e #{code.inspect}") + result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") expect(result).not_to include("-rbundler/setup") end @@ -79,7 +88,7 @@ RSpec.describe "Bundler.with_env helpers" do code = "print Bundler.clean_env['MANPATH']" ENV["MANPATH"] = "/foo" ENV["BUNDLER_ORIG_MANPATH"] = "/foo-original" - result = bundle("exec ruby -e #{code.inspect}") + result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") expect(result).to eq("/foo-original") end end @@ -100,7 +109,7 @@ RSpec.describe "Bundler.with_env helpers" do end end - describe "Bundler.with_clean_env" do + describe "Bundler.with_clean_env", :bundler => "< 2" do it "should set ENV to clean_env in the block" do expected = Bundler.clean_env actual = Bundler.with_clean_env { ENV.to_hash } @@ -116,14 +125,14 @@ RSpec.describe "Bundler.with_env helpers" do end end - describe "Bundler.clean_system", :ruby => ">= 1.9" do + describe "Bundler.clean_system", :ruby => ">= 1.9", :bundler => "< 2" do it "runs system inside with_clean_env" do Bundler.clean_system(%(echo 'if [ "$BUNDLE_PATH" = "" ]; then exit 42; else exit 1; fi' | /bin/sh)) expect($?.exitstatus).to eq(42) end end - describe "Bundler.clean_exec", :ruby => ">= 1.9" do + describe "Bundler.clean_exec", :ruby => ">= 1.9", :bundler => "< 2" do it "runs exec inside with_clean_env" do pid = Kernel.fork do Bundler.clean_exec(%(echo 'if [ "$BUNDLE_PATH" = "" ]; then exit 42; else exit 1; fi' | /bin/sh)) |