From be7b5929126cb3e696ef222339237faba9b8fe5a Mon Sep 17 00:00:00 2001 From: hsbt Date: Wed, 1 Nov 2017 23:29:38 +0000 Subject: Update bundled bundler to 1.16.0. * lib/bundler, spec/bundler: Merge bundler-1.16.0. * common.mk: rspec examples of bundler-1.16.0 needs require option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/bundler/runtime/executable_spec.rb | 54 +++++--- spec/bundler/runtime/gem_tasks_spec.rb | 1 - spec/bundler/runtime/inline_spec.rb | 20 +-- spec/bundler/runtime/load_spec.rb | 18 +-- spec/bundler/runtime/platform_spec.rb | 11 +- spec/bundler/runtime/require_spec.rb | 86 +++++++------ spec/bundler/runtime/setup_spec.rb | 193 +++++++++++++++++++++------- spec/bundler/runtime/with_clean_env_spec.rb | 37 ++++-- 8 files changed, 274 insertions(+), 146 deletions(-) (limited to 'spec/bundler/runtime') diff --git a/spec/bundler/runtime/executable_spec.rb b/spec/bundler/runtime/executable_spec.rb index ff27d0b415..388ee049d0 100644 --- a/spec/bundler/runtime/executable_spec.rb +++ b/spec/bundler/runtime/executable_spec.rb @@ -1,16 +1,15 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "Running bin/* commands" do before :each do - gemfile <<-G + install_gemfile! <<-G source "file://#{gem_repo1}" gem "rack" G end it "runs the bundled command when in the bundle" do - bundle "install --binstubs" + bundle! "binstubs rack" build_gem "rack", "2.0", :to_system => true do |s| s.executables = "rackup" @@ -21,7 +20,7 @@ RSpec.describe "Running bin/* commands" do end it "allows the location of the gem stubs to be specified" do - bundle "install --binstubs gbin" + bundle! "binstubs rack", :path => "gbin" expect(bundled_app("bin")).not_to exist expect(bundled_app("gbin/rackup")).to exist @@ -31,24 +30,24 @@ RSpec.describe "Running bin/* commands" do end it "allows absolute paths as a specification of where to install bin stubs" do - bundle "install --binstubs #{tmp}/bin" + bundle! "binstubs rack", :path => tmp("bin") gembin tmp("bin/rackup") expect(out).to eq("1.0.0") end it "uses the default ruby install name when shebang is not specified" do - bundle "install --binstubs" + bundle! "binstubs rack" expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env #{RbConfig::CONFIG["ruby_install_name"]}\n") end it "allows the name of the shebang executable to be specified" do - bundle "install --binstubs --shebang ruby-foo" + bundle! "binstubs rack", :shebang => "ruby-foo" expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env ruby-foo\n") end it "runs the bundled command when out of the bundle" do - bundle "install --binstubs" + bundle! "binstubs rack" build_gem "rack", "2.0", :to_system => true do |s| s.executables = "rackup" @@ -69,7 +68,7 @@ RSpec.describe "Running bin/* commands" do gem "rack", :path => "#{lib_path("rack")}" G - bundle "install --binstubs" + bundle! "binstubs rack" build_gem "rack", "2.0", :to_system => true do |s| s.executables = "rackup" @@ -79,7 +78,7 @@ RSpec.describe "Running bin/* commands" do expect(out).to eq("1.0") end - it "don't bundle da bundla" do + it "creates a bundle binstub" do build_gem "bundler", Bundler::VERSION, :to_system => true do |s| s.executables = "bundle" end @@ -89,35 +88,35 @@ RSpec.describe "Running bin/* commands" do gem "bundler" G - bundle "install --binstubs" + bundle! "binstubs bundler" - expect(bundled_app("bin/bundle")).not_to exist + expect(bundled_app("bin/bundle")).to exist end it "does not generate bin stubs if the option was not specified" do - bundle "install" + bundle! "install" expect(bundled_app("bin/rackup")).not_to exist end - it "allows you to stop installing binstubs" do - bundle "install --binstubs bin/" + it "allows you to stop installing binstubs", :bundler => "< 2" do + bundle! "install --binstubs bin/" bundled_app("bin/rackup").rmtree - bundle "install --binstubs \"\"" + bundle! "install --binstubs \"\"" expect(bundled_app("bin/rackup")).not_to exist - bundle "config bin" + bundle! "config bin" expect(out).to include("You have not configured a value for `bin`") end - it "remembers that the option was specified" do + it "remembers that the option was specified", :bundler => "< 2" do gemfile <<-G source "file://#{gem_repo1}" gem "activesupport" G - bundle "install --binstubs" + bundle! :install, forgotten_command_line_options([:binstubs, :bin] => "bin") gemfile <<-G source "file://#{gem_repo1}" @@ -130,13 +129,13 @@ RSpec.describe "Running bin/* commands" do expect(bundled_app("bin/rackup")).to exist end - it "rewrites bins on --binstubs (to maintain backwards compatibility)" do + it "rewrites bins on --binstubs (to maintain backwards compatibility)", :bundler => "< 2" do gemfile <<-G source "file://#{gem_repo1}" gem "rack" G - bundle "install --binstubs bin/" + bundle! :install, forgotten_command_line_options([:binstubs, :bin] => "bin") File.open(bundled_app("bin/rackup"), "wb") do |file| file.print "OMG" @@ -146,4 +145,17 @@ RSpec.describe "Running bin/* commands" do expect(bundled_app("bin/rackup").read).to_not eq("OMG") end + + it "rewrites bins on binstubs (to maintain backwards compatibility)" do + install_gemfile! <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + create_file("bin/rackup", "OMG") + + bundle! "binstubs rack" + + expect(bundled_app("bin/rackup").read).to_not eq("OMG") + end end diff --git a/spec/bundler/runtime/gem_tasks_spec.rb b/spec/bundler/runtime/gem_tasks_spec.rb index 7cb0f32c0c..500c3128fd 100644 --- a/spec/bundler/runtime/gem_tasks_spec.rb +++ b/spec/bundler/runtime/gem_tasks_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "require 'bundler/gem_tasks'" do before :each do diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index e816799d08..dcaba3ab9d 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "bundler/inline#gemfile" do def script(code, options = {}) @@ -53,8 +52,9 @@ RSpec.describe "bundler/inline#gemfile" do it "requires the gems" do script <<-RUBY gemfile do - path "#{lib_path}" - gem "two" + path "#{lib_path}" do + gem "two" + end end RUBY @@ -63,8 +63,9 @@ RSpec.describe "bundler/inline#gemfile" do script <<-RUBY gemfile do - path "#{lib_path}" - gem "eleven" + path "#{lib_path}" do + gem "eleven" + end end puts "success" @@ -133,8 +134,9 @@ RSpec.describe "bundler/inline#gemfile" do require 'bundler' options = { :ui => Bundler::UI::Shell.new } gemfile(false, options) do - path "#{lib_path}" - gem "two" + path "#{lib_path}" do + gem "two" + end end puts "OKAY" if options.key?(:ui) RUBY @@ -262,7 +264,7 @@ RSpec.describe "bundler/inline#gemfile" do puts RACK RUBY - expect(exitstatus).to eq(0) if exitstatus - expect(out).to eq "1.0.0" + expect(last_command).to be_success + expect(last_command.stdout).to eq "1.0.0" end end diff --git a/spec/bundler/runtime/load_spec.rb b/spec/bundler/runtime/load_spec.rb index d0e308ed3e..b74dbde3f6 100644 --- a/spec/bundler/runtime/load_spec.rb +++ b/spec/bundler/runtime/load_spec.rb @@ -1,14 +1,9 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "Bundler.load" do - before :each do - system_gems "rack-1.0.0" - end - describe "with a gemfile" do before(:each) do - gemfile <<-G + install_gemfile! <<-G source "file://#{gem_repo1}" gem "rack" G @@ -36,6 +31,7 @@ RSpec.describe "Bundler.load" do source "file://#{gem_repo1}" gem "rack" G + bundle! :install end it "provides a list of the env dependencies" do @@ -77,13 +73,13 @@ RSpec.describe "Bundler.load" do describe "when called twice" do it "doesn't try to load the runtime twice" do - system_gems "rack-1.0.0", "activesupport-2.3.5" - gemfile <<-G + install_gemfile! <<-G + source "file:#{gem_repo1}" gem "rack" gem "activesupport", :group => :test G - ruby <<-RUBY + ruby! <<-RUBY require "bundler" Bundler.setup :default Bundler.require :default @@ -101,8 +97,8 @@ RSpec.describe "Bundler.load" do describe "not hurting brittle rubygems" do it "does not inject #source into the generated YAML of the gem specs" do - system_gems "activerecord-2.3.2", "activesupport-2.3.2" - gemfile <<-G + install_gemfile! <<-G + source "file:#{gem_repo1}" gem "activerecord" G diff --git a/spec/bundler/runtime/platform_spec.rb b/spec/bundler/runtime/platform_spec.rb index 4df934e71f..f38f733845 100644 --- a/spec/bundler/runtime/platform_spec.rb +++ b/spec/bundler/runtime/platform_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "Bundler.setup with multi platform stuff" do it "raises a friendly error when gems are missing locally" do @@ -33,7 +32,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do expect(out).to eq("WIN") end - it "will resolve correctly on the current platform when the lockfile was targetted for a different one" do + it "will resolve correctly on the current platform when the lockfile was targeted for a different one" do lockfile <<-G GEM remote: file:#{gem_repo1}/ @@ -49,10 +48,8 @@ RSpec.describe "Bundler.setup with multi platform stuff" do nokogiri G - system_gems "nokogiri-1.4.2" - simulate_platform "x86-darwin-10" - gemfile <<-G + install_gemfile! <<-G source "file://#{gem_repo1}" gem "nokogiri" G @@ -78,9 +75,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do simulate_platform "x86-darwin-100" - system_gems "nokogiri-1.4.2", "platform_specific-1.0-x86-darwin-100" - - gemfile <<-G + install_gemfile! <<-G source "file://#{gem_repo1}" gem "nokogiri" gem "platform_specific" diff --git a/spec/bundler/runtime/require_spec.rb b/spec/bundler/runtime/require_spec.rb index b68313726b..3eccd60fba 100644 --- a/spec/bundler/runtime/require_spec.rb +++ b/spec/bundler/runtime/require_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "Bundler.require" do before :each do @@ -47,19 +46,20 @@ RSpec.describe "Bundler.require" do end gemfile <<-G - path "#{lib_path}" - gem "one", :group => :bar, :require => %w[baz qux] - gem "two" - gem "three", :group => :not - gem "four", :require => false - gem "five" - gem "six", :group => "string" - gem "seven", :group => :not - gem "eight", :require => true, :group => :require_true - env "BUNDLER_TEST" => "nine" do - gem "nine", :require => true + path "#{lib_path}" do + gem "one", :group => :bar, :require => %w[baz qux] + gem "two" + gem "three", :group => :not + gem "four", :require => false + gem "five" + gem "six", :group => "string" + gem "seven", :group => :not + gem "eight", :require => true, :group => :require_true + env "BUNDLER_TEST" => "nine" do + gem "nine", :require => true + end + gem "ten", :install_if => lambda { ENV["BUNDLER_TEST"] == "ten" } end - gem "ten", :install_if => lambda { ENV["BUNDLER_TEST"] == "ten" } G end @@ -86,7 +86,7 @@ RSpec.describe "Bundler.require" do # required in resolver order instead of gemfile order run("Bundler.require(:not)") - expect(out.split("\n").sort).to eq(%w(seven three)) + expect(out.split("\n").sort).to eq(%w[seven three]) # test require: true run "Bundler.require(:require_true)" @@ -112,8 +112,9 @@ RSpec.describe "Bundler.require" do it "raises an exception if a require is specified but the file does not exist" do gemfile <<-G - path "#{lib_path}" - gem "two", :require => 'fail' + path "#{lib_path}" do + gem "two", :require => 'fail' + end G load_error_run <<-R, "fail" @@ -129,8 +130,9 @@ RSpec.describe "Bundler.require" do end gemfile <<-G - path "#{lib_path}" - gem "faulty" + path "#{lib_path}" do + gem "faulty" + end G run "Bundler.require" @@ -144,8 +146,9 @@ RSpec.describe "Bundler.require" do end gemfile <<-G - path "#{lib_path}" - gem "loadfuuu" + path "#{lib_path}" do + gem "loadfuuu" + end G cmd = <<-RUBY @@ -170,8 +173,9 @@ RSpec.describe "Bundler.require" do it "requires gem names that are namespaced" do gemfile <<-G - path '#{lib_path}' - gem 'jquery-rails' + path '#{lib_path}' do + gem 'jquery-rails' + end G run "Bundler.require" @@ -183,8 +187,9 @@ RSpec.describe "Bundler.require" do s.write "lib/brcrypt.rb", "BCrypt = '1.0.0'" end gemfile <<-G - path "#{lib_path}" - gem "bcrypt-ruby" + path "#{lib_path}" do + gem "bcrypt-ruby" + end G cmd = <<-RUBY @@ -198,8 +203,9 @@ RSpec.describe "Bundler.require" do it "does not mangle explicitly given requires" do gemfile <<-G - path "#{lib_path}" - gem 'jquery-rails', :require => 'jquery-rails' + path "#{lib_path}" do + gem 'jquery-rails', :require => 'jquery-rails' + end G load_error_run <<-R, "jquery-rails" @@ -214,8 +220,9 @@ RSpec.describe "Bundler.require" do end gemfile <<-G - path "#{lib_path}" - gem "load-fuuu" + path "#{lib_path}" do + gem "load-fuuu" + end G cmd = <<-RUBY @@ -237,8 +244,9 @@ RSpec.describe "Bundler.require" do lib_path("load-fuuu-1.0.0/lib/load-fuuu.rb").rmtree gemfile <<-G - path "#{lib_path}" - gem "load-fuuu" + path "#{lib_path}" do + gem "load-fuuu" + end G cmd = <<-RUBY @@ -294,9 +302,10 @@ RSpec.describe "Bundler.require" do it "works when the gems are in the Gemfile in the correct order" do gemfile <<-G - path "#{lib_path}" - gem "two" - gem "one" + path "#{lib_path}" do + gem "two" + gem "one" + end G run "Bundler.require" @@ -305,7 +314,7 @@ RSpec.describe "Bundler.require" do describe "a gem with different requires for different envs" do before(:each) do - build_gem "multi_gem", :to_system => true do |s| + build_gem "multi_gem", :to_bundle => true do |s| s.write "lib/one.rb", "puts 'ONE'" s.write "lib/two.rb", "puts 'TWO'" end @@ -334,9 +343,10 @@ RSpec.describe "Bundler.require" do it "fails when the gems are in the Gemfile in the wrong order" do gemfile <<-G - path "#{lib_path}" - gem "one" - gem "two" + path "#{lib_path}" do + gem "one" + gem "two" + end G run "Bundler.require" @@ -345,7 +355,7 @@ RSpec.describe "Bundler.require" do describe "with busted gems" do it "should be busted" do - build_gem "busted_require", :to_system => true do |s| + build_gem "busted_require", :to_bundle => true do |s| s.write "lib/busted_require.rb", "require 'no_such_file_omg'" end diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index dc7af07188..8f6f656359 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require "spec_helper" RSpec.describe "Bundler.setup" do describe "with no arguments" do @@ -117,7 +116,7 @@ RSpec.describe "Bundler.setup" do tmp("rubygems/lib").to_s, root.join("../lib").expand_path.to_s, ] - without_bundler_load_path - lp.map! {|p| p.sub(/^#{system_gem_path}/, "") } + lp.map! {|p| p.sub(/^#{Regexp.union system_gem_path.to_s, default_bundle_path.to_s}/i, "") } end it "puts loaded gems after -I and RUBYLIB", :ruby_repo do @@ -270,21 +269,51 @@ RSpec.describe "Bundler.setup" do expect(bundled_app("Gemfile.lock")).to exist end - it "uses BUNDLE_GEMFILE to locate the gemfile if present" do - gemfile <<-G - source "file://#{gem_repo1}" - gem "rack" - G + describe "$BUNDLE_GEMFILE" do + context "user provides an absolute path" do + it "uses BUNDLE_GEMFILE to locate the gemfile if present" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G - gemfile bundled_app("4realz"), <<-G - source "file://#{gem_repo1}" - gem "activesupport", "2.3.5" - G + gemfile bundled_app("4realz"), <<-G + source "file://#{gem_repo1}" + gem "activesupport", "2.3.5" + G + + ENV["BUNDLE_GEMFILE"] = bundled_app("4realz").to_s + bundle :install + + expect(the_bundle).to include_gems "activesupport 2.3.5" + end + end + + context "an absolute path is not provided" do + it "uses BUNDLE_GEMFILE to locate the gemfile if present" do + gemfile <<-G + source "file://#{gem_repo1}" + G + + bundle "install" + bundle "install --deployment" + + ENV["BUNDLE_GEMFILE"] = "Gemfile" + ruby <<-R + require 'rubygems' + require 'bundler' - ENV["BUNDLE_GEMFILE"] = bundled_app("4realz").to_s - bundle :install + begin + Bundler.setup + puts "WIN" + rescue ArgumentError => e + puts "FAIL" + end + R - expect(the_bundle).to include_gems "activesupport 2.3.5" + expect(out).to eq("WIN") + end + end end it "prioritizes gems in BUNDLE_PATH over gems in GEM_HOME" do @@ -396,9 +425,10 @@ RSpec.describe "Bundler.setup" do end gemfile <<-G - path "#{lib_path("rack-1.0.0")}" source "file://#{gem_repo1}" - gem "rack" + path "#{lib_path("rack-1.0.0")}" do + gem "rack" + end G run "require 'rack'" @@ -465,13 +495,13 @@ RSpec.describe "Bundler.setup" do end it "works even when the cache directory has been deleted" do - bundle "install --path vendor/bundle" + bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") FileUtils.rm_rf vendored_gems("cache") expect(the_bundle).to include_gems "rack 1.0.0" end it "does not randomly change the path when specifying --path and the bundle directory becomes read only" do - bundle "install --path vendor/bundle" + bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") with_read_only("**/*") do expect(the_bundle).to include_gems "rack 1.0.0" @@ -499,8 +529,7 @@ RSpec.describe "Bundler.setup" do G bundle %(config local.rack #{lib_path("local-rack")}) - bundle :install - expect(out).to match(/at #{lib_path('local-rack')}/) + bundle! :install FileUtils.rm_rf(lib_path("local-rack")) run "require 'rack'" @@ -518,8 +547,7 @@ RSpec.describe "Bundler.setup" do G bundle %(config local.rack #{lib_path("local-rack")}) - bundle :install - expect(out).to match(/at #{lib_path('local-rack')}/) + bundle! :install gemfile <<-G source "file://#{gem_repo1}" @@ -541,8 +569,7 @@ RSpec.describe "Bundler.setup" do G bundle %(config local.rack #{lib_path("local-rack")}) - bundle :install - expect(out).to match(/at #{lib_path('local-rack')}/) + bundle! :install gemfile <<-G source "file://#{gem_repo1}" @@ -576,7 +603,7 @@ RSpec.describe "Bundler.setup" do describe "when excluding groups" do it "doesn't change the resolve if --without is used" do - install_gemfile <<-G, :without => :rails + install_gemfile <<-G, forgotten_command_line_options(:without => :rails) source "file://#{gem_repo1}" gem "activesupport" @@ -591,7 +618,7 @@ RSpec.describe "Bundler.setup" do end it "remembers --without and does not bail on bare Bundler.setup" do - install_gemfile <<-G, :without => :rails + install_gemfile <<-G, forgotten_command_line_options(:without => :rails) source "file://#{gem_repo1}" gem "activesupport" @@ -606,7 +633,7 @@ RSpec.describe "Bundler.setup" do end it "remembers --without and does not include groups passed to Bundler.setup" do - install_gemfile <<-G, :without => :rails + install_gemfile <<-G, forgotten_command_line_options(:without => :rails) source "file://#{gem_repo1}" gem "activesupport" @@ -680,7 +707,7 @@ RSpec.describe "Bundler.setup" do end end - # Rubygems returns loaded_from as a string + # RubyGems returns loaded_from as a string it "has loaded_from as a string on all specs" do build_git "foo" build_git "no-gemspec", :gemspec => false @@ -741,12 +768,50 @@ end expect(err).to lack_errors end + describe "$MANPATH" do + before do + build_repo4 do + build_gem "with_man" do |s| + s.write("man/man1/page.1", "MANPAGE") + end + end + end + + context "when the user has one set" do + before { ENV["MANPATH"] = "/foo:" } + + it "adds the gem's man dir to the MANPATH" do + install_gemfile! <<-G + source "file:#{gem_repo4}" + gem "with_man" + G + + run! "puts ENV['MANPATH']" + expect(out).to eq("#{default_bundle_path("gems/with_man-1.0/man")}:/foo") + end + end + + context "when the user does not have one set" do + before { ENV.delete("MANPATH") } + + it "adds the gem's man dir to the MANPATH" do + install_gemfile! <<-G + source "file:#{gem_repo4}" + gem "with_man" + G + + run! "puts ENV['MANPATH']" + expect(out).to eq(default_bundle_path("gems/with_man-1.0/man").to_s) + end + end + end + it "should prepend gemspec require paths to $LOAD_PATH in order" do update_repo2 do build_gem("requirepaths") do |s| s.write("lib/rq.rb", "puts 'yay'") s.write("src/rq.rb", "puts 'nooo'") - s.require_paths = %w(lib src) + s.require_paths = %w[lib src] end end @@ -930,6 +995,7 @@ end describe "with system gems in the bundle" do before :each do + bundle! "config path.system true" system_gems "rack-1.0.0" install_gemfile <<-G @@ -943,7 +1009,6 @@ end run "puts Gem.path" paths = out.split("\n") expect(paths).to include(system_gem_path.to_s) - expect(paths).to include(default_bundle_path.to_s) end end @@ -1027,7 +1092,7 @@ end rack (1.0.0) PLATFORMS - #{generic_local_platform} + #{lockfile_platforms} DEPENDENCIES rack @@ -1085,7 +1150,7 @@ end rack (1.0.0) PLATFORMS - #{generic_local_platform} + #{lockfile_platforms} DEPENDENCIES rack @@ -1166,11 +1231,11 @@ end if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") || ENV["RGV"] == "master" [] else - %w(io-console openssl) + %w[io-console openssl] end << "bundler" end - let(:code) { strip_whitespace(<<-RUBY) } + let(:activation_warning_hack) { strip_whitespace(<<-RUBY) } require "rubygems" if Gem::Specification.instance_methods.map(&:to_sym).include?(:activate) @@ -1185,7 +1250,14 @@ end bundler_spec_activate end end + RUBY + + let(:activation_warning_hack_rubyopt) do + create_file("activation_warning_hack.rb", activation_warning_hack) + "-r#{bundled_app("activation_warning_hack.rb")} #{ENV["RUBYOPT"]}" + end + let(:code) { strip_whitespace(<<-RUBY) } require "bundler/setup" require "pp" loaded_specs = Gem.loaded_specs.dup @@ -1201,17 +1273,15 @@ end it "activates no gems with -rbundler/setup" do install_gemfile! "" - ruby!(code) - expect(err).to eq("") - expect(out).to eq("{}") + ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt } + expect(last_command.stdout).to eq("{}") end it "activates no gems with bundle exec" do install_gemfile! "" create_file("script.rb", code) - bundle! "exec ruby ./script.rb" - expect(err).to eq("") - expect(out).to eq("{}") + bundle! "exec ruby ./script.rb", :env => { :RUBYOPT => activation_warning_hack_rubyopt } + expect(last_command.stdout).to eq("{}") end it "activates no gems with bundle exec that is loaded" do @@ -1221,9 +1291,8 @@ end install_gemfile! "" create_file("script.rb", "#!/usr/bin/env ruby\n\n#{code}") FileUtils.chmod(0o777, bundled_app("script.rb")) - bundle! "exec ./script.rb", :artifice => nil - expect(err).to eq("") - expect(out).to eq("{}") + bundle! "exec ./script.rb", :artifice => nil, :env => { :RUBYOPT => activation_warning_hack_rubyopt } + expect(last_command.stdout).to eq("{}") end let(:default_gems) do @@ -1241,6 +1310,8 @@ end end end + default_gems.reject! {|g| exemptions.include?(g) } + install_gemfile! <<-G source "file:#{gem_repo4}" #{default_gems}.each do |g| @@ -1273,17 +1344,51 @@ end end describe "after setup" do - it "allows calling #gem on random objects" do + it "allows calling #gem on random objects", :bundler => "< 2" do install_gemfile <<-G source "file:#{gem_repo1}" gem "rack" G + ruby! <<-RUBY require "bundler/setup" Object.new.gem "rack" puts Gem.loaded_specs["rack"].full_name RUBY + expect(out).to eq("rack-1.0.0") end + + it "keeps Kernel#gem private", :bundler => "2" do + install_gemfile! <<-G + source "file:#{gem_repo1}" + gem "rack" + G + + ruby <<-RUBY + require "bundler/setup" + Object.new.gem "rack" + puts "FAIL" + RUBY + + expect(last_command.stdboth).not_to include "FAIL" + expect(last_command.stderr).to include "private method `gem'" + end + + it "keeps Kernel#require private" do + install_gemfile! <<-G + source "file:#{gem_repo1}" + gem "rack" + G + + ruby <<-RUBY + require "bundler/setup" + Object.new.require "rack" + puts "FAIL" + RUBY + + expect(last_command.stdboth).not_to include "FAIL" + expect(last_command.stderr).to include "private method `require'" + end end end 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)) -- cgit v1.2.3