summaryrefslogtreecommitdiff
path: root/spec/bundler/runtime
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-14 06:01:35 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-14 06:01:35 +0000
commit68ddd4d300e9a88737c4f37af74e1a0312949b2f (patch)
tree787e1e83d76934ce039eb336995a8d5bb53a89e6 /spec/bundler/runtime
parentd636809c057432e8d42abe30c6c6785eb0721d77 (diff)
Merge Bundler 2.1.0.pre.1 as developed version from upstream.
https://github.com/bundler/bundler/commit/a53709556b95a914e874b22ed2116a46b0528852 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/bundler/runtime')
-rw-r--r--spec/bundler/runtime/executable_spec.rb17
-rw-r--r--spec/bundler/runtime/gem_tasks_spec.rb2
-rw-r--r--spec/bundler/runtime/inline_spec.rb29
-rw-r--r--spec/bundler/runtime/platform_spec.rb4
-rw-r--r--spec/bundler/runtime/require_spec.rb32
-rw-r--r--spec/bundler/runtime/setup_spec.rb178
-rw-r--r--spec/bundler/runtime/with_clean_env_spec.rb151
-rw-r--r--spec/bundler/runtime/with_unbundled_env_spec.rb241
8 files changed, 335 insertions, 319 deletions
diff --git a/spec/bundler/runtime/executable_spec.rb b/spec/bundler/runtime/executable_spec.rb
index 7ba510a509..b2d5b6c03f 100644
--- a/spec/bundler/runtime/executable_spec.rb
+++ b/spec/bundler/runtime/executable_spec.rb
@@ -129,23 +129,6 @@ RSpec.describe "Running bin/* commands" do
expect(bundled_app("bin/rackup")).to exist
end
- it "rewrites bins on --binstubs (to maintain backwards compatibility)", :bundler => "< 2" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- gem "rack"
- G
-
- bundle! :install, forgotten_command_line_options([:binstubs, :bin] => "bin")
-
- File.open(bundled_app("bin/rackup"), "wb") do |file|
- file.print "OMG"
- end
-
- bundle "install"
-
- 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}"
diff --git a/spec/bundler/runtime/gem_tasks_spec.rb b/spec/bundler/runtime/gem_tasks_spec.rb
index de72869dc3..3c69f8a800 100644
--- a/spec/bundler/runtime/gem_tasks_spec.rb
+++ b/spec/bundler/runtime/gem_tasks_spec.rb
@@ -22,7 +22,7 @@ RSpec.describe "require 'bundler/gem_tasks'", :ruby_repo do
sys_exec "#{rake} -T"
end
- expect(err).to eq("")
+ expect(last_command.stderr).to eq("")
expected_tasks = [
"rake build",
"rake clean",
diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb
index 18ca246199..96a3fa09ae 100644
--- a/spec/bundler/runtime/inline_spec.rb
+++ b/spec/bundler/runtime/inline_spec.rb
@@ -67,7 +67,7 @@ RSpec.describe "bundler/inline#gemfile" do
puts "success"
RUBY
- expect(err).to include "Could not find gem 'eleven'"
+ expect(last_command.stderr).to include "Could not find gem 'eleven'"
expect(out).not_to include "success"
script <<-RUBY
@@ -90,7 +90,7 @@ RSpec.describe "bundler/inline#gemfile" do
expect(out).to include("Installing activesupport")
err.gsub! %r{.*lib/sinatra/base\.rb:\d+: warning: constant ::Fixnum is deprecated$}, ""
err.strip!
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
expect(exitstatus).to be_zero if exitstatus
end
@@ -112,6 +112,19 @@ RSpec.describe "bundler/inline#gemfile" do
expect(exitstatus).to be_zero if exitstatus
end
+ it "has an option for quiet installation" do
+ script <<-RUBY, :artifice => "endpoint"
+ require 'bundler'
+
+ gemfile(true, :quiet => true) do
+ source "https://notaserver.com"
+ gem "activesupport", :require => true
+ end
+ RUBY
+
+ expect(out).to be_empty
+ end
+
it "raises an exception if passed unknown arguments" do
script <<-RUBY
gemfile(true, :arglebargle => true) do
@@ -121,7 +134,7 @@ RSpec.describe "bundler/inline#gemfile" do
puts "success"
RUBY
- expect(err).to include "Unknown options: arglebargle"
+ expect(last_command.stderr).to include "Unknown options: arglebargle"
expect(out).not_to include "success"
end
@@ -152,7 +165,7 @@ RSpec.describe "bundler/inline#gemfile" do
RUBY
expect(out).to eq("1.0.0")
- expect(err).to be_empty
+ expect(last_command.stderr).to be_empty
expect(exitstatus).to be_zero if exitstatus
end
@@ -170,7 +183,7 @@ RSpec.describe "bundler/inline#gemfile" do
RUBY
expect(out).to eq("1.0.0\n2.0.0")
- expect(err).to be_empty
+ expect(last_command.stderr).to be_empty
expect(exitstatus).to be_zero if exitstatus
end
@@ -190,7 +203,7 @@ RSpec.describe "bundler/inline#gemfile" do
RUBY
expect(out).to eq("two\nfour")
- expect(err).to be_empty
+ expect(last_command.stderr).to be_empty
expect(exitstatus).to be_zero if exitstatus
end
@@ -227,7 +240,7 @@ RSpec.describe "bundler/inline#gemfile" do
RUBY
end
- expect(err).to be_empty
+ expect(last_command.stderr).to be_empty
expect(exitstatus).to be_zero if exitstatus
end
@@ -245,7 +258,7 @@ RSpec.describe "bundler/inline#gemfile" do
RUBY
end
- expect(err).to be_empty
+ expect(last_command.stderr).to be_empty
expect(exitstatus).to be_zero if exitstatus
end
diff --git a/spec/bundler/runtime/platform_spec.rb b/spec/bundler/runtime/platform_spec.rb
index eecf162427..11fe16f499 100644
--- a/spec/bundler/runtime/platform_spec.rb
+++ b/spec/bundler/runtime/platform_spec.rb
@@ -93,7 +93,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do
gem "platform_specific"
G
- bundle! "config force_ruby_platform true"
+ bundle! "config set force_ruby_platform true"
bundle! "install"
@@ -108,7 +108,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do
gem "platform_specific"
G
- bundle! "config force_ruby_platform true"
+ bundle! "config set force_ruby_platform true"
bundle! "install"
diff --git a/spec/bundler/runtime/require_spec.rb b/spec/bundler/runtime/require_spec.rb
index 0484e38845..c9cfa199d3 100644
--- a/spec/bundler/runtime/require_spec.rb
+++ b/spec/bundler/runtime/require_spec.rb
@@ -121,7 +121,7 @@ RSpec.describe "Bundler.require" do
Bundler.require
R
- expect(err).to eq_err("ZOMG LOAD ERROR")
+ expect(err_without_deprecations).to eq("ZOMG LOAD ERROR")
end
it "displays a helpful message if the required gem throws an error" do
@@ -136,8 +136,8 @@ RSpec.describe "Bundler.require" do
G
run "Bundler.require"
- expect(err).to match("error while trying to load the gem 'faulty'")
- expect(err).to match("Gem Internal Error Message")
+ expect(last_command.stderr).to match("error while trying to load the gem 'faulty'")
+ expect(last_command.stderr).to match("Gem Internal Error Message")
end
it "doesn't swallow the error when the library has an unrelated error" do
@@ -160,7 +160,7 @@ RSpec.describe "Bundler.require" do
RUBY
run(cmd)
- expect(err).to eq_err("ZOMG LOAD ERROR: cannot load such file -- load-bar")
+ expect(err_without_deprecations).to eq("ZOMG LOAD ERROR: cannot load such file -- load-bar")
end
describe "with namespaced gems" do
@@ -198,7 +198,7 @@ RSpec.describe "Bundler.require" do
RUBY
ruby(cmd)
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
end
it "does not mangle explicitly given requires" do
@@ -211,7 +211,7 @@ RSpec.describe "Bundler.require" do
load_error_run <<-R, "jquery-rails"
Bundler.require
R
- expect(err).to eq_err("ZOMG LOAD ERROR")
+ expect(err_without_deprecations).to eq("ZOMG LOAD ERROR")
end
it "handles the case where regex fails" do
@@ -234,7 +234,7 @@ RSpec.describe "Bundler.require" do
RUBY
run(cmd)
- expect(err).to eq_err("ZOMG LOAD ERROR")
+ expect(err_without_deprecations).to eq("ZOMG LOAD ERROR")
end
it "doesn't swallow the error when the library has an unrelated error" do
@@ -258,19 +258,19 @@ RSpec.describe "Bundler.require" do
RUBY
run(cmd)
- expect(err).to eq_err("ZOMG LOAD ERROR: cannot load such file -- load-bar")
+ expect(err_without_deprecations).to eq("ZOMG LOAD ERROR: cannot load such file -- load-bar")
end
end
describe "using bundle exec" do
it "requires the locked gems" do
- bundle "exec ruby -e 'Bundler.require'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" }
+ bundle "exec ruby -e 'Bundler.require'"
expect(out).to eq("two")
- bundle "exec ruby -e 'Bundler.require(:bar)'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" }
+ bundle "exec ruby -e 'Bundler.require(:bar)'"
expect(out).to eq("baz\nqux")
- bundle "exec ruby -e 'Bundler.require(:default, :bar)'", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" }
+ bundle "exec ruby -e 'Bundler.require(:default, :bar)'"
expect(out).to eq("baz\nqux\ntwo")
end
end
@@ -366,12 +366,12 @@ RSpec.describe "Bundler.require" do
load_error_run <<-R, "no_such_file_omg"
Bundler.require
R
- expect(err).to eq_err("ZOMG LOAD ERROR")
+ expect(err_without_deprecations).to eq("ZOMG LOAD ERROR")
end
end
end
- it "does not load rubygems gemspecs that are used", :rubygems => ">= 2.5.2" do
+ it "does not load rubygems gemspecs that are used" do
install_gemfile! <<-G
source "file://#{gem_repo1}"
gem "rack"
@@ -394,7 +394,7 @@ RSpec.describe "Bundler.require" do
expect(out).to eq("WIN")
end
- it "does not load git gemspecs that are used", :rubygems => ">= 2.5.2" do
+ it "does not load git gemspecs that are used" do
build_git "foo"
install_gemfile! <<-G
@@ -432,7 +432,7 @@ RSpec.describe "Bundler.require with platform specific dependencies" do
G
run "Bundler.require"
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
end
it "requires gems pinned to multiple platforms, including the current one" do
@@ -447,6 +447,6 @@ RSpec.describe "Bundler.require with platform specific dependencies" do
run "Bundler.require; puts RACK"
expect(out).to eq("1.0.0")
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
end
end
diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb
index f2f750a9ca..c81baa34ea 100644
--- a/spec/bundler/runtime/setup_spec.rb
+++ b/spec/bundler/runtime/setup_spec.rb
@@ -1,5 +1,8 @@
# frozen_string_literal: true
+require "tmpdir"
+require "tempfile"
+
RSpec.describe "Bundler.setup" do
describe "with no arguments" do
it "makes all groups available" do
@@ -16,7 +19,7 @@ RSpec.describe "Bundler.setup" do
require 'rack'
puts RACK
RUBY
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
expect(out).to eq("1.0.0")
end
end
@@ -42,7 +45,7 @@ RSpec.describe "Bundler.setup" do
puts "WIN"
end
RUBY
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
expect(out).to eq("WIN")
end
@@ -55,7 +58,7 @@ RSpec.describe "Bundler.setup" do
require 'rack'
puts RACK
RUBY
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
expect(out).to eq("1.0.0")
end
@@ -69,7 +72,7 @@ RSpec.describe "Bundler.setup" do
require 'rack'
puts RACK
RUBY
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
expect(out).to eq("1.0.0")
end
@@ -87,7 +90,7 @@ RSpec.describe "Bundler.setup" do
puts "FAIL"
end
RUBY
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
expect(out).to match("WIN")
end
@@ -101,8 +104,8 @@ RSpec.describe "Bundler.setup" do
puts "FAIL"
RUBY
- expect(err).to match("rack")
- expect(err).to match("LoadError")
+ expect(last_command.stderr).to match("rack")
+ expect(last_command.stderr).to match("LoadError")
expect(out).not_to match("FAIL")
end
end
@@ -125,7 +128,7 @@ RSpec.describe "Bundler.setup" do
gem "rack"
G
- ENV["RUBYOPT"] = "-Idash_i_dir"
+ ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -Idash_i_dir"
ENV["RUBYLIB"] = "rubylib_dir"
ruby <<-RUBY
@@ -138,9 +141,8 @@ RSpec.describe "Bundler.setup" do
load_path = out.split("\n")
rack_load_order = load_path.index {|path| path.include?("rack") }
- expect(err).to eq("")
- expect(load_path[1]).to include "dash_i_dir"
- expect(load_path[2]).to include "rubylib_dir"
+ expect(last_command.stderr).to eq("")
+ expect(load_path).to include(a_string_ending_with("dash_i_dir"), "rubylib_dir")
expect(rack_load_order).to be > 0
end
@@ -159,10 +161,6 @@ RSpec.describe "Bundler.setup" do
load_path = clean_load_path(out.split("\n"))
- unless Bundler.load.specs["bundler"].empty?
- load_path.delete_if {|path| path =~ /bundler/ }
- end
-
expect(load_path).to start_with(
"/gems/rails-2.3.2/lib",
"/gems/activeresource-2.3.2/lib",
@@ -170,7 +168,7 @@ RSpec.describe "Bundler.setup" do
"/gems/actionpack-2.3.2/lib",
"/gems/actionmailer-2.3.2/lib",
"/gems/activesupport-2.3.2/lib",
- "/gems/rake-10.0.2/lib"
+ "/gems/rake-12.3.2/lib"
)
end
@@ -366,7 +364,7 @@ RSpec.describe "Bundler.setup" do
end
R
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
end
it "replaces #gem but raises when the version is wrong" do
@@ -392,7 +390,7 @@ RSpec.describe "Bundler.setup" do
end
R
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
end
end
@@ -451,7 +449,7 @@ RSpec.describe "Bundler.setup" do
it "provides a useful exception when the git repo is not checked out yet" do
run "1"
- expect(err).to match(/the git source #{lib_path('rack-1.0.0')} is not yet checked out. Please run `bundle install`/i)
+ expect(last_command.stderr).to match(/the git source #{lib_path('rack-1.0.0')} is not yet checked out. Please run `bundle install`/i)
end
it "does not hit the git binary if the lockfile is available and up to date" do
@@ -532,12 +530,12 @@ RSpec.describe "Bundler.setup" do
gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master"
G
- bundle %(config local.rack #{lib_path("local-rack")})
+ bundle %(config set local.rack #{lib_path("local-rack")})
bundle! :install
FileUtils.rm_rf(lib_path("local-rack"))
run "require 'rack'"
- expect(err).to match(/Cannot use local override for rack-0.8 because #{Regexp.escape(lib_path('local-rack').to_s)} does not exist/)
+ expect(last_command.stderr).to match(/Cannot use local override for rack-0.8 because #{Regexp.escape(lib_path('local-rack').to_s)} does not exist/)
end
it "explodes if branch is not given on runtime" do
@@ -550,7 +548,7 @@ RSpec.describe "Bundler.setup" do
gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master"
G
- bundle %(config local.rack #{lib_path("local-rack")})
+ bundle %(config set local.rack #{lib_path("local-rack")})
bundle! :install
gemfile <<-G
@@ -559,7 +557,7 @@ RSpec.describe "Bundler.setup" do
G
run "require 'rack'"
- expect(err).to match(/because :branch is not specified in Gemfile/)
+ expect(last_command.stderr).to match(/because :branch is not specified in Gemfile/)
end
it "explodes on different branches on runtime" do
@@ -572,7 +570,7 @@ RSpec.describe "Bundler.setup" do
gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master"
G
- bundle %(config local.rack #{lib_path("local-rack")})
+ bundle %(config set local.rack #{lib_path("local-rack")})
bundle! :install
gemfile <<-G
@@ -581,7 +579,7 @@ RSpec.describe "Bundler.setup" do
G
run "require 'rack'"
- expect(err).to match(/is using branch master but Gemfile specifies changed/)
+ expect(last_command.stderr).to match(/is using branch master but Gemfile specifies changed/)
end
it "explodes on refs with different branches on runtime" do
@@ -599,9 +597,9 @@ RSpec.describe "Bundler.setup" do
gem "rack", :git => "#{lib_path("rack-0.8")}", :ref => "master", :branch => "nonexistant"
G
- bundle %(config local.rack #{lib_path("local-rack")})
+ bundle %(config set local.rack #{lib_path("local-rack")})
run "require 'rack'"
- expect(err).to match(/is using branch master but Gemfile specifies nonexistant/)
+ expect(last_command.stderr).to match(/is using branch master but Gemfile specifies nonexistant/)
end
end
@@ -655,62 +653,6 @@ RSpec.describe "Bundler.setup" do
end
end
- # Unfortunately, gem_prelude does not record the information about
- # activated gems, so this test cannot work on 1.9 :(
- if RUBY_VERSION < "1.9"
- describe "preactivated gems" do
- it "raises an exception if a pre activated gem conflicts with the bundle" do
- system_gems "thin-1.0", "rack-1.0.0"
- build_gem "thin", "1.1", :to_system => true do |s|
- s.add_dependency "rack"
- end
-
- gemfile <<-G
- gem "thin", "1.0"
- G
-
- ruby <<-R
- require 'rubygems'
- gem "thin"
- require 'bundler'
- begin
- Bundler.setup
- puts "FAIL"
- rescue Gem::LoadError => e
- puts e.message
- end
- R
-
- expect(out).to eq("You have already activated thin 1.1, but your Gemfile requires thin 1.0. Prepending `bundle exec` to your command may solve this.")
- end
-
- it "version_requirement is now deprecated in rubygems 1.4.0+" do
- system_gems "thin-1.0", "rack-1.0.0"
- build_gem "thin", "1.1", :to_system => true do |s|
- s.add_dependency "rack"
- end
-
- gemfile <<-G
- gem "thin", "1.0"
- G
-
- ruby <<-R
- require 'rubygems'
- gem "thin"
- require 'bundler'
- begin
- Bundler.setup
- puts "FAIL"
- rescue Gem::LoadError => e
- puts e.message
- end
- R
-
- expect(err).to lack_errors
- end
- end
- end
-
# RubyGems returns loaded_from as a string
it "has loaded_from as a string on all specs" do
build_git "foo"
@@ -732,7 +674,7 @@ RSpec.describe "Bundler.setup" do
expect(out).to be_empty
end
- it "does not load all gemspecs", :rubygems => ">= 2.3" do
+ it "does not load all gemspecs" do
install_gemfile! <<-G
source "file://#{gem_repo1}"
gem "rack"
@@ -767,9 +709,9 @@ end
G
ENV["GEM_HOME"] = ""
- bundle %(exec ruby -e "require 'set'"), :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" }
+ bundle %(exec ruby -e "require 'set'")
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
end
describe "$MANPATH" do
@@ -831,7 +773,7 @@ end
it "should clean $LOAD_PATH properly", :ruby_repo do
gem_name = "very_simple_binary"
full_gem_name = gem_name + "-1.0"
- ext_dir = File.join(tmp "extenstions", full_gem_name)
+ ext_dir = File.join(tmp("extensions", full_gem_name))
install_gem full_gem_name
@@ -863,48 +805,41 @@ end
context "with bundler is located in symlinked GEM_HOME" do
let(:gem_home) { Dir.mktmpdir }
- let(:symlinked_gem_home) { Tempfile.new("gem_home") }
+ let(:symlinked_gem_home) { Tempfile.new("gem_home").path }
let(:bundler_dir) { ruby_core? ? File.expand_path("../../../..", __FILE__) : File.expand_path("../../..", __FILE__) }
- let(:bundler_lib) { File.join(bundler_dir, "lib") }
+ let(:full_name) { "bundler-#{Bundler::VERSION}" }
before do
- FileUtils.ln_sf(gem_home, symlinked_gem_home.path)
+ FileUtils.ln_sf(gem_home, symlinked_gem_home)
gems_dir = File.join(gem_home, "gems")
specifications_dir = File.join(gem_home, "specifications")
Dir.mkdir(gems_dir)
Dir.mkdir(specifications_dir)
- FileUtils.ln_s(bundler_dir, File.join(gems_dir, "bundler-#{Bundler::VERSION}"))
+ FileUtils.ln_s(bundler_dir, File.join(gems_dir, full_name))
gemspec_file = ruby_core? ? "#{bundler_dir}/lib/bundler/bundler.gemspec" : "#{bundler_dir}/bundler.gemspec"
- gemspec = File.read(gemspec_file).
+ gemspec = File.binread(gemspec_file).
sub("Bundler::VERSION", %("#{Bundler::VERSION}"))
gemspec = gemspec.lines.reject {|line| line =~ %r{lib/bundler/version} }.join
- File.open(File.join(specifications_dir, "bundler.gemspec"), "wb") do |f|
+ File.open(File.join(specifications_dir, "#{full_name}.gemspec"), "wb") do |f|
f.write(gemspec)
end
end
- # Can't make this pass on 2.6 since the ruby standard library has the same $LOAD_PATH
- # entry as bundler (since it's a default gem)
- it "should successfully require 'bundler/setup'", :ruby_repo, :ruby => "< 2.6" do
+ it "should not remove itself from the LOAD_PATH and require a different copy of 'bundler/setup'", :ruby_repo do
install_gemfile ""
- ENV["GEM_PATH"] = symlinked_gem_home.path
-
- ruby <<-R
- if $LOAD_PATH.include?("#{bundler_lib}")
- # We should use bundler from GEM_PATH for this test, so we should
- # remove path to the bundler source tree
- $LOAD_PATH.delete("#{bundler_lib}")
- else
- raise "We don't have #{bundler_lib} in $LOAD_PATH"
+ ruby <<-R, :env => { "GEM_PATH" => symlinked_gem_home }, :no_lib => true
+ TracePoint.trace(:class) do |tp|
+ puts "OMG" if tp.path.include?("bundler") && !tp.path.start_with?("#{File.expand_path("../..", __dir__)}")
end
- puts (require 'bundler/setup')
+ gem 'bundler', '#{Bundler::VERSION}'
+ require 'bundler/setup'
R
- expect(out).to eql("true")
+ expect(out).to be_empty
end
end
@@ -943,7 +878,7 @@ end
require 'foo'
R
end
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
end
it "should make sure the Bundler.root is really included in the path relative to the Gemfile" do
@@ -968,7 +903,7 @@ end
R
end
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
end
end
@@ -1046,7 +981,7 @@ end
describe "with system gems in the bundle" do
before :each do
- bundle! "config path.system true"
+ bundle! "config set path.system true"
system_gems "rack-1.0.0"
install_gemfile <<-G
@@ -1099,9 +1034,9 @@ end
end.ref_for("HEAD")
bundle :install
- expect(out.lines.map(&:chomp)).to include(
+ expect(err.lines.map(&:chomp)).to include(
a_string_starting_with("[!] There was an error while loading `bar.gemspec`:"),
- RUBY_VERSION >= "1.9" ? a_string_starting_with("Does it try to require a relative path? That's been removed in Ruby 1.9.") : "",
+ a_string_starting_with("Does it try to require a relative path? That's been removed in Ruby 1.9."),
" # from #{default_bundle_path "bundler", "gems", "bar-1.0-#{ref[0, 12]}", "bar.gemspec"}:1",
" > require 'foobarbaz'"
)
@@ -1118,7 +1053,7 @@ end
Bundler.load
RUBY
- expect(err).to lack_errors
+ expect(last_command.stderr).to be_empty
expect(out).to eq("")
end
end
@@ -1129,8 +1064,8 @@ end
gem "bundler", :path => "#{File.expand_path("..", lib)}"
G
- bundle %(exec ruby -e "require 'bundler'; Bundler.setup"), :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" }
- expect(err).to lack_errors
+ bundle %(exec ruby -e "require 'bundler'; Bundler.setup")
+ expect(last_command.stderr).to be_empty
end
end
@@ -1253,7 +1188,7 @@ end
end
describe "with gemified standard libraries" do
- it "does not load Psych", :ruby => "~> 2.2" do
+ it "does not load Psych" do
gemfile ""
ruby <<-RUBY
require 'bundler/setup'
@@ -1279,7 +1214,7 @@ end
describe "default gem activation" do
let(:exemptions) do
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") || ENV["RGV"] == "master"
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7")
[]
else
%w[io-console openssl]
@@ -1310,7 +1245,6 @@ end
end
let(:code) { strip_whitespace(<<-RUBY) }
- require "bundler/setup"
require "pp"
loaded_specs = Gem.loaded_specs.dup
#{exemptions.inspect}.each {|s| loaded_specs.delete(s) }
@@ -1325,22 +1259,18 @@ end
it "activates no gems with -rbundler/setup" do
install_gemfile! ""
- ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt }
+ ruby! code, :env => { :RUBYOPT => activation_warning_hack_rubyopt + " -rbundler/setup" }
expect(last_command.stdout).to eq("{}")
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 + " -rbundler/setup" }
+ 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
- # TODO: remove once https://github.com/erikhuda/thor/pull/539 is released
- exemptions << "io-console"
-
install_gemfile! ""
create_file("script.rb", "#!/usr/bin/env ruby\n\n#{code}")
FileUtils.chmod(0o777, bundled_app("script.rb"))
diff --git a/spec/bundler/runtime/with_clean_env_spec.rb b/spec/bundler/runtime/with_clean_env_spec.rb
deleted file mode 100644
index da8e37b45d..0000000000
--- a/spec/bundler/runtime/with_clean_env_spec.rb
+++ /dev/null
@@ -1,151 +0,0 @@
-# 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"
- gemfile ""
- bundle "install"
- end
-
- it "should return the PATH present before bundle was activated" do
- code = "print Bundler.original_env['PATH']"
- path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo"
- with_path_as(path) do
- bundle_exec_ruby!(code.dump)
- expect(last_command.stdboth).to eq(path)
- end
- end
-
- it "should return the GEM_PATH present before bundle was activated" do
- code = "print Bundler.original_env['GEM_PATH']"
- gem_path = ENV["GEM_PATH"] + ":/foo"
- with_gem_path_as(gem_path) do
- bundle_exec_ruby!(code.dump)
- expect(last_command.stdboth).to eq(gem_path)
- end
- end
-
- it "works with nested bundle exec invocations", :ruby_repo do
- create_file("exe.rb", <<-'RB')
- count = ARGV.first.to_i
- exit if count < 0
- STDERR.puts "#{count} #{ENV["PATH"].end_with?(":/foo")}"
- if count == 2
- ENV["PATH"] = "#{ENV["PATH"]}:/foo"
- end
- 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 '#{Gem.ruby}' #{bundled_app("exe.rb")} 2", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" }
- end
- expect(err).to eq <<-EOS.strip
-2 false
-1 true
-0 true
- EOS
- end
-
- it "removes variables that bundler added", :ruby_repo do
- 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.dump}", :env => { :RUBYOPT => "-r#{spec_dir.join("support/hax")}" }
- expect(out).to eq original
- end
- end
-
- describe "Bundler.clean_env", :bundler => "< 3" do
- before do
- bundle "config path vendor/bundle"
- gemfile ""
- bundle "install"
- end
-
- it "should delete BUNDLE_PATH" do
- code = "print Bundler.clean_env.has_key?('BUNDLE_PATH')"
- ENV["BUNDLE_PATH"] = "./foo"
- 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"
- 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"
- 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"
- bundle_exec_ruby! code.dump
- expect(last_command.stdboth).to eq("/foo-original")
- end
- end
-
- describe "Bundler.with_original_env" do
- it "should set ENV to original_env in the block" do
- expected = Bundler.original_env
- actual = Bundler.with_original_env { ENV.to_hash }
- expect(actual).to eq(expected)
- end
-
- it "should restore the environment after execution" do
- Bundler.with_original_env do
- ENV["FOO"] = "hello"
- end
-
- expect(ENV).not_to have_key("FOO")
- end
- end
-
- describe "Bundler.with_clean_env", :bundler => "< 3" do
- it "should set ENV to clean_env in the block" do
- expected = Bundler.clean_env
- actual = Bundler.with_clean_env { ENV.to_hash }
- expect(actual).to eq(expected)
- end
-
- it "should restore the environment after execution" do
- Bundler.with_clean_env do
- ENV["FOO"] = "hello"
- end
-
- expect(ENV).not_to have_key("FOO")
- end
- end
-
- describe "Bundler.clean_system", :ruby => ">= 1.9", :bundler => "< 3" 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", :bundler => "< 3" 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))
- end
- Process.wait(pid)
- expect($?.exitstatus).to eq(42)
- end
- end
-end
diff --git a/spec/bundler/runtime/with_unbundled_env_spec.rb b/spec/bundler/runtime/with_unbundled_env_spec.rb
new file mode 100644
index 0000000000..b4503cba32
--- /dev/null
+++ b/spec/bundler/runtime/with_unbundled_env_spec.rb
@@ -0,0 +1,241 @@
+# frozen_string_literal: true
+
+RSpec.describe "Bundler.with_env helpers" do
+ def bundle_exec_ruby!(code)
+ build_bundler_context
+ bundle! "exec '#{Gem.ruby}' -e #{code}"
+ end
+
+ def build_bundler_context
+ bundle "config set path vendor/bundle"
+ gemfile ""
+ bundle "install"
+ end
+
+ describe "Bundler.original_env" do
+ it "should return the PATH present before bundle was activated" do
+ code = "print Bundler.original_env['PATH']"
+ path = `getconf PATH`.strip + "#{File::PATH_SEPARATOR}/foo"
+ with_path_as(path) do
+ bundle_exec_ruby!(code.dump)
+ expect(last_command.stdboth).to eq(path)
+ end
+ end
+
+ it "should return the GEM_PATH present before bundle was activated" do
+ code = "print Bundler.original_env['GEM_PATH']"
+ gem_path = ENV["GEM_PATH"] + ":/foo"
+ with_gem_path_as(gem_path) do
+ bundle_exec_ruby!(code.dump)
+ expect(last_command.stdboth).to eq(gem_path)
+ end
+ end
+
+ it "works with nested bundle exec invocations", :ruby_repo do
+ create_file("exe.rb", <<-'RB')
+ count = ARGV.first.to_i
+ exit if count < 0
+ STDERR.puts "#{count} #{ENV["PATH"].end_with?(":/foo")}"
+ if count == 2
+ ENV["PATH"] = "#{ENV["PATH"]}:/foo"
+ end
+ 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
+ build_bundler_context
+ bundle! "exec '#{Gem.ruby}' #{bundled_app("exe.rb")} 2"
+ end
+ expect(last_command.stderr).to eq <<-EOS.strip
+2 false
+1 true
+0 true
+ EOS
+ end
+
+ it "removes variables that bundler added", :ruby_repo do
+ 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
+ expect(out).to eq original
+ end
+ end
+
+ shared_examples_for "an unbundling helper" do
+ it "should delete BUNDLE_PATH" do
+ code = "print #{modified_env}.has_key?('BUNDLE_PATH')"
+ ENV["BUNDLE_PATH"] = "./foo"
+ bundle_exec_ruby! code.dump
+ expect(last_command.stdboth).to include "false"
+ end
+
+ it "should remove '-rbundler/setup' from RUBYOPT" do
+ code = "print #{modified_env}['RUBYOPT']"
+ ENV["RUBYOPT"] = "-W2 -rbundler/setup #{ENV["RUBYOPT"]}"
+ 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 #{modified_env}['RUBYLIB']"
+ ENV["RUBYLIB"] = root.join("lib").to_s + File::PATH_SEPARATOR + "/foo"
+ bundle_exec_ruby! code.dump
+ expect(last_command.stdboth).to include("/foo")
+ end
+
+ it "should restore the original MANPATH" do
+ code = "print #{modified_env}['MANPATH']"
+ ENV["MANPATH"] = "/foo"
+ ENV["BUNDLER_ORIG_MANPATH"] = "/foo-original"
+ bundle_exec_ruby! code.dump
+ expect(last_command.stdboth).to include("/foo-original")
+ end
+ end
+
+ describe "Bundler.unbundled_env" do
+ let(:modified_env) { "Bundler.unbundled_env" }
+
+ it_behaves_like "an unbundling helper"
+ end
+
+ describe "Bundler.clean_env", :bundler => 2 do
+ let(:modified_env) { "Bundler.clean_env" }
+
+ it_behaves_like "an unbundling helper"
+ end
+
+ describe "Bundler.with_original_env" do
+ it "should set ENV to original_env in the block" do
+ expected = Bundler.original_env
+ actual = Bundler.with_original_env { ENV.to_hash }
+ expect(actual).to eq(expected)
+ end
+
+ it "should restore the environment after execution" do
+ Bundler.with_original_env do
+ ENV["FOO"] = "hello"
+ end
+
+ expect(ENV).not_to have_key("FOO")
+ end
+ end
+
+ describe "Bundler.with_clean_env", :bundler => 2 do
+ it "should set ENV to unbundled_env in the block" do
+ expected = Bundler.unbundled_env
+ actual = Bundler.with_clean_env { ENV.to_hash }
+ expect(actual).to eq(expected)
+ end
+
+ it "should restore the environment after execution" do
+ Bundler.with_clean_env do
+ ENV["FOO"] = "hello"
+ end
+
+ expect(ENV).not_to have_key("FOO")
+ end
+ end
+
+ describe "Bundler.with_unbundled_env" do
+ it "should set ENV to unbundled_env in the block" do
+ expected = Bundler.unbundled_env
+ actual = Bundler.with_unbundled_env { ENV.to_hash }
+ expect(actual).to eq(expected)
+ end
+
+ it "should restore the environment after execution" do
+ Bundler.with_unbundled_env do
+ ENV["FOO"] = "hello"
+ end
+
+ expect(ENV).not_to have_key("FOO")
+ end
+ end
+
+ describe "Bundler.original_system" do
+ it "runs system inside with_original_env" do
+ code = 'exit Bundler.original_system(%(test "\$BUNDLE_FOO" = "bar"))'
+ lib = File.expand_path("../../lib", __dir__)
+ system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'")
+ expect($?.exitstatus).to eq(0)
+ end
+ end
+
+ describe "Bundler.clean_system", :bundler => 2 do
+ it "runs system inside with_clean_env" do
+ code = 'exit Bundler.clean_system(%(test "\$BUNDLE_FOO" = "bar"))'
+ lib = File.expand_path("../../lib", __dir__)
+ system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'")
+ expect($?.exitstatus).to eq(1)
+ end
+ end
+
+ describe "Bundler.unbundled_system" do
+ it "runs system inside with_unbundled_env" do
+ code = 'exit Bundler.clean_system(%(test "\$BUNDLE_FOO" = "bar"))'
+ lib = File.expand_path("../../lib", __dir__)
+ system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'")
+ expect($?.exitstatus).to eq(1)
+ end
+ end
+
+ describe "Bundler.original_exec" do
+ let(:code) do
+ <<~RUBY
+ Process.fork do
+ exit Bundler.original_exec(%(test "\$BUNDLE_FOO" = "bar"))
+ end
+
+ _, status = Process.wait2
+
+ exit(status.exitstatus)
+ RUBY
+ end
+
+ it "runs exec inside with_original_env" do
+ lib = File.expand_path("../../lib", __dir__)
+ system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'")
+ expect($?.exitstatus).to eq(0)
+ end
+ end
+
+ describe "Bundler.clean_exec", :bundler => 2 do
+ let(:code) do
+ <<~RUBY
+ Process.fork do
+ exit Bundler.clean_exec(%(test "\$BUNDLE_FOO" = "bar"))
+ end
+
+ _, status = Process.wait2
+
+ exit(status.exitstatus)
+ RUBY
+ end
+
+ it "runs exec inside with_clean_env" do
+ lib = File.expand_path("../../lib", __dir__)
+ system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'")
+ expect($?.exitstatus).to eq(1)
+ end
+ end
+
+ describe "Bundler.unbundled_exec" do
+ let(:code) do
+ <<~RUBY
+ Process.fork do
+ exit Bundler.unbundled_exec(%(test "\$BUNDLE_FOO" = "bar"))
+ end
+
+ _, status = Process.wait2
+
+ exit(status.exitstatus)
+ RUBY
+ end
+
+ it "runs exec inside with_clean_env" do
+ lib = File.expand_path("../../lib", __dir__)
+ system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'")
+ expect($?.exitstatus).to eq(1)
+ end
+ end
+end