From 323d6d2e09678f1c3a1653b0bdf1de2f05a86410 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Mon, 24 Jul 2017 13:32:57 -0500 Subject: Untangle the system gem path and the default bundle path in the specs --- lib/bundler/resolver.rb | 2 +- spec/commands/clean_spec.rb | 4 ++-- spec/commands/exec_spec.rb | 2 +- spec/commands/install_spec.rb | 20 +++++++++++++++----- spec/commands/newgem_spec.rb | 3 +-- spec/commands/show_spec.rb | 6 +++--- spec/install/allow_offline_install_spec.rb | 2 +- spec/install/gemfile/gemspec_spec.rb | 21 +++++++++++++-------- spec/install/gemfile/git_spec.rb | 5 +++-- spec/install/gemfile/sources_spec.rb | 2 +- spec/install/gems/compact_index_spec.rb | 2 +- spec/install/gemspecs_spec.rb | 4 ++-- spec/install/post_bundle_message_spec.rb | 22 +++++++++++++--------- spec/install/process_lock_spec.rb | 2 ++ spec/other/platform_spec.rb | 26 ++++++++++++++------------ spec/runtime/load_spec.rb | 17 +++++++---------- spec/runtime/platform_spec.rb | 8 ++------ spec/runtime/require_spec.rb | 4 ++-- spec/runtime/setup_spec.rb | 10 ++++++---- spec/support/builders.rb | 15 +++++++++------ spec/support/helpers.rb | 21 +++++++++++++++++---- spec/support/path.rb | 6 +++++- spec/update/git_spec.rb | 4 ++-- 23 files changed, 123 insertions(+), 85 deletions(-) diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 4aeffa7265..00cd0cad26 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -453,7 +453,7 @@ module Bundler message << if versions_with_platforms.any? "The source contains '#{name}' at: #{formatted_versions_with_platforms(versions_with_platforms)}" else - "The source does not contain any versions of '#{requirement}'" + "The source does not contain any versions of '#{name}'" end else message = "Could not find gem '#{requirement}' in any of the gem sources " \ diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb index 387098cdc7..9be8f24fda 100644 --- a/spec/commands/clean_spec.rb +++ b/spec/commands/clean_spec.rb @@ -467,8 +467,9 @@ RSpec.describe "bundle clean" do describe "when missing permissions" do before { ENV["BUNDLE_PATH__SYSTEM"] = "true" } + let(:system_cache_path) { system_gem_path("cache") } after do - FileUtils.chmod(0o755, default_bundle_path("cache")) + FileUtils.chmod(0o755, system_cache_path) end it "returns a helpful error message" do gemfile <<-G @@ -486,7 +487,6 @@ RSpec.describe "bundle clean" do G bundle :install - system_cache_path = default_bundle_path("cache") FileUtils.chmod(0o500, system_cache_path) bundle :clean, :force => true diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 8acc00fc91..bcc436d39b 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "bundle exec" do let(:system_gems_to_install) { %w[rack-1.0.0 rack-0.9.1] } before :each do - system_gems(system_gems_to_install) + system_gems(system_gems_to_install, :path => :bundle_path) end it "activates the correct gem" do diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb index fd825a374f..46ec7105a0 100644 --- a/spec/commands/install_spec.rb +++ b/spec/commands/install_spec.rb @@ -29,13 +29,23 @@ RSpec.describe "bundle install with gem sources" do expect(bundled_app("Gemfile.lock")).to exist end - it "does not create ./.bundle by default" do + it "does not create ./.bundle by default", :bundler => "< 2" do gemfile <<-G source "file://#{gem_repo1}" gem "rack" G - bundle :install # can't use install_gemfile since it sets retry + bundle! :install # can't use install_gemfile since it sets retry + expect(bundled_app(".bundle")).not_to exist + end + + it "does not create ./.bundle by default when installing to system gems" do + gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle! :install, :env => { "BUNDLE_PATH__SYSTEM" => true } # can't use install_gemfile since it sets retry expect(bundled_app(".bundle")).not_to exist end @@ -166,7 +176,7 @@ RSpec.describe "bundle install with gem sources" do end it "does not reinstall any gem that is already available locally" do - system_gems "activesupport-2.3.2" + system_gems "activesupport-2.3.2", :path => :bundle_path build_repo2 do build_gem "activesupport", "2.3.2" do |s| @@ -183,7 +193,7 @@ RSpec.describe "bundle install with gem sources" do end it "works when the gemfile specifies gems that only exist in the system" do - build_gem "foo", :to_system => true + build_gem "foo", :to_bundle => true install_gemfile <<-G source "file://#{gem_repo1}" gem "rack" @@ -194,7 +204,7 @@ RSpec.describe "bundle install with gem sources" do end it "prioritizes local gems over remote gems" do - build_gem "rack", "1.0.0", :to_system => true do |s| + build_gem "rack", "1.0.0", :to_bundle => true do |s| s.add_dependency "activesupport", "2.3.5" end diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index d08a0c0c6b..8543989ca2 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -191,8 +191,6 @@ RSpec.describe "bundle gem" do end it "generates a valid gemspec" do - system_gems ["rake-10.0.2"] - in_app_root bundle "gem newgem --bin" @@ -214,6 +212,7 @@ RSpec.describe "bundle gem" do end Dir.chdir(bundled_app("newgem")) do + system_gems ["rake-10.0.2"], :path => :bundle_path bundle! "exec rake build" end diff --git a/spec/commands/show_spec.rb b/spec/commands/show_spec.rb index 56d8b50a10..9b2648bf75 100644 --- a/spec/commands/show_spec.rb +++ b/spec/commands/show_spec.rb @@ -31,12 +31,12 @@ RSpec.describe "bundle show" do end it "warns if path no longer exists on disk" do - FileUtils.rm_rf("#{system_gem_path}/gems/rails-2.3.2") + FileUtils.rm_rf(default_bundle_path("gems", "rails-2.3.2")) bundle "show rails" - expect(out).to match(/has been deleted/i) - expect(out).to include(default_bundle_path("gems", "rails-2.3.2").to_s) + expect(out).to match(/has been deleted/i). + and include(default_bundle_path("gems", "rails-2.3.2").to_s) end it "prints the path to the running bundler" do diff --git a/spec/install/allow_offline_install_spec.rb b/spec/install/allow_offline_install_spec.rb index 6ef4a95df9..6b335e23d5 100644 --- a/spec/install/allow_offline_install_spec.rb +++ b/spec/install/allow_offline_install_spec.rb @@ -26,7 +26,7 @@ RSpec.describe "bundle install with :allow_offline_install" do context "with cached data locally" do it "will install from the compact index" do - system_gems ["rack-1.0.0"] + system_gems ["rack-1.0.0"], :path => :bundle_path install_gemfile! <<-G, :artifice => "compact_index" source "http://testgemserver.local" diff --git a/spec/install/gemfile/gemspec_spec.rb b/spec/install/gemfile/gemspec_spec.rb index 2585f7106f..6ab974ee41 100644 --- a/spec/install/gemfile/gemspec_spec.rb +++ b/spec/install/gemfile/gemspec_spec.rb @@ -2,8 +2,10 @@ RSpec.describe "bundle install from an existing gemspec" do before(:each) do - build_gem "bar", :to_system => true - build_gem "bar-dev", :to_system => true + build_repo2 do + build_gem "bar" + build_gem "bar-dev" + end end it "should install runtime and development dependencies" do @@ -39,8 +41,10 @@ RSpec.describe "bundle install from an existing gemspec" do end it "should handle a list of requirements" do - build_gem "baz", "1.0", :to_system => true - build_gem "baz", "1.1", :to_system => true + update_repo2 do + build_gem "baz", "1.0" + build_gem "baz", "1.1" + end build_lib("foo", :path => tmp.join("foo")) do |s| s.write("Gemfile", "source :rubygems\ngemspec") @@ -169,7 +173,7 @@ RSpec.describe "bundle install from an existing gemspec" do s.add_dependency "platform_specific" end - install_gem "platform_specific-1.0-java" + system_gems "platform_specific-1.0-java", :path => :bundle_path, :keep_path => true install_gemfile! <<-G gemspec :path => '#{tmp.join("foo")}' @@ -192,6 +196,7 @@ RSpec.describe "bundle install from an existing gemspec" do end it "allows the gemspec to activate other gems" do + ENV["BUNDLE_PATH__SYSTEM"] = "true" # see https://github.com/bundler/bundler/issues/5409 # # issue was caused by rubygems having an unresolved gem during a require, @@ -216,10 +221,10 @@ RSpec.describe "bundle install from an existing gemspec" do s.version = "1.0.0" s.add_dependency "bar", "= 1.0.0" end - build_gem "deps", :to_system => true do |s| + build_gem "deps", :to_bundle => true do |s| s.add_dependency "foo", "= 0.0.1" end - build_gem "foo", "0.0.1", :to_system => true + build_gem "foo", "0.0.1", :to_bundle => true install_gemfile <<-G source "file://#{gem_repo2}" @@ -235,7 +240,7 @@ RSpec.describe "bundle install from an existing gemspec" do s.version = "1.0.0" s.add_dependency "bar", "= 1.0.0" end - build_repo2 do + update_repo2 do build_gem "deps" do |s| s.add_dependency "foo", "= 0.0.1" end diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb index 71ef3c856f..a3e69325cc 100644 --- a/spec/install/gemfile/git_spec.rb +++ b/spec/install/gemfile/git_spec.rb @@ -287,7 +287,7 @@ RSpec.describe "bundle install with git sources" do # ensure we also git fetch after cloning bundle! :update, :all => bundle_update_requires_all? - Dir.chdir(Dir[system_gem_path("cache/bundler/git/foo-*")].first) do + Dir.chdir(Dir[default_bundle_path("cache/bundler/git/foo-*")].first) do sys_exec("git ls-remote .") end @@ -893,6 +893,7 @@ RSpec.describe "bundle install with git sources" do it "prints a friendly error if a file blocks the git repo" do build_git "foo" + FileUtils.mkdir_p(default_bundle_path) FileUtils.touch(default_bundle_path("bundler")) install_gemfile <<-G @@ -1118,7 +1119,7 @@ RSpec.describe "bundle install with git sources" do run! <<-R puts $:.grep(/ext/) R - expect(out).to eq(Pathname.glob(system_gem_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s) + expect(out).to eq(Pathname.glob(default_bundle_path("bundler/gems/extensions/**/foo-1.0-*")).first.to_s) end it "does not use old extension after ref changes" do diff --git a/spec/install/gemfile/sources_spec.rb b/spec/install/gemfile/sources_spec.rb index 6afe8bda59..0b837f87a1 100644 --- a/spec/install/gemfile/sources_spec.rb +++ b/spec/install/gemfile/sources_spec.rb @@ -394,7 +394,7 @@ RSpec.describe "bundle install with gems on multiple sources" do context "with an existing lockfile" do before do - system_gems "rack-0.9.1", "rack-1.0.0" + system_gems "rack-0.9.1", "rack-1.0.0", :path => :bundle_path lockfile <<-L GEM diff --git a/spec/install/gems/compact_index_spec.rb b/spec/install/gems/compact_index_spec.rb index 6dadbd9fca..273366c32f 100644 --- a/spec/install/gems/compact_index_spec.rb +++ b/spec/install/gems/compact_index_spec.rb @@ -830,7 +830,7 @@ The checksum of /versions does not match the checksum provided by the server! So and include("The checksum for the downloaded `rack-1.0.0.gem` does not match the checksum given by the server."). and include("This means the contents of the downloaded gem is different from what was uploaded to the server, and could be a potential security issue."). and include("To resolve this issue:"). - and include("1. delete the downloaded gem located at: `#{system_gem_path}/gems/rack-1.0.0/rack-1.0.0.gem`"). + and include("1. delete the downloaded gem located at: `#{default_bundle_path}/gems/rack-1.0.0/rack-1.0.0.gem`"). and include("2. run `bundle install`"). and include("If you wish to continue installing the downloaded gem, and are certain it does not pose a security issue despite the mismatching checksum, do the following:"). and include("1. run `bundle config disable_checksum_validation true` to turn off checksum verification"). diff --git a/spec/install/gemspecs_spec.rb b/spec/install/gemspecs_spec.rb index a404a556b7..0c1ed99097 100644 --- a/spec/install/gemspecs_spec.rb +++ b/spec/install/gemspecs_spec.rb @@ -33,8 +33,8 @@ RSpec.describe "bundle install" do gem 'rack' G - FileUtils.mkdir_p "#{tmp}/gems/system/specifications" - File.open("#{tmp}/gems/system/specifications/rack-1.0.0.gemspec", "w+") do |f| + FileUtils.mkdir_p "#{default_bundle_path}/specifications" + File.open("#{default_bundle_path}/specifications/rack-1.0.0.gemspec", "w+") do |f| spec = Gem::Specification.new do |s| s.name = "rack" s.version = "1.0.0" diff --git a/spec/install/post_bundle_message_spec.rb b/spec/install/post_bundle_message_spec.rb index 08b70f9512..a953847bac 100644 --- a/spec/install/post_bundle_message_spec.rb +++ b/spec/install/post_bundle_message_spec.rb @@ -13,11 +13,13 @@ RSpec.describe "post bundle message" do G end - let(:bundle_show_message) { "Use `bundle info [gemname]` to see where a bundled gem is installed." } - let(:bundle_deployment_message) { "Bundled gems are installed into `./vendor`" } - let(:bundle_complete_message) { "Bundle complete!" } - let(:bundle_updated_message) { "Bundle updated!" } - let(:installed_gems_stats) { "4 Gemfile dependencies, 5 gems now installed." } + let(:bundle_path) { "./.bundle" } + let(:bundle_show_system_message) { "Use `bundle info [gemname]` to see where a bundled gem is installed." } + let(:bundle_show_path_message) { "Bundled gems are installed into `#{bundle_path}`" } + let(:bundle_complete_message) { "Bundle complete!" } + let(:bundle_updated_message) { "Bundle updated!" } + let(:installed_gems_stats) { "4 Gemfile dependencies, 5 gems now installed." } + let(:bundle_show_message) { Bundler::VERSION.split(".").first.to_i < 2 ? bundle_show_system_message : bundle_show_path_message } describe "for fresh bundle install" do it "without any options" do @@ -53,30 +55,32 @@ RSpec.describe "post bundle message" do end describe "with --path and" do + let(:bundle_path) { "./vendor" } + it "without any options" do bundle! :install, forgotten_command_line_options(:path => "vendor") - expect(out).to include(bundle_deployment_message) + expect(out).to include(bundle_show_path_message) expect(out).to_not include("Gems in the group") expect(out).to include(bundle_complete_message) end it "with --without one group" do bundle! :install, forgotten_command_line_options(:without => "emo", :path => "vendor") - expect(out).to include(bundle_deployment_message) + expect(out).to include(bundle_show_path_message) expect(out).to include("Gems in the group emo were not installed") expect(out).to include(bundle_complete_message) end it "with --without two groups" do bundle! :install, forgotten_command_line_options(:without => "emo test", :path => "vendor") - expect(out).to include(bundle_deployment_message) + expect(out).to include(bundle_show_path_message) expect(out).to include("Gems in the groups emo and test were not installed") expect(out).to include(bundle_complete_message) end it "with --without more groups" do bundle! :install, forgotten_command_line_options(:without => "emo obama test", :path => "vendor") - expect(out).to include(bundle_deployment_message) + expect(out).to include(bundle_show_path_message) expect(out).to include("Gems in the groups emo, obama and test were not installed") expect(out).to include(bundle_complete_message) end diff --git a/spec/install/process_lock_spec.rb b/spec/install/process_lock_spec.rb index 113fd37934..02217f493b 100644 --- a/spec/install/process_lock_spec.rb +++ b/spec/install/process_lock_spec.rb @@ -2,6 +2,8 @@ RSpec.describe "process lock spec" do describe "when an install operation is already holding a process lock" do + before { FileUtils.mkdir_p(default_bundle_path) } + it "will not run a second concurrent bundle install until the lock is released" do thread = Thread.new do Bundler::ProcessLock.lock(default_bundle_path) do diff --git a/spec/other/platform_spec.rb b/spec/other/platform_spec.rb index 7b0c71311f..63831c89b6 100644 --- a/spec/other/platform_spec.rb +++ b/spec/other/platform_spec.rb @@ -595,7 +595,7 @@ G end it "prints path if ruby version is correct" do - gemfile <<-G + install_gemfile! <<-G source "file://#{gem_repo1}" gem "rails" @@ -608,7 +608,7 @@ G it "prints path if ruby version is correct for any engine" do simulate_ruby_engine "jruby" do - gemfile <<-G + install_gemfile! <<-G source "file://#{gem_repo1}" gem "rails" @@ -676,11 +676,10 @@ G context "bundle cache" do before do - gemfile <<-G + install_gemfile <<-G + source "file:#{gem_repo1}" gem 'rack' G - - system_gems "rack-1.0.0" end it "copies the .gem file to vendor/cache when ruby version matches" do @@ -696,13 +695,14 @@ G it "copies the .gem file to vendor/cache when ruby version matches for any engine" do simulate_ruby_engine "jruby" do - gemfile <<-G + install_gemfile! <<-G + source "file:#{gem_repo1}" gem 'rack' #{ruby_version_correct_engineless} G - bundle :cache + bundle! :cache expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end end @@ -757,11 +757,10 @@ G context "bundle pack" do before do - gemfile <<-G + install_gemfile! <<-G + source "file:#{gem_repo1}" gem 'rack' G - - system_gems "rack-1.0.0" end it "copies the .gem file to vendor/cache when ruby version matches" do @@ -777,7 +776,8 @@ G it "copies the .gem file to vendor/cache when ruby version matches any engine" do simulate_ruby_engine "jruby" do - gemfile <<-G + install_gemfile! <<-G + source "file:#{gem_repo1}" gem 'rack' #{ruby_version_correct_engineless} @@ -839,7 +839,7 @@ G context "bundle exec" do before do ENV["BUNDLER_FORCE_TTY"] = "true" - system_gems "rack-1.0.0", "rack-0.9.1" + system_gems "rack-1.0.0", "rack-0.9.1", :path => :bundle_path end it "activates the correct gem when ruby version matches" do @@ -855,6 +855,7 @@ G it "activates the correct gem when ruby version matches any engine" do simulate_ruby_engine "jruby" do + system_gems "rack-1.0.0", "rack-0.9.1", :path => :bundle_path gemfile <<-G gem "rack", "0.9.1" @@ -1179,6 +1180,7 @@ G it "returns list of outdated gems when the ruby version matches for any engine" do simulate_ruby_engine "jruby" do + bundle! :install update_repo2 do build_gem "activesupport", "3.0" update_git "foo", :path => lib_path("foo") diff --git a/spec/runtime/load_spec.rb b/spec/runtime/load_spec.rb index 8f38e4fd04..b74dbde3f6 100644 --- a/spec/runtime/load_spec.rb +++ b/spec/runtime/load_spec.rb @@ -1,13 +1,9 @@ # frozen_string_literal: true 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 @@ -35,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 @@ -76,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 @@ -100,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/runtime/platform_spec.rb b/spec/runtime/platform_spec.rb index 5160d602e0..f38f733845 100644 --- a/spec/runtime/platform_spec.rb +++ b/spec/runtime/platform_spec.rb @@ -48,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 @@ -77,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/runtime/require_spec.rb b/spec/runtime/require_spec.rb index 5dcbba5d06..3eccd60fba 100644 --- a/spec/runtime/require_spec.rb +++ b/spec/runtime/require_spec.rb @@ -314,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 @@ -355,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/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 3f95399c2b..0ea07c7b0a 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -116,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" do @@ -787,7 +787,7 @@ end G run! "puts ENV['MANPATH']" - expect(out).to eq("#{system_gem_path("gems/with_man-1.0/man")}:/foo") + expect(out).to eq("#{default_bundle_path("gems/with_man-1.0/man")}:/foo") end end @@ -801,7 +801,7 @@ end G run! "puts ENV['MANPATH']" - expect(out).to eq(system_gem_path("gems/with_man-1.0/man").to_s) + expect(out).to eq(default_bundle_path("gems/with_man-1.0/man").to_s) end end end @@ -995,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 @@ -1008,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 @@ -1310,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| diff --git a/spec/support/builders.rb b/spec/support/builders.rb index 6b15cffe5a..af91c5e6a7 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -718,18 +718,21 @@ module Spec class GemBuilder < LibBuilder def _build(opts) lib_path = super(opts.merge(:path => @context.tmp(".tmp/#{@spec.full_name}"), :no_default => opts[:no_default])) + destination = opts[:path] || _default_path Dir.chdir(lib_path) do - destination = opts[:path] || _default_path FileUtils.mkdir_p(destination) @spec.authors = ["that guy"] if !@spec.authors || @spec.authors.empty? Bundler.rubygems.build(@spec, opts[:skip_validation]) - if opts[:to_system] - `gem install --ignore-dependencies --no-ri --no-rdoc #{@spec.full_name}.gem` - else - FileUtils.mv("#{@spec.full_name}.gem", opts[:path] || _default_path) - end + end + gem_path = File.expand_path("#{@spec.full_name}.gem", lib_path) + if opts[:to_system] + @context.system_gems gem_path, :keep_path => true + elsif opts[:to_bundle] + @context.system_gems gem_path, :path => :bundle_path, :keep_path => true + else + FileUtils.mv(gem_path, destination) end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index be187d5332..a0b46bfad7 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -362,11 +362,24 @@ module Spec def system_gems(*gems) opts = gems.last.is_a?(Hash) ? gems.last : {} path = opts.fetch(:path, system_gem_path) - path = ruby!("require 'bundler'; puts Bundler.bundle_path") if path == :bundle_path + if path == :bundle_path + path = ruby!(<<-RUBY) + require "bundler" + begin + puts Bundler.bundle_path + rescue Bundler::GemfileNotFound + ENV["BUNDLE_GEMFILE"] = "Gemfile" + retry + end + + RUBY + end gems = gems.flatten - FileUtils.rm_rf(path) - FileUtils.mkdir_p(path) + unless opts[:keep_path] + FileUtils.rm_rf(path) + FileUtils.mkdir_p(path) + end Gem.clear_paths @@ -426,7 +439,7 @@ module Spec def simulate_new_machine system_gems [] - FileUtils.rm_rf default_bundle_path + FileUtils.rm_rf system_gem_path FileUtils.rm_rf bundled_app(".bundle") end diff --git a/spec/support/path.rb b/spec/support/path.rb index cc9c5b3cad..54fc03c850 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -17,7 +17,11 @@ module Spec end def default_bundle_path(*path) - system_gem_path(*path) + if Bundler::VERSION.split(".").first.to_i < 2 + system_gem_path(*path) + else + bundled_app(*[".bundle", ENV.fetch("BUNDLER_SPEC_RUBY_ENGINE", Gem.ruby_engine), Gem::ConfigMap[:ruby_version], *path].compact) + end end def bundled_app(*path) diff --git a/spec/update/git_spec.rb b/spec/update/git_spec.rb index b8f98ade27..95b0a95976 100644 --- a/spec/update/git_spec.rb +++ b/spec/update/git_spec.rb @@ -56,7 +56,7 @@ RSpec.describe "bundle update" do it "floats on master when updating all gems that are pinned to the source even if you have child dependencies" do build_git "foo", :path => lib_path("foo") - build_gem "bar", :to_system => true do |s| + build_gem "bar", :to_bundle => true do |s| s.add_dependency "foo" end @@ -117,7 +117,7 @@ RSpec.describe "bundle update" do describe "with submodules" do before :each do - build_gem "submodule", :to_system => true do |s| + build_gem "submodule", :to_bundle => true do |s| s.write "lib/submodule.rb", "puts 'GEM'" end -- cgit v1.2.1