diff options
Diffstat (limited to 'spec/bundler/runtime/with_clean_env_spec.rb')
-rw-r--r-- | spec/bundler/runtime/with_clean_env_spec.rb | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/spec/bundler/runtime/with_clean_env_spec.rb b/spec/bundler/runtime/with_clean_env_spec.rb index 05b334c28a..c88da3cd02 100644 --- a/spec/bundler/runtime/with_clean_env_spec.rb +++ b/spec/bundler/runtime/with_clean_env_spec.rb @@ -1,6 +1,14 @@ # frozen_string_literal: true RSpec.describe "Bundler.with_env helpers" do + def bundle_exec_ruby!(code, *args) + opts = args.last.is_a?(Hash) ? args.pop : {} + env = opts[:env] ||= {} + env[:RUBYOPT] ||= "-r#{spec_dir.join("support/hax")}" + args.push opts + bundle! "exec '#{Gem.ruby}' -e #{code}", *args + end + describe "Bundler.original_env" do before do bundle "config path vendor/bundle" @@ -12,8 +20,8 @@ RSpec.describe "Bundler.with_env helpers" do code = "print Bundler.original_env['PATH']" path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo" with_path_as(path) do - result = bundle("exec '#{Gem.ruby}' -e #{code.dump}") - expect(result).to eq(path) + bundle_exec_ruby!(code.dump) + expect(last_command.stdboth).to eq(path) end end @@ -21,8 +29,8 @@ 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 '#{Gem.ruby}' -e #{code.inspect}") - expect(result).to eq(gem_path) + bundle_exec_ruby!(code.dump) + expect(last_command.stdboth).to eq(gem_path) end end @@ -38,7 +46,7 @@ RSpec.describe "Bundler.with_env helpers" do RB path = `getconf PATH`.strip + File::PATH_SEPARATOR + File.dirname(Gem.ruby) with_path_as(path) do - bundle!("exec '#{Gem.ruby}' #{bundled_app("exe.rb")} 2") + bundle! "exec '#{Gem.ruby}' #{bundled_app("exe.rb")} 2", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } end expect(err).to eq <<-EOS.strip 2 false @@ -48,10 +56,9 @@ RSpec.describe "Bundler.with_env helpers" do 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")') + original = ruby!('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")', :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" }) code = 'puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n")' - bundle!("exec '#{Gem.ruby}' -e #{code.inspect}", :system_bundler => true) + bundle! "exec '#{Gem.ruby}' -e #{code.dump}", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq original end end @@ -66,30 +73,30 @@ RSpec.describe "Bundler.with_env helpers" do it "should delete BUNDLE_PATH" do code = "print Bundler.clean_env.has_key?('BUNDLE_PATH')" ENV["BUNDLE_PATH"] = "./foo" - result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") - expect(result).to eq("false") + bundle_exec_ruby! code.dump + expect(last_command.stdboth).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 '#{Gem.ruby}' -e #{code.inspect}") - expect(result).not_to include("-rbundler/setup") + bundle_exec_ruby! code.dump + expect(last_command.stdboth).not_to include("-rbundler/setup") end it "should clean up RUBYLIB", :ruby_repo do code = "print Bundler.clean_env['RUBYLIB']" ENV["RUBYLIB"] = root.join("lib").to_s + File::PATH_SEPARATOR + "/foo" - result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") - expect(result).to eq("/foo") + bundle_exec_ruby! code.dump + expect(last_command.stdboth).to eq("/foo") end it "should restore the original MANPATH" do code = "print Bundler.clean_env['MANPATH']" ENV["MANPATH"] = "/foo" ENV["BUNDLER_ORIG_MANPATH"] = "/foo-original" - result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}") - expect(result).to eq("/foo-original") + bundle_exec_ruby! code.dump + expect(last_command.stdboth).to eq("/foo-original") end end |