diff options
-rw-r--r-- | spec/commands/exec_spec.rb | 18 | ||||
-rw-r--r-- | spec/commands/newgem_spec.rb | 4 | ||||
-rw-r--r-- | spec/install/gemfile/sources_spec.rb | 5 | ||||
-rw-r--r-- | spec/runtime/gem_tasks_spec.rb | 6 | ||||
-rw-r--r-- | spec/runtime/require_spec.rb | 6 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 8 | ||||
-rw-r--r-- | spec/runtime/with_clean_env_spec.rb | 37 |
7 files changed, 49 insertions, 35 deletions
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index ae31487937..1bedaa690e 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -29,7 +29,7 @@ RSpec.describe "bundle exec" do gem "rack" G - bundle "exec 'cd #{tmp("gems")} && rackup'" + bundle "exec 'cd #{tmp("gems")} && rackup'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to include("1.0.0") end @@ -42,7 +42,7 @@ RSpec.describe "bundle exec" do it "works when exec'ing to ruby" do install_gemfile 'gem "rack"' - bundle "exec ruby -e 'puts %{hi}'" + bundle "exec ruby -e 'puts %{hi}'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("hi") end @@ -76,7 +76,9 @@ RSpec.describe "bundle exec" do G install_gemfile "" - sys_exec("#{Gem.ruby} #{command.path}") + with_env_vars "RUBYOPT" => "-r#{spec_dir.join("support/hax")}" do + sys_exec "#{Gem.ruby} #{command.path}" + end if Bundler.current_ruby.ruby_2? expect(out).to eq("") @@ -237,7 +239,7 @@ RSpec.describe "bundle exec" do G [true, false].each do |l| bundle! "config disable_exec_load #{l}" - bundle "exec rackup" + bundle "exec rackup", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(last_command.stderr).to include "rack is not part of the bundle. Add it to your Gemfile." end end @@ -339,14 +341,14 @@ RSpec.describe "bundle exec" do end it "works when unlocked" do - bundle "exec 'cd #{tmp("gems")} && rackup'" + bundle "exec 'cd #{tmp("gems")} && rackup'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("1.0.0") expect(out).to include("1.0.0") end it "works when locked" do expect(the_bundle).to be_locked - bundle "exec 'cd #{tmp("gems")} && rackup'" + bundle "exec 'cd #{tmp("gems")} && rackup'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to include("1.0.0") end end @@ -472,7 +474,7 @@ RSpec.describe "bundle exec" do Bundler.rubygems.extend(Monkey) G bundle "install --deployment" - bundle "exec ruby -e '`#{bindir.join("bundler")} -v`; puts $?.success?'" + bundle "exec ruby -e '`#{bindir.join("bundler")} -v`; puts $?.success?'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to match("true") end end @@ -512,7 +514,7 @@ RSpec.describe "bundle exec" do let(:expected) { [exec, args, rack, process].join("\n") } let(:expected_err) { "" } - subject { bundle "exec #{path} arg1 arg2" } + subject { bundle "exec #{path} arg1 arg2", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } } shared_examples_for "it runs" do it "like a normally executed executable" do diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 494599abf1..1a3e8236b6 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -191,7 +191,7 @@ RSpec.describe "bundle gem" do it "generates a valid gemspec" do in_app_root - bundle "gem newgem --bin" + bundle! "gem newgem --bin" process_file(bundled_app("newgem", "newgem.gemspec")) do |line| # Simulate replacing TODOs with real values @@ -211,7 +211,7 @@ RSpec.describe "bundle gem" do end Dir.chdir(bundled_app("newgem")) do - system_gems ["rake-10.0.2"], :path => :bundle_path + system_gems ["rake-10.0.2", :bundler], :path => :bundle_path bundle! "exec rake build" end diff --git a/spec/install/gemfile/sources_spec.rb b/spec/install/gemfile/sources_spec.rb index 1a4e87514f..8ba3ec2d27 100644 --- a/spec/install/gemfile/sources_spec.rb +++ b/spec/install/gemfile/sources_spec.rb @@ -435,12 +435,11 @@ RSpec.describe "bundle install with gems on multiple sources" do end it "does not unlock the non-path gem after install" do - bundle :install + bundle! :install - bundle %(exec ruby -e 'puts "OK"') + bundle! %(exec ruby -e 'puts "OK"'), :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to include("OK") - expect(exitstatus).to eq(0) if exitstatus end end end diff --git a/spec/runtime/gem_tasks_spec.rb b/spec/runtime/gem_tasks_spec.rb index 884039e425..7bfd0e44a4 100644 --- a/spec/runtime/gem_tasks_spec.rb +++ b/spec/runtime/gem_tasks_spec.rb @@ -36,7 +36,9 @@ RSpec.describe "require 'bundler/gem_tasks'" do end it "adds 'pkg' to rake/clean's CLOBBER" do - require "bundler/gem_tasks" - expect(CLOBBER).to include("pkg") + with_gem_path_as(Spec::Path.base_system_gems.to_s) do + sys_exec! %('#{Gem.ruby}' -rrake -e 'load "Rakefile"; puts CLOBBER.inspect') + end + expect(last_command.stdout).to eq '["pkg"]' end end diff --git a/spec/runtime/require_spec.rb b/spec/runtime/require_spec.rb index 3eccd60fba..0484e38845 100644 --- a/spec/runtime/require_spec.rb +++ b/spec/runtime/require_spec.rb @@ -264,13 +264,13 @@ RSpec.describe "Bundler.require" do describe "using bundle exec" do it "requires the locked gems" do - bundle "exec ruby -e 'Bundler.require'" + bundle "exec ruby -e 'Bundler.require'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("two") - bundle "exec ruby -e 'Bundler.require(:bar)'" + bundle "exec ruby -e 'Bundler.require(:bar)'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("baz\nqux") - bundle "exec ruby -e 'Bundler.require(:default, :bar)'" + bundle "exec ruby -e 'Bundler.require(:default, :bar)'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(out).to eq("baz\nqux\ntwo") end end diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index e8aa973ba8..d758232723 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -763,7 +763,7 @@ end G ENV["GEM_HOME"] = "" - bundle %(exec ruby -e "require 'set'") + bundle %(exec ruby -e "require 'set'"), :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(err).to lack_errors end @@ -1078,7 +1078,7 @@ end gem "bundler", :path => "#{File.expand_path("..", lib)}" G - bundle %(exec ruby -e "require 'bundler'; Bundler.setup") + bundle %(exec ruby -e "require 'bundler'; Bundler.setup"), :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" } expect(err).to lack_errors end end @@ -1236,6 +1236,7 @@ end end let(:activation_warning_hack) { strip_whitespace(<<-RUBY) } + require #{spec_dir.join("support/hax").to_s.dump} require "rubygems" if Gem::Specification.instance_methods.map(&:to_sym).include?(:activate) @@ -1279,8 +1280,9 @@ end it "activates no gems with bundle exec" do install_gemfile! "" + # ensure we clean out the default gems, bceause bundler's allowed to be activated create_file("script.rb", code) - bundle! "exec ruby ./script.rb", :env => { :RUBYOPT => activation_warning_hack_rubyopt } + bundle! "exec ruby ./script.rb", :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -rbundler/setup" } expect(last_command.stdout).to eq("{}") end diff --git a/spec/runtime/with_clean_env_spec.rb b/spec/runtime/with_clean_env_spec.rb index b160e5b409..225e794eba 100644 --- a/spec/runtime/with_clean_env_spec.rb +++ b/spec/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 @@ -49,9 +57,10 @@ RSpec.describe "Bundler.with_env helpers" do it "removes variables that bundler added" do system_gems :bundler + system_gems :bundler, :path => :bundle_path # to ensure the bundler under test is the one activated... 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) + bundle! "exec '#{Gem.ruby}' -e #{code.dump}", :system_bundler => true expect(out).to eq original end end @@ -66,30 +75,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" 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 |