From 2c26c8c2f3b2d8c68c2170ba06193b1d13847738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 26 Aug 2019 11:34:59 +0200 Subject: Extract `bundled_app_lock` path helper --- spec/bundler/definition_spec.rb | 6 +++--- spec/bundler/env_spec.rb | 2 +- spec/cache/gems_spec.rb | 6 +++--- spec/commands/binstubs_spec.rb | 2 +- spec/commands/check_spec.rb | 6 +++--- spec/commands/clean_spec.rb | 4 ++-- spec/commands/info_spec.rb | 2 +- spec/commands/inject_spec.rb | 14 +++++++------- spec/commands/install_spec.rb | 12 ++++++------ spec/commands/show_spec.rb | 4 ++-- spec/commands/update_spec.rb | 4 ++-- spec/install/gemfile/git_spec.rb | 14 +++++++------- spec/install/gems/flex_spec.rb | 2 +- spec/install/gems/win32_spec.rb | 2 +- spec/lock/lockfile_spec.rb | 28 ++++++++++++++-------------- spec/other/platform_spec.rb | 38 +++++++++++++++++++------------------- spec/runtime/setup_spec.rb | 14 +++++++------- spec/support/matchers.rb | 2 +- spec/support/path.rb | 4 ++++ 19 files changed, 85 insertions(+), 81 deletions(-) diff --git a/spec/bundler/definition_spec.rb b/spec/bundler/definition_spec.rb index 1f4c1a0807..ad6d4e433e 100644 --- a/spec/bundler/definition_spec.rb +++ b/spec/bundler/definition_spec.rb @@ -213,7 +213,7 @@ RSpec.describe Bundler::Definition do end it "should get a locked specs list when updating all" do - definition = Bundler::Definition.new(bundled_app("Gemfile.lock"), [], Bundler::SourceList.new, true) + definition = Bundler::Definition.new(bundled_app_lock, [], Bundler::SourceList.new, true) locked_specs = definition.gem_version_promoter.locked_specs expect(locked_specs.to_a.map(&:name)).to eq ["foo"] expect(definition.instance_variable_get("@locked_specs").empty?).to eq true @@ -275,7 +275,7 @@ RSpec.describe Bundler::Definition do Bundler::Dependency.new("shared_owner_b", ">= 0")] unlock_hash_for_bundle_install = {} definition = Bundler::Definition.new( - bundled_app("Gemfile.lock"), + bundled_app_lock, updated_deps_in_gemfile, source_list, unlock_hash_for_bundle_install @@ -289,7 +289,7 @@ RSpec.describe Bundler::Definition do Bundler::Dependency.new("shared_owner_a", ">= 0"), Bundler::Dependency.new("shared_owner_b", ">= 0")] definition = Bundler::Definition.new( - bundled_app("Gemfile.lock"), + bundled_app_lock, updated_deps_in_gemfile, source_list, :gems => ["shared_owner_a"], :lock_shared_dependencies => true diff --git a/spec/bundler/env_spec.rb b/spec/bundler/env_spec.rb index 5e588a6042..aefedebf13 100644 --- a/spec/bundler/env_spec.rb +++ b/spec/bundler/env_spec.rb @@ -177,7 +177,7 @@ RSpec.describe Bundler::Env do ### Gemfile.lock ``` - + ``` ENV end diff --git a/spec/cache/gems_spec.rb b/spec/cache/gems_spec.rb index 89d6d41570..b82ccbbd30 100644 --- a/spec/cache/gems_spec.rb +++ b/spec/cache/gems_spec.rb @@ -69,7 +69,7 @@ RSpec.describe "bundle cache" do bundle "cache" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end @@ -165,11 +165,11 @@ RSpec.describe "bundle cache" do end it "should not explode if the lockfile is not present" do - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) bundle :cache - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb index b24392caa1..0c86e4cdb6 100644 --- a/spec/commands/binstubs_spec.rb +++ b/spec/commands/binstubs_spec.rb @@ -221,7 +221,7 @@ RSpec.describe "bundle binstubs " do context "without a lockfile" do it "falls back to the latest installed bundler" do - FileUtils.rm bundled_app("Gemfile.lock") + FileUtils.rm bundled_app_lock sys_exec! bundled_app("bin/bundle").to_s expect(out).to eq "system bundler #{system_bundler_version}\n[]" end diff --git a/spec/commands/check_spec.rb b/spec/commands/check_spec.rb index c755ef2804..46a5aaa75a 100644 --- a/spec/commands/check_spec.rb +++ b/spec/commands/check_spec.rb @@ -33,7 +33,7 @@ RSpec.describe "bundle check" do bundle "check" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "does not create a Gemfile.lock if --dry-run was passed" do @@ -46,7 +46,7 @@ RSpec.describe "bundle check" do bundle "check --dry-run" - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist end it "prints a generic error if the missing gems are unresolvable" do @@ -232,7 +232,7 @@ RSpec.describe "bundle check" do G bundle! "install", forgotten_command_line_options(:deployment => true) - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) bundle :check expect(last_command).to be_failure diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb index 471ddb0805..590852b02d 100644 --- a/spec/commands/clean_spec.rb +++ b/spec/commands/clean_spec.rb @@ -585,11 +585,11 @@ RSpec.describe "bundle clean" do bundle "install" # mimic 7 length git revisions in Gemfile.lock - gemfile_lock = File.read(bundled_app("Gemfile.lock")).split("\n") + gemfile_lock = File.read(bundled_app_lock).split("\n") gemfile_lock.each_with_index do |line, index| gemfile_lock[index] = line[0..(11 + 7)] if line.include?(" revision:") end - lockfile(bundled_app("Gemfile.lock"), gemfile_lock.join("\n")) + lockfile(bundled_app_lock, gemfile_lock.join("\n")) bundle "config set path vendor/bundle" bundle "install" diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index 4feab54d4a..a01360a023 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -15,7 +15,7 @@ RSpec.describe "bundle info" do bundle! "info rails" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "prints information if gem exists in bundle" do diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index 01c1f91877..c5c63935af 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -10,9 +10,9 @@ RSpec.describe "bundle inject", :bundler => "< 3" do context "without a lockfile" do it "locks with the injected gems" do - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile.lock").read).to match(/rack-obama/) + expect(bundled_app_lock.read).to match(/rack-obama/) end end @@ -28,9 +28,9 @@ RSpec.describe "bundle inject", :bundler => "< 3" do end it "locks with the injected gems" do - expect(bundled_app("Gemfile.lock").read).not_to match(/rack-obama/) + expect(bundled_app_lock.read).not_to match(/rack-obama/) bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile.lock").read).to match(/rack-obama/) + expect(bundled_app_lock.read).to match(/rack-obama/) end end @@ -92,9 +92,9 @@ Usage: "bundle inject GEM VERSION" end it "locks with the injected gems" do - expect(bundled_app("Gemfile.lock").read).not_to match(/rack-obama/) + expect(bundled_app_lock.read).not_to match(/rack-obama/) bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile.lock").read).to match(/rack-obama/) + expect(bundled_app_lock.read).to match(/rack-obama/) end it "restores frozen afterwards" do @@ -111,7 +111,7 @@ Usage: "bundle inject GEM VERSION" bundle "inject 'rack' '> 0'" expect(err).to match(/trying to install in deployment mode after changing/) - expect(bundled_app("Gemfile.lock").read).not_to match(/rack-obama/) + expect(bundled_app_lock.read).not_to match(/rack-obama/) end end end diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb index c79e44677a..8acf2202bb 100644 --- a/spec/commands/install_spec.rb +++ b/spec/commands/install_spec.rb @@ -17,7 +17,7 @@ RSpec.describe "bundle install with gem sources" do G expect(err).to include('StandardError, "FAIL"') - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist end it "creates a Gemfile.lock" do @@ -26,7 +26,7 @@ RSpec.describe "bundle install with gem sources" do gem "rack" G - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "does not create ./.bundle by default", :bundler => "< 3" do @@ -66,13 +66,13 @@ RSpec.describe "bundle install with gem sources" do gem 'rack' G - lockfile = File.read(bundled_app("Gemfile.lock")) + lockfile = File.read(bundled_app_lock) install_gemfile <<-G raise StandardError, "FAIL" G - expect(File.read(bundled_app("Gemfile.lock"))).to eq(lockfile) + expect(File.read(bundled_app_lock)).to eq(lockfile) end it "does not touch the lockfile if nothing changed" do @@ -81,7 +81,7 @@ RSpec.describe "bundle install with gem sources" do gem "rack" G - expect { run "1" }.not_to change { File.mtime(bundled_app("Gemfile.lock")) } + expect { run "1" }.not_to change { File.mtime(bundled_app_lock) } end it "fetches gems" do @@ -320,7 +320,7 @@ RSpec.describe "bundle install with gem sources" do install_gemfile <<-G G - expect(File.exist?(bundled_app("Gemfile.lock"))).to eq(true) + expect(File.exist?(bundled_app_lock)).to eq(true) end context "throws a warning if a gem is added twice in Gemfile" do diff --git a/spec/commands/show_spec.rb b/spec/commands/show_spec.rb index b21892bae2..3a1fcc1a7a 100644 --- a/spec/commands/show_spec.rb +++ b/spec/commands/show_spec.rb @@ -14,7 +14,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do bundle! "show" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "creates a Gemfile.lock when invoked with a gem name" do @@ -22,7 +22,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do bundle! "show rails" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "prints path if gem exists in bundle" do diff --git a/spec/commands/update_spec.rb b/spec/commands/update_spec.rb index e4449312eb..8455d140fe 100644 --- a/spec/commands/update_spec.rb +++ b/spec/commands/update_spec.rb @@ -31,7 +31,7 @@ RSpec.describe "bundle update" do exit! G bundle "update" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end @@ -54,7 +54,7 @@ RSpec.describe "bundle update" do exit! G bundle "update", :all => true - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb index c916664bd9..249ed48eab 100644 --- a/spec/install/gemfile/git_spec.rb +++ b/spec/install/gemfile/git_spec.rb @@ -481,7 +481,7 @@ RSpec.describe "bundle install with git sources" do gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master" G - lockfile0 = File.read(bundled_app("Gemfile.lock")) + lockfile0 = File.read(bundled_app_lock) FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) update_git "rack", "0.8", :path => lib_path("local-rack") do |s| @@ -491,7 +491,7 @@ RSpec.describe "bundle install with git sources" do bundle %(config set local.rack #{lib_path("local-rack")}) run "require 'rack'" - lockfile1 = File.read(bundled_app("Gemfile.lock")) + lockfile1 = File.read(bundled_app_lock) expect(lockfile1).not_to eq(lockfile0) end @@ -503,7 +503,7 @@ RSpec.describe "bundle install with git sources" do gem "rack", :git => "#{lib_path("rack-0.8")}", :branch => "master" G - lockfile0 = File.read(bundled_app("Gemfile.lock")) + lockfile0 = File.read(bundled_app_lock) FileUtils.cp_r("#{lib_path("rack-0.8")}/.", lib_path("local-rack")) update_git "rack", "0.8", :path => lib_path("local-rack") @@ -511,7 +511,7 @@ RSpec.describe "bundle install with git sources" do bundle %(config set local.rack #{lib_path("local-rack")}) bundle :install - lockfile1 = File.read(bundled_app("Gemfile.lock")) + lockfile1 = File.read(bundled_app_lock) expect(lockfile1).not_to eq(lockfile0) end @@ -965,7 +965,7 @@ RSpec.describe "bundle install with git sources" do gem "bar", :git => "#{lib_path("nested")}" G - expect(File.read(bundled_app("Gemfile.lock")).scan("GIT").size).to eq(1) + expect(File.read(bundled_app_lock).scan("GIT").size).to eq(1) end describe "switching sources" do @@ -1025,8 +1025,8 @@ RSpec.describe "bundle install with git sources" do update_git "valim" new_revision = revision_for(lib_path("valim-1.0")) - old_lockfile = File.read(bundled_app("Gemfile.lock")) - lockfile(bundled_app("Gemfile.lock"), old_lockfile.gsub(/revision: #{old_revision}/, "revision: #{new_revision}")) + old_lockfile = File.read(bundled_app_lock) + lockfile(bundled_app_lock, old_lockfile.gsub(/revision: #{old_revision}/, "revision: #{new_revision}")) bundle "install" diff --git a/spec/install/gems/flex_spec.rb b/spec/install/gems/flex_spec.rb index 865bc7b72a..77891acc24 100644 --- a/spec/install/gems/flex_spec.rb +++ b/spec/install/gems/flex_spec.rb @@ -233,7 +233,7 @@ RSpec.describe "bundle flex_install" do it "does something" do expect do bundle "install" - end.not_to change { File.read(bundled_app("Gemfile.lock")) } + end.not_to change { File.read(bundled_app_lock) } expect(err).to include("rack = 0.9.1") expect(err).to include("locked at 1.0.0") diff --git a/spec/install/gems/win32_spec.rb b/spec/install/gems/win32_spec.rb index 01edcca803..972a455bee 100644 --- a/spec/install/gems/win32_spec.rb +++ b/spec/install/gems/win32_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "bundle install with win32-generated lockfile" do it "should read lockfile" do - File.open(bundled_app("Gemfile.lock"), "wb") do |f| + File.open(bundled_app_lock, "wb") do |f| f << "GEM\r\n" f << " remote: #{file_uri_for(gem_repo1)}/\r\n" f << " specs:\r\n" diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index 0f5a0c6e52..afcb89ba8a 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -1211,7 +1211,7 @@ RSpec.describe "the lockfile format" do gem "rack", "1.1" G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist expect(err).to include "rack (= 1.0) and rack (= 1.1)" end @@ -1222,7 +1222,7 @@ RSpec.describe "the lockfile format" do gem "rack", :git => "git://hubz.com" G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist expect(err).to include "rack (>= 0) should come from an unspecified source and git://hubz.com (at master)" end @@ -1378,7 +1378,7 @@ RSpec.describe "the lockfile format" do describe "a line ending" do def set_lockfile_mtime_to_known_value time = Time.local(2000, 1, 1, 0, 0, 0) - File.utime(time, time, bundled_app("Gemfile.lock")) + File.utime(time, time, bundled_app_lock) end before(:each) do build_repo2 @@ -1391,7 +1391,7 @@ RSpec.describe "the lockfile format" do end it "generates Gemfile.lock with \\n line endings" do - expect(File.read(bundled_app("Gemfile.lock"))).not_to match("\r\n") + expect(File.read(bundled_app_lock)).not_to match("\r\n") expect(the_bundle).to include_gems "rack 1.0" end @@ -1399,8 +1399,8 @@ RSpec.describe "the lockfile format" do it "preserves Gemfile.lock \\n line endings" do update_repo2 - expect { bundle "update", :all => true }.to change { File.mtime(bundled_app("Gemfile.lock")) } - expect(File.read(bundled_app("Gemfile.lock"))).not_to match("\r\n") + expect { bundle "update", :all => true }.to change { File.mtime(bundled_app_lock) } + expect(File.read(bundled_app_lock)).not_to match("\r\n") expect(the_bundle).to include_gems "rack 1.2" end @@ -1408,12 +1408,12 @@ RSpec.describe "the lockfile format" do skip "needs to be adapted" if Gem.win_platform? update_repo2 - win_lock = File.read(bundled_app("Gemfile.lock")).gsub(/\n/, "\r\n") - File.open(bundled_app("Gemfile.lock"), "wb") {|f| f.puts(win_lock) } + win_lock = File.read(bundled_app_lock).gsub(/\n/, "\r\n") + File.open(bundled_app_lock, "wb") {|f| f.puts(win_lock) } set_lockfile_mtime_to_known_value - expect { bundle "update", :all => true }.to change { File.mtime(bundled_app("Gemfile.lock")) } - expect(File.read(bundled_app("Gemfile.lock"))).to match("\r\n") + expect { bundle "update", :all => true }.to change { File.mtime(bundled_app_lock) } + expect(File.read(bundled_app_lock)).to match("\r\n") expect(the_bundle).to include_gems "rack 1.2" end end @@ -1425,12 +1425,12 @@ RSpec.describe "the lockfile format" do require 'bundler' Bundler.setup RUBY - end.not_to change { File.mtime(bundled_app("Gemfile.lock")) } + end.not_to change { File.mtime(bundled_app_lock) } end it "preserves Gemfile.lock \\n\\r line endings" do - win_lock = File.read(bundled_app("Gemfile.lock")).gsub(/\n/, "\r\n") - File.open(bundled_app("Gemfile.lock"), "wb") {|f| f.puts(win_lock) } + win_lock = File.read(bundled_app_lock).gsub(/\n/, "\r\n") + File.open(bundled_app_lock, "wb") {|f| f.puts(win_lock) } set_lockfile_mtime_to_known_value expect do @@ -1438,7 +1438,7 @@ RSpec.describe "the lockfile format" do require 'bundler' Bundler.setup RUBY - end.not_to change { File.mtime(bundled_app("Gemfile.lock")) } + end.not_to change { File.mtime(bundled_app_lock) } end end end diff --git a/spec/other/platform_spec.rb b/spec/other/platform_spec.rb index da35c6a0af..9c8df44acc 100644 --- a/spec/other/platform_spec.rb +++ b/spec/other/platform_spec.rb @@ -298,7 +298,7 @@ G #{ruby_version_correct} G - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "installs fine with any engine" do @@ -310,7 +310,7 @@ G #{ruby_version_correct_engineless} G - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end @@ -322,7 +322,7 @@ G #{ruby_version_correct_patchlevel} G - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "doesn't install when the ruby version doesn't match" do @@ -333,7 +333,7 @@ G #{ruby_version_incorrect} G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_ruby_version_incorrect end @@ -345,7 +345,7 @@ G #{engine_incorrect} G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_engine_incorrect end @@ -358,7 +358,7 @@ G #{engine_version_incorrect} G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_engine_version_incorrect end end @@ -371,7 +371,7 @@ G #{patchlevel_incorrect} G - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_patchlevel_incorrect end end @@ -1051,10 +1051,10 @@ G #{ruby_version_correct} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) run "1" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end it "makes a Gemfile.lock if setup succeeds for any engine" do @@ -1067,10 +1067,10 @@ G #{ruby_version_correct_engineless} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) run "1" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end end @@ -1083,13 +1083,13 @@ G #{ruby_version_incorrect} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) ruby <<-R require 'bundler/setup' R - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_ruby_version_incorrect end @@ -1102,13 +1102,13 @@ G #{engine_incorrect} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) ruby <<-R require 'bundler/setup' R - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_engine_incorrect end @@ -1122,13 +1122,13 @@ G #{engine_version_incorrect} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) ruby <<-R require 'bundler/setup' R - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_engine_version_incorrect end end @@ -1142,13 +1142,13 @@ G #{patchlevel_incorrect} G - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) ruby <<-R require 'bundler/setup' R - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist should_be_patchlevel_incorrect end end diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index cab7b7cc2a..e06e877ff9 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -218,7 +218,7 @@ RSpec.describe "Bundler.setup" do Bundler.setup R - expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app_lock).not_to exist end it "doesn't change the Gemfile.lock if the setup fails" do @@ -227,7 +227,7 @@ RSpec.describe "Bundler.setup" do gem "rack" G - lockfile = File.read(bundled_app("Gemfile.lock")) + lockfile = File.read(bundled_app_lock) gemfile <<-G source "#{file_uri_for(gem_repo1)}" @@ -241,7 +241,7 @@ RSpec.describe "Bundler.setup" do Bundler.setup R - expect(File.read(bundled_app("Gemfile.lock"))).to eq(lockfile) + expect(File.read(bundled_app_lock)).to eq(lockfile) end it "makes a Gemfile.lock if setup succeeds" do @@ -250,12 +250,12 @@ RSpec.describe "Bundler.setup" do gem "rack" G - File.read(bundled_app("Gemfile.lock")) + File.read(bundled_app_lock) - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) run "1" - expect(bundled_app("Gemfile.lock")).to exist + expect(bundled_app_lock).to exist end describe "$BUNDLE_GEMFILE" do @@ -460,7 +460,7 @@ RSpec.describe "Bundler.setup" do it "provides a good exception if the lockfile is unavailable" do bundle "install" - FileUtils.rm(bundled_app("Gemfile.lock")) + FileUtils.rm(bundled_app_lock) break_git! diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index df35854c2f..37461901fc 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -214,7 +214,7 @@ module Spec end def lockfile_should_be(expected) - expect(bundled_app("Gemfile.lock")).to have_lockfile(expected) + expect(bundled_app_lock).to have_lockfile(expected) end def gemfile_should_be(expected) diff --git a/spec/support/path.rb b/spec/support/path.rb index 0c80fe5551..7d3c96ea02 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -96,6 +96,10 @@ module Spec bundled_app("vendor/cache/#{path}.gem") end + def bundled_app_lock + bundled_app("Gemfile.lock") + end + def base_system_gems tmp.join("gems/base") end -- cgit v1.2.1 From d4b6a4164ac7fac1de4c352a04e80dfd8b3a601a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 11 Jan 2020 13:50:21 +0100 Subject: Extract `bundled_app_gemfile` path helper --- spec/bundler/cli_spec.rb | 4 ++-- spec/bundler/dsl_spec.rb | 4 ++-- spec/bundler/plugin_spec.rb | 2 +- spec/commands/add_spec.rb | 36 ++++++++++++++++++------------------ spec/commands/init_spec.rb | 6 +++--- spec/commands/inject_spec.rb | 12 ++++++------ spec/commands/remove_spec.rb | 6 +++--- spec/install/path_spec.rb | 4 ++-- spec/runtime/setup_spec.rb | 4 ++-- spec/support/matchers.rb | 2 +- spec/support/path.rb | 4 ++++ 11 files changed, 44 insertions(+), 40 deletions(-) diff --git a/spec/bundler/cli_spec.rb b/spec/bundler/cli_spec.rb index cafb5579c1..561f471687 100644 --- a/spec/bundler/cli_spec.rb +++ b/spec/bundler/cli_spec.rb @@ -93,7 +93,7 @@ RSpec.describe "bundle executable" do context "when ENV['BUNDLE_GEMFILE'] is set to an empty string" do it "ignores it" do - gemfile bundled_app("Gemfile"), <<-G + gemfile bundled_app_gemfile, <<-G source "#{file_uri_for(gem_repo1)}" gem 'rack' G @@ -106,7 +106,7 @@ RSpec.describe "bundle executable" do context "when ENV['RUBYGEMS_GEMDEPS'] is set" do it "displays a warning" do - gemfile bundled_app("Gemfile"), <<-G + gemfile bundled_app_gemfile, <<-G source "#{file_uri_for(gem_repo1)}" gem 'rack' G diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index 8252367f99..56a5bfdb48 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -271,7 +271,7 @@ RSpec.describe Bundler::Dsl do describe "syntax errors" do it "will raise a Bundler::GemfileError" do gemfile "gem 'foo', :path => /unquoted/string/syntax/error" - expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }. + expect { Bundler::Dsl.evaluate(bundled_app_gemfile, nil, true) }. to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`:( compile error -)? unknown regexp options - trg.+ Bundler cannot continue./) end end @@ -279,7 +279,7 @@ RSpec.describe Bundler::Dsl do describe "Runtime errors" do it "will raise a Bundler::GemfileError" do gemfile "raise RuntimeError, 'foo'" - expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }. + expect { Bundler::Dsl.evaluate(bundled_app_gemfile, nil, true) }. to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: foo. Bundler cannot continue./i) end end diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb index e0e2e9afdf..cb6012da45 100644 --- a/spec/bundler/plugin_spec.rb +++ b/spec/bundler/plugin_spec.rb @@ -107,7 +107,7 @@ RSpec.describe Bundler::Plugin do describe "evaluate gemfile for plugins" do let(:definition) { double("definition") } let(:builder) { double("builder") } - let(:gemfile) { bundled_app("Gemfile") } + let(:gemfile) { bundled_app_gemfile } before do allow(Plugin::DSL).to receive(:new) { builder } diff --git a/spec/commands/add_spec.rb b/spec/commands/add_spec.rb index 35fd43d3d2..672b1ffa52 100644 --- a/spec/commands/add_spec.rb +++ b/spec/commands/add_spec.rb @@ -30,25 +30,25 @@ RSpec.describe "bundle add" do describe "without version specified" do it "version requirement becomes ~> major.minor.patch when resolved version is < 1.0" do bundle "add 'bar'" - expect(bundled_app("Gemfile").read).to match(/gem "bar", "~> 0.12.3"/) + expect(bundled_app_gemfile.read).to match(/gem "bar", "~> 0.12.3"/) expect(the_bundle).to include_gems "bar 0.12.3" end it "version requirement becomes ~> major.minor when resolved version is > 1.0" do bundle "add 'baz'" - expect(bundled_app("Gemfile").read).to match(/gem "baz", "~> 1.2"/) + expect(bundled_app_gemfile.read).to match(/gem "baz", "~> 1.2"/) expect(the_bundle).to include_gems "baz 1.2.3" end it "version requirement becomes ~> major.minor.patch.pre when resolved version is < 1.0" do bundle "add 'cat'" - expect(bundled_app("Gemfile").read).to match(/gem "cat", "~> 0.12.3.pre"/) + expect(bundled_app_gemfile.read).to match(/gem "cat", "~> 0.12.3.pre"/) expect(the_bundle).to include_gems "cat 0.12.3.pre" end it "version requirement becomes ~> major.minor.pre when resolved version is > 1.0.pre" do bundle "add 'dog'" - expect(bundled_app("Gemfile").read).to match(/gem "dog", "~> 1.1.pre"/) + expect(bundled_app_gemfile.read).to match(/gem "dog", "~> 1.1.pre"/) expect(the_bundle).to include_gems "dog 1.1.3.pre" end end @@ -56,14 +56,14 @@ RSpec.describe "bundle add" do describe "with --version" do it "adds dependency of specified version and runs install" do bundle "add 'foo' --version='~> 1.0'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 1.0"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 1.0"/) expect(the_bundle).to include_gems "foo 1.1" end it "adds multiple version constraints when specified" do requirements = ["< 3.0", "> 1.0"] bundle "add 'foo' --version='#{requirements.join(", ")}'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", #{Gem::Requirement.new(requirements).as_list.map(&:dump).join(', ')}/) + expect(bundled_app_gemfile.read).to match(/gem "foo", #{Gem::Requirement.new(requirements).as_list.map(&:dump).join(', ')}/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -71,13 +71,13 @@ RSpec.describe "bundle add" do describe "with --group" do it "adds dependency for the specified group" do bundle "add 'foo' --group='development'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :group => :development/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :group => :development/) expect(the_bundle).to include_gems "foo 2.0" end it "adds dependency to more than one group" do bundle "add 'foo' --group='development, test'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :groups => \[:development, :test\]/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :groups => \[:development, :test\]/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -86,7 +86,7 @@ RSpec.describe "bundle add" do it "adds dependency with specified source" do bundle "add 'foo' --source='#{file_uri_for(gem_repo2)}'" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :source => "#{file_uri_for(gem_repo2)}"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :source => "#{file_uri_for(gem_repo2)}"/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -95,7 +95,7 @@ RSpec.describe "bundle add" do it "adds dependency with specified github source" do bundle "add foo --git=#{lib_path("foo-2.0")}" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}"/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -108,7 +108,7 @@ RSpec.describe "bundle add" do it "adds dependency with specified github source and branch" do bundle "add foo --git=#{lib_path("foo-2.0")} --branch=test" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :branch => "test"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "~> 2.0", :git => "#{lib_path("foo-2.0")}", :branch => "test"/) expect(the_bundle).to include_gems "foo 2.0" end end @@ -117,14 +117,14 @@ RSpec.describe "bundle add" do it "adds gem to Gemfile but is not installed" do bundle "add foo --skip-install --version=2.0" - expect(bundled_app("Gemfile").read).to match(/gem "foo", "= 2.0"/) + expect(bundled_app_gemfile.read).to match(/gem "foo", "= 2.0"/) expect(the_bundle).to_not include_gems "foo 2.0" end end it "using combination of short form options works like long form" do bundle "add 'foo' -s='#{file_uri_for(gem_repo2)}' -g='development' -v='~>1.0'" - expect(bundled_app("Gemfile").read).to include %(gem "foo", "~> 1.0", :group => :development, :source => "#{file_uri_for(gem_repo2)}") + expect(bundled_app_gemfile.read).to include %(gem "foo", "~> 1.0", :group => :development, :source => "#{file_uri_for(gem_repo2)}") expect(the_bundle).to include_gems "foo 1.1" end @@ -153,7 +153,7 @@ RSpec.describe "bundle add" do describe "with --optimistic" do it "adds optimistic version" do bundle! "add 'foo' --optimistic" - expect(bundled_app("Gemfile").read).to include %(gem "foo", ">= 2.0") + expect(bundled_app_gemfile.read).to include %(gem "foo", ">= 2.0") expect(the_bundle).to include_gems "foo 2.0" end end @@ -161,7 +161,7 @@ RSpec.describe "bundle add" do describe "with --strict option" do it "adds strict version" do bundle! "add 'foo' --strict" - expect(bundled_app("Gemfile").read).to include %(gem "foo", "= 2.0") + expect(bundled_app_gemfile.read).to include %(gem "foo", "= 2.0") expect(the_bundle).to include_gems "foo 2.0" end end @@ -169,7 +169,7 @@ RSpec.describe "bundle add" do describe "with no option" do it "adds pessimistic version" do bundle! "add 'foo'" - expect(bundled_app("Gemfile").read).to include %(gem "foo", "~> 2.0") + expect(bundled_app_gemfile.read).to include %(gem "foo", "~> 2.0") expect(the_bundle).to include_gems "foo 2.0" end end @@ -186,8 +186,8 @@ RSpec.describe "bundle add" do it "adds multiple gems to gemfile" do bundle! "add bar baz" - expect(bundled_app("Gemfile").read).to match(/gem "bar", "~> 0.12.3"/) - expect(bundled_app("Gemfile").read).to match(/gem "baz", "~> 1.2"/) + expect(bundled_app_gemfile.read).to match(/gem "bar", "~> 0.12.3"/) + expect(bundled_app_gemfile.read).to match(/gem "baz", "~> 1.2"/) end it "throws error if any of the specified gems are present in the gemfile with different version" do diff --git a/spec/commands/init_spec.rb b/spec/commands/init_spec.rb index 7960ce85bd..1fb83827c2 100644 --- a/spec/commands/init_spec.rb +++ b/spec/commands/init_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "bundle init" do it "generates a Gemfile" do bundle! :init expect(out).to include("Writing new Gemfile") - expect(bundled_app("Gemfile")).to be_file + expect(bundled_app_gemfile).to be_file end context "when a Gemfile already exists" do @@ -15,7 +15,7 @@ RSpec.describe "bundle init" do end it "does not change existing Gemfiles" do - expect { bundle :init }.not_to change { File.read(bundled_app("Gemfile")) } + expect { bundle :init }.not_to change { File.read(bundled_app_gemfile) } end it "notifies the user that an existing Gemfile already exists" do @@ -75,7 +75,7 @@ RSpec.describe "bundle init" do bundle :init, :gemspec => spec_file - gemfile = bundled_app("Gemfile").read + gemfile = bundled_app_gemfile.read expect(gemfile).to match(%r{source 'https://rubygems.org'}) expect(gemfile.scan(/gem "rack", "= 1.0.1"/).size).to eq(1) expect(gemfile.scan(/gem "rspec", "= 1.2"/).size).to eq(1) diff --git a/spec/commands/inject_spec.rb b/spec/commands/inject_spec.rb index c5c63935af..78355edab3 100644 --- a/spec/commands/inject_spec.rb +++ b/spec/commands/inject_spec.rb @@ -22,9 +22,9 @@ RSpec.describe "bundle inject", :bundler => "< 3" do end it "adds the injected gems to the Gemfile" do - expect(bundled_app("Gemfile").read).not_to match(/rack-obama/) + expect(bundled_app_gemfile.read).not_to match(/rack-obama/) bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile").read).to match(/rack-obama/) + expect(bundled_app_gemfile.read).to match(/rack-obama/) end it "locks with the injected gems" do @@ -54,7 +54,7 @@ Usage: "bundle inject GEM VERSION" context "with source option" do it "add gem with source option in gemfile" do bundle "inject 'foo' '>0' --source #{file_uri_for(gem_repo1)}" - gemfile = bundled_app("Gemfile").read + gemfile = bundled_app_gemfile.read str = "gem \"foo\", \"> 0\", :source => \"#{file_uri_for(gem_repo1)}\"" expect(gemfile).to include str end @@ -63,14 +63,14 @@ Usage: "bundle inject GEM VERSION" context "with group option" do it "add gem with group option in gemfile" do bundle "inject 'rack-obama' '>0' --group=development" - gemfile = bundled_app("Gemfile").read + gemfile = bundled_app_gemfile.read str = "gem \"rack-obama\", \"> 0\", :group => :development" expect(gemfile).to include str end it "add gem with multiple groups in gemfile" do bundle "inject 'rack-obama' '>0' --group=development,test" - gemfile = bundled_app("Gemfile").read + gemfile = bundled_app_gemfile.read str = "gem \"rack-obama\", \"> 0\", :groups => [:development, :test]" expect(gemfile).to include str end @@ -88,7 +88,7 @@ Usage: "bundle inject GEM VERSION" it "injects anyway" do bundle "inject 'rack-obama' '> 0'" - expect(bundled_app("Gemfile").read).to match(/rack-obama/) + expect(bundled_app_gemfile.read).to match(/rack-obama/) end it "locks with the injected gems" do diff --git a/spec/commands/remove_spec.rb b/spec/commands/remove_spec.rb index 402faaf1f3..ef313928e2 100644 --- a/spec/commands/remove_spec.rb +++ b/spec/commands/remove_spec.rb @@ -54,7 +54,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" - expect(err).to include("`rack` is not specified in #{bundled_app("Gemfile")} so it could not be removed.") + expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") end end end @@ -91,7 +91,7 @@ RSpec.describe "bundle remove" do bundle "remove rails rack minitest" - expect(err).to include("`rack` is not specified in #{bundled_app("Gemfile")} so it could not be removed.") + expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") gemfile_should_be <<-G source "#{file_uri_for(gem_repo1)}" @@ -436,7 +436,7 @@ RSpec.describe "bundle remove" do bundle "remove rack" - expect(err).to include("`rack` is not specified in #{bundled_app("Gemfile")} so it could not be removed.") + expect(err).to include("`rack` is not specified in #{bundled_app_gemfile} so it could not be removed.") end end diff --git a/spec/install/path_spec.rb b/spec/install/path_spec.rb index 5240c5820c..89a441d0f4 100644 --- a/spec/install/path_spec.rb +++ b/spec/install/path_spec.rb @@ -64,7 +64,7 @@ RSpec.describe "bundle install" do it "installs the standalone bundle relative to the cwd" do Dir.chdir(bundled_app.parent) do - bundle! :install, :gemfile => bundled_app("Gemfile"), :standalone => true + bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true expect(out).to include("installed into `./bundled_app/bundle`") expect(bundled_app("bundle")).to be_directory expect(bundled_app("bundle/ruby")).to be_directory @@ -73,7 +73,7 @@ RSpec.describe "bundle install" do bundle! "config unset path" Dir.chdir(bundled_app("subdir").tap(&:mkpath)) do - bundle! :install, :gemfile => bundled_app("Gemfile"), :standalone => true + bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true expect(out).to include("installed into `../bundle`") expect(bundled_app("bundle")).to be_directory expect(bundled_app("bundle/ruby")).to be_directory diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index e06e877ff9..7ffddbd151 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -866,7 +866,7 @@ end G Dir.chdir(bundled_app.parent) do - run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app("Gemfile").to_s } + run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s } require 'foo' R end @@ -890,7 +890,7 @@ end bundle :install Dir.chdir(bundled_app.parent) do - run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app("Gemfile").to_s } + run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s } require 'foo' R end diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 37461901fc..87f1326448 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -218,7 +218,7 @@ module Spec end def gemfile_should_be(expected) - expect(bundled_app("Gemfile")).to read_as(strip_whitespace(expected)) + expect(bundled_app_gemfile).to read_as(strip_whitespace(expected)) end end end diff --git a/spec/support/path.rb b/spec/support/path.rb index 7d3c96ea02..3de269d91a 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -96,6 +96,10 @@ module Spec bundled_app("vendor/cache/#{path}.gem") end + def bundled_app_gemfile + bundled_app("Gemfile") + end + def bundled_app_lock bundled_app("Gemfile.lock") end -- cgit v1.2.1 From 7c1e5152b19010c95fbbfb62ddfdd753911d94b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 12 Jan 2020 15:18:32 +0100 Subject: Simplify `gem_command` to pass full args to `gem` together --- spec/install/gems/compact_index_spec.rb | 2 +- spec/support/helpers.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/install/gems/compact_index_spec.rb b/spec/install/gems/compact_index_spec.rb index 88f5a5f24b..3f85e9ee38 100644 --- a/spec/install/gems/compact_index_spec.rb +++ b/spec/install/gems/compact_index_spec.rb @@ -1035,7 +1035,7 @@ Either installing with `--full-index` or running `bundle update rails` should fi gem "activemerchant" end G - gem_command! :uninstall, "activemerchant" + gem_command! "uninstall activemerchant" bundle! "update rails", :artifice => "compact_index" expect(lockfile.scan(/activemerchant \(/).size).to eq(1) end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index ff1a9b6823..fe142e62d9 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -180,8 +180,8 @@ module Spec ENV["RUBYOPT"] = old end - def gem_command(command, args = "") - sys_exec("#{Path.gem_bin} #{command} #{args}") + def gem_command(command) + sys_exec("#{Path.gem_bin} #{command}") end bang :gem_command @@ -292,12 +292,12 @@ module Spec def install_gem(path) raise "OMG `#{path}` does not exist!" unless File.exist?(path) - gem_command! :install, "--no-document --ignore-dependencies '#{path}'" + gem_command! "install --no-document --ignore-dependencies '#{path}'" end def with_built_bundler with_root_gemspec do |gemspec| - in_repo_root { gem_command! :build, gemspec.to_s } + in_repo_root { gem_command! "build #{gemspec}" } end bundler_path = root + "bundler-#{Bundler::VERSION}.gem" @@ -406,7 +406,7 @@ module Spec ENV["GEM_PATH"] = system_gem_path.to_s gems.each do |gem| - gem_command! :install, "--no-document #{gem}" + gem_command! "install --no-document #{gem}" end return unless block_given? begin -- cgit v1.2.1 From 544e57cbe9bccd4f6e85c2ccea7e8d4a8c0f59fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 12 Jan 2020 15:38:55 +0100 Subject: Pass a generic options hash to `sys_exec` For consistency with the rest of helpers. --- spec/commands/binstubs_spec.rb | 2 +- spec/commands/newgem_spec.rb | 2 +- spec/runtime/gem_tasks_spec.rb | 4 ++-- spec/runtime/setup_spec.rb | 2 +- spec/support/helpers.rb | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb index 0c86e4cdb6..1d84b16524 100644 --- a/spec/commands/binstubs_spec.rb +++ b/spec/commands/binstubs_spec.rb @@ -137,7 +137,7 @@ RSpec.describe "bundle binstubs " do context "when BUNDLER_VERSION is set" do it "runs the correct version of bundler" do - sys_exec "#{bundled_app("bin/bundle")} install", "BUNDLER_VERSION" => "999.999.999" + sys_exec "#{bundled_app("bin/bundle")} install", :env => { "BUNDLER_VERSION" => "999.999.999" } expect(exitstatus).to eq(42) if exitstatus expect(err).to include("Activating bundler (~> 999.999) failed:"). and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 999.999'`") diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 0bdf8ecba8..13d1e7abd7 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -232,7 +232,7 @@ RSpec.describe "bundle gem" do load_paths = [lib_dir, spec_dir] load_path_str = "-I#{load_paths.join(File::PATH_SEPARATOR)}" - sys_exec! "#{Gem.ruby} #{load_path_str} #{bindir.join("bundle")} gem #{gem_name}", "PATH" => "" + sys_exec! "#{Gem.ruby} #{load_path_str} #{bindir.join("bundle")} gem #{gem_name}", :env => { "PATH" => "" } end it "creates the gem without the need for git" do diff --git a/spec/runtime/gem_tasks_spec.rb b/spec/runtime/gem_tasks_spec.rb index f85f364865..91ea5cf189 100644 --- a/spec/runtime/gem_tasks_spec.rb +++ b/spec/runtime/gem_tasks_spec.rb @@ -29,7 +29,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do it "includes the relevant tasks" do with_gem_path_as(Spec::Path.base_system_gems.to_s) do - sys_exec "#{rake} -T", "RUBYOPT" => "-I#{lib_dir}" + sys_exec "#{rake} -T", :env => { "RUBYOPT" => "-I#{lib_dir}" } end expect(err).to be_empty @@ -47,7 +47,7 @@ RSpec.describe "require 'bundler/gem_tasks'" do it "defines a working `rake install` task" do with_gem_path_as(Spec::Path.base_system_gems.to_s) do - sys_exec "#{rake} install", "RUBYOPT" => "-I#{lib_dir}" + sys_exec "#{rake} install", :env => { "RUBYOPT" => "-I#{lib_dir}" } end expect(err).to be_empty diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 7ffddbd151..8c2c55ac5b 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -1375,7 +1375,7 @@ end end it "takes care of requiring rubygems" do - sys_exec("#{Gem.ruby} -I#{lib_dir} -e \"puts require('bundler/setup')\"", "RUBYOPT" => "--disable=gems") + sys_exec("#{Gem.ruby} -I#{lib_dir} -e \"puts require('bundler/setup')\"", :env => { "RUBYOPT" => "--disable=gems" }) expect(last_command.stdboth).to eq("true") end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index fe142e62d9..4180a2f1ae 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -128,7 +128,7 @@ module Spec end.join cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" - sys_exec(cmd, env, &block) + sys_exec(cmd, { :env => env }, &block) end bang :bundle @@ -155,9 +155,8 @@ module Spec end def ruby(ruby, options = {}) - env = options.delete(:env) || {} lib_option = options[:no_lib] ? "" : " -I#{lib_dir}" - sys_exec(%(#{Gem.ruby}#{lib_option} -w -e #{ruby.shellescape}), env) + sys_exec(%(#{Gem.ruby}#{lib_option} -w -e #{ruby.shellescape}), options) end bang :ruby @@ -189,7 +188,8 @@ module Spec "#{Gem.ruby} -S #{ENV["GEM_PATH"]}/bin/rake" end - def sys_exec(cmd, env = {}) + def sys_exec(cmd, options = {}) + env = options[:env] || {} command_execution = CommandExecution.new(cmd.to_s, Dir.pwd) require "open3" -- cgit v1.2.1 From 0465f07dfe7e49084ac47972aef79fc9d8ecd8e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 12 Jan 2020 17:32:44 +0100 Subject: Extract `man_tracked_files` path helper --- spec/quality_es_spec.rb | 2 +- spec/quality_spec.rb | 2 +- spec/support/path.rb | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/quality_es_spec.rb b/spec/quality_es_spec.rb index 4224d6244f..c1cb028ee1 100644 --- a/spec/quality_es_spec.rb +++ b/spec/quality_es_spec.rb @@ -41,7 +41,7 @@ RSpec.describe "La biblioteca si misma" do included = /ronn/ error_messages = [] in_repo_root do - `git ls-files -z -- man`.split("\x0").each do |filename| + man_tracked_files.split("\x0").each do |filename| next unless filename =~ included error_messages << check_for_expendable_words(filename) error_messages << check_for_specific_pronouns(filename) diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index b519a8747b..c6438817f2 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -157,7 +157,7 @@ RSpec.describe "The library itself" do included = /ronn/ error_messages = [] in_repo_root do - `git ls-files -z -- man`.split("\x0").each do |filename| + man_tracked_files.split("\x0").each do |filename| next unless filename =~ included error_messages << check_for_expendable_words(filename) error_messages << check_for_specific_pronouns(filename) diff --git a/spec/support/path.rb b/spec/support/path.rb index 3de269d91a..a645aa6ffd 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -51,6 +51,12 @@ module Spec @lib_tracked_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb` : `git ls-files -z -- lib` end + def man_tracked_files + skip "not in git working directory" unless git_root_dir? + + @man_tracked_files ||= `git ls-files -z -- man` + end + def tmp(*path) root.join("tmp", scope, *path) end -- cgit v1.2.1 From 58bec9e2911fdc43187854ea225060ccdb4eb38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 12 Jan 2020 17:34:39 +0100 Subject: Don't load default URI gem during specs --- spec/install/gems/compact_index_spec.rb | 2 +- spec/install/gems/dependency_api_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/install/gems/compact_index_spec.rb b/spec/install/gems/compact_index_spec.rb index 3f85e9ee38..be6c01aee9 100644 --- a/spec/install/gems/compact_index_spec.rb +++ b/spec/install/gems/compact_index_spec.rb @@ -645,7 +645,7 @@ The checksum of /versions does not match the checksum provided by the server! So let(:user) { "user" } let(:password) { "pass" } let(:basic_auth_source_uri) do - uri = URI.parse(source_uri) + uri = Bundler::URI.parse(source_uri) uri.user = user uri.password = password diff --git a/spec/install/gems/dependency_api_spec.rb b/spec/install/gems/dependency_api_spec.rb index 6791ff846c..78cca5f8b7 100644 --- a/spec/install/gems/dependency_api_spec.rb +++ b/spec/install/gems/dependency_api_spec.rb @@ -615,7 +615,7 @@ RSpec.describe "gemcutter's dependency API" do let(:user) { "user" } let(:password) { "pass" } let(:basic_auth_source_uri) do - uri = URI.parse(source_uri) + uri = Bundler::URI.parse(source_uri) uri.user = user uri.password = password -- cgit v1.2.1 From 55630c23f4e0683e820116af917888cf23569020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 12 Jan 2020 17:36:08 +0100 Subject: Make warnings spec independent of LOAD_PATH --- spec/quality_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index c6438817f2..95ab31dae0 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -251,10 +251,10 @@ RSpec.describe "The library itself" do ] files_to_require = lib_tracked_files.split("\x0").grep(/\.rb$/) - exclusions files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") } - files_to_require.map! {|f| f.chomp(".rb") } - sys_exec!("ruby -w -Ilib") do |input, _, _| + files_to_require.map! {|f| File.expand_path("../#{f}", __dir__) } + sys_exec!("ruby -w") do |input, _, _| files_to_require.each do |f| - input.puts "require '#{f.sub(%r{\Alib/}, "")}'" + input.puts "require '#{f}'" end end -- cgit v1.2.1 From 7dc38a75680f991bf32320cca850c32d1dcd90ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 10 Jan 2020 09:56:42 +0100 Subject: Remove global directory switching from specs `Dir.chdir` is not thread safe, so it makes our parallel specs flaky. Instead, use the following alternatives: * Use `:chdir` parameter to `Open3` methods for specs that shell out. * Stub `find_gemfile` or other relevant helpers for unit tests. --- spec/bundler/bundler_spec.rb | 2 + spec/bundler/definition_spec.rb | 4 + spec/bundler/dsl_spec.rb | 6 +- spec/bundler/env_spec.rb | 16 ++- spec/bundler/gem_helper_spec.rb | 38 +++---- spec/bundler/plugin/index_spec.rb | 11 ++- spec/bundler/plugin_spec.rb | 7 +- spec/bundler/settings_spec.rb | 2 + spec/bundler/shared_helpers_spec.rb | 39 ++++---- spec/cache/git_spec.rb | 6 +- spec/commands/binstubs_spec.rb | 4 +- spec/commands/check_spec.rb | 7 +- spec/commands/config_spec.rb | 11 +-- spec/commands/doctor_spec.rb | 2 + spec/commands/exec_spec.rb | 36 +++---- spec/commands/info_spec.rb | 2 +- spec/commands/init_spec.rb | 12 +-- spec/commands/install_spec.rb | 9 +- spec/commands/lock_spec.rb | 6 ++ spec/commands/newgem_spec.rb | 98 +++++++++--------- spec/commands/pristine_spec.rb | 2 + spec/commands/show_spec.rb | 11 +-- spec/commands/update_spec.rb | 1 + spec/install/deploy_spec.rb | 13 ++- spec/install/gemfile/eval_gemfile_spec.rb | 4 +- spec/install/gemfile/gemspec_spec.rb | 24 +++-- spec/install/gemfile/git_spec.rb | 83 ++++++---------- spec/install/gemfile/path_spec.rb | 59 +++++------ spec/install/gemfile/ruby_spec.rb | 4 +- spec/install/gemfile/specific_platform_spec.rb | 6 ++ spec/install/gemfile_spec.rb | 8 +- spec/install/gems/standalone_spec.rb | 132 +++++++++---------------- spec/install/global_cache_spec.rb | 42 ++++---- spec/install/path_spec.rb | 42 +++----- spec/plugins/install_spec.rb | 14 +-- spec/plugins/source/example_spec.rb | 11 +-- spec/plugins/source_spec.rb | 3 + spec/quality_es_spec.rb | 20 ++-- spec/quality_spec.rb | 130 +++++++++++------------- spec/runtime/executable_spec.rb | 10 +- spec/runtime/gem_tasks_spec.rb | 5 +- spec/runtime/inline_spec.rb | 32 +++--- spec/runtime/load_spec.rb | 4 +- spec/runtime/platform_spec.rb | 2 +- spec/runtime/setup_spec.rb | 21 ++-- spec/spec_helper.rb | 5 - spec/support/builders.rb | 76 +++++++------- spec/support/helpers.rb | 28 +++--- spec/support/path.rb | 12 +-- spec/support/rubygems_version_manager.rb | 10 +- spec/update/gemfile_spec.rb | 8 +- spec/update/git_spec.rb | 18 ++-- 52 files changed, 511 insertions(+), 647 deletions(-) diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 27477465bb..7237f644e2 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -210,6 +210,8 @@ EOF gem "rack" G + allow(Bundler).to receive(:root).and_return(bundled_app) + Bundler.mkdir_p(bundled_app.join("foo", "bar")) expect(bundled_app.join("foo", "bar")).to exist end diff --git a/spec/bundler/definition_spec.rb b/spec/bundler/definition_spec.rb index ad6d4e433e..d0ebb37933 100644 --- a/spec/bundler/definition_spec.rb +++ b/spec/bundler/definition_spec.rb @@ -210,6 +210,8 @@ RSpec.describe Bundler::Definition do source "#{file_uri_for(gem_repo1)}" gem "foo" G + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "should get a locked specs list when updating all" do @@ -267,6 +269,8 @@ RSpec.describe Bundler::Definition do BUNDLED WITH 1.13.0 L + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "should not eagerly unlock shared dependency with bundle install conservative updating behavior" do diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index 56a5bfdb48..319472d4b0 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -72,7 +72,7 @@ RSpec.describe Bundler::Dsl do describe "#method_missing" do it "raises an error for unknown DSL methods" do - expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s). + expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s). and_return("unknown") error_msg = "There was an error parsing `Gemfile`: Undefined local variable or method `unknown' for Gemfile. Bundler cannot continue." @@ -83,13 +83,13 @@ RSpec.describe Bundler::Dsl do describe "#eval_gemfile" do it "handles syntax errors with a useful message" do - expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).and_return("}") + expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return("}") expect { subject.eval_gemfile("Gemfile") }. to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: (syntax error, unexpected tSTRING_DEND|(compile error - )?syntax error, unexpected '\}'). Bundler cannot continue./) end it "distinguishes syntax errors from evaluation errors" do - expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).and_return( + expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return( "ruby '2.1.5', :engine => 'ruby', :engine_version => '1.2.4'" ) expect { subject.eval_gemfile("Gemfile") }. diff --git a/spec/bundler/env_spec.rb b/spec/bundler/env_spec.rb index aefedebf13..8ff5ddada6 100644 --- a/spec/bundler/env_spec.rb +++ b/spec/bundler/env_spec.rb @@ -86,6 +86,8 @@ RSpec.describe Bundler::Env do BUNDLED WITH 1.10.0 L + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end let(:output) { described_class.report(:print_gemfile => true) } @@ -125,6 +127,8 @@ RSpec.describe Bundler::Env do File.open(bundled_app.join("foo.gemspec"), "wb") do |f| f.write(gemspec) end + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "prints the gemspec" do @@ -137,13 +141,15 @@ RSpec.describe Bundler::Env do context "when eval_gemfile is used" do it "prints all gemfiles" do - create_file "other/Gemfile-other", "gem 'rack'" - create_file "other/Gemfile", "eval_gemfile 'Gemfile-other'" - create_file "Gemfile-alt", <<-G + create_file bundled_app("other/Gemfile-other"), "gem 'rack'" + create_file bundled_app("other/Gemfile"), "eval_gemfile 'Gemfile-other'" + create_file bundled_app("Gemfile-alt"), <<-G source "#{file_uri_for(gem_repo1)}" eval_gemfile "other/Gemfile" G - gemfile "eval_gemfile #{File.expand_path("Gemfile-alt").dump}" + gemfile "eval_gemfile #{bundled_app("Gemfile-alt").to_s.dump}" + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) output = described_class.report(:print_gemspecs => true) expect(output).to include(strip_whitespace(<<-ENV)) @@ -152,7 +158,7 @@ RSpec.describe Bundler::Env do ### Gemfile ```ruby - eval_gemfile #{File.expand_path("Gemfile-alt").dump} + eval_gemfile #{bundled_app("Gemfile-alt").to_s.dump} ``` ### Gemfile-alt diff --git a/spec/bundler/gem_helper_spec.rb b/spec/bundler/gem_helper_spec.rb index b27c96b9a5..6af78e00be 100644 --- a/spec/bundler/gem_helper_spec.rb +++ b/spec/bundler/gem_helper_spec.rb @@ -178,13 +178,11 @@ RSpec.describe Bundler::GemHelper do end before do - Dir.chdir(app_path) do - `git init` - `git config user.email "you@example.com"` - `git config user.name "name"` - `git config commit.gpgsign false` - `git config push.default simple` - end + sys_exec("git init", :dir => app_path) + sys_exec("git config user.email \"you@example.com\"", :dir => app_path) + sys_exec("git config user.name \"name\"", :dir => app_path) + sys_exec("git config commit.gpgsign false", :dir => app_path) + sys_exec("git config push.default simple", :dir => app_path) # silence messages allow(Bundler.ui).to receive(:confirm) @@ -198,13 +196,13 @@ RSpec.describe Bundler::GemHelper do end it "when there are uncommitted files" do - Dir.chdir(app_path) { `git add .` } + sys_exec("git add .", :dir => app_path) expect { Rake.application["release"].invoke }. to raise_error("There are files that need to be committed first.") end it "when there is no git remote" do - Dir.chdir(app_path) { `git commit -a -m "initial commit"` } + sys_exec("git commit -a -m \"initial commit\"", :dir => app_path) expect { Rake.application["release"].invoke }.to raise_error(RuntimeError) end end @@ -213,10 +211,8 @@ RSpec.describe Bundler::GemHelper do let(:repo) { build_git("foo", :bare => true) } before do - Dir.chdir(app_path) do - sys_exec("git remote add origin #{file_uri_for(repo.path)}") - sys_exec('git commit -a -m "initial commit"') - end + sys_exec("git remote add origin #{file_uri_for(repo.path)}", :dir => app_path) + sys_exec('git commit -a -m "initial commit"', :dir => app_path) end context "on releasing" do @@ -225,7 +221,7 @@ RSpec.describe Bundler::GemHelper do mock_confirm_message "Tagged v#{app_version}." mock_confirm_message "Pushed git commits and tags." - Dir.chdir(app_path) { sys_exec("git push -u origin master") } + sys_exec("git push -u origin master", :dir => app_path) end it "calls rubygem_push with proper arguments" do @@ -246,9 +242,7 @@ RSpec.describe Bundler::GemHelper do mock_confirm_message "Tag v#{app_version} has already been created." expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s) - Dir.chdir(app_path) do - `git tag -a -m \"Version #{app_version}\" v#{app_version}` - end + sys_exec("git tag -a -m \"Version #{app_version}\" v#{app_version}", :dir => app_path) Rake.application["release"].invoke end @@ -269,12 +263,10 @@ RSpec.describe Bundler::GemHelper do end before do - Dir.chdir(app_path) do - `git init` - `git config user.email "you@example.com"` - `git config user.name "name"` - `git config push.default simple` - end + sys_exec("git init", :dir => app_path) + sys_exec("git config user.email \"you@example.com\"", :dir => app_path) + sys_exec("git config user.name \"name\"", :dir => app_path) + sys_exec("git config push.gpgsign simple", :dir => app_path) # silence messages allow(Bundler.ui).to receive(:confirm) diff --git a/spec/bundler/plugin/index_spec.rb b/spec/bundler/plugin/index_spec.rb index e18e960fb8..925dc558ac 100644 --- a/spec/bundler/plugin/index_spec.rb +++ b/spec/bundler/plugin/index_spec.rb @@ -4,6 +4,7 @@ RSpec.describe Bundler::Plugin::Index do Index = Bundler::Plugin::Index before do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) gemfile "" path = lib_path(plugin_name) index.register_plugin("new-plugin", path.to_s, [path.join("lib").to_s], commands, sources, hooks) @@ -117,11 +118,11 @@ RSpec.describe Bundler::Plugin::Index do describe "global index" do before do - Dir.chdir(tmp) do - Bundler::Plugin.reset! - path = lib_path("gplugin") - index.register_plugin("gplugin", path.to_s, [path.join("lib").to_s], [], ["glb_source"], []) - end + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(nil) + + Bundler::Plugin.reset! + path = lib_path("gplugin") + index.register_plugin("gplugin", path.to_s, [path.join("lib").to_s], [], ["glb_source"], []) end it "skips sources" do diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb index cb6012da45..8c95723bcc 100644 --- a/spec/bundler/plugin_spec.rb +++ b/spec/bundler/plugin_spec.rb @@ -237,7 +237,7 @@ RSpec.describe Bundler::Plugin do describe "#root" do context "in app dir" do before do - gemfile "" + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "returns plugin dir in app .bundle path" do @@ -246,8 +246,11 @@ RSpec.describe Bundler::Plugin do end context "outside app dir" do + before do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(nil) + end + it "returns plugin dir in global bundle path" do - Dir.chdir tmp expect(subject.root).to eq(home.join(".bundle/plugin")) end end diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb index b83d768477..116a038445 100644 --- a/spec/bundler/settings_spec.rb +++ b/spec/bundler/settings_spec.rb @@ -130,6 +130,8 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow describe "#temporary" do it "reset after used" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + Bundler.settings.set_command_option :no_install, true Bundler.settings.temporary(:no_install => false) do diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index 5c91cb7bd1..4b4d5f33f6 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/bundler/shared_helpers_spec.rb @@ -4,10 +4,13 @@ RSpec.describe Bundler::SharedHelpers do let(:ext_lock_double) { double(:ext_lock) } before do + pwd_stub allow(Bundler.rubygems).to receive(:ext_lock).and_return(ext_lock_double) allow(ext_lock_double).to receive(:synchronize) {|&block| block.call } end + let(:pwd_stub) { allow(subject).to receive(:pwd).and_return(bundled_app) } + subject { Bundler::SharedHelpers } describe "#default_gemfile" do @@ -77,7 +80,7 @@ RSpec.describe Bundler::SharedHelpers do let(:global_rubygems_dir) { Pathname.new(bundled_app) } before do - Dir.mkdir ".bundle" + Dir.mkdir bundled_app(".bundle") allow(Bundler.rubygems).to receive(:user_home).and_return(global_rubygems_dir) end @@ -91,7 +94,7 @@ RSpec.describe Bundler::SharedHelpers do let(:expected_bundle_dir_path) { Pathname.new("#{bundled_app}/.bundle") } before do - Dir.mkdir ".bundle" + Dir.mkdir bundled_app(".bundle") allow(Bundler.rubygems).to receive(:user_home).and_return(global_rubygems_dir) end @@ -109,8 +112,8 @@ RSpec.describe Bundler::SharedHelpers do shared_examples_for "correctly determines whether to return a Gemfile path" do context "currently in directory with a Gemfile" do - before { FileUtils.touch("Gemfile") } - after { FileUtils.rm("Gemfile") } + before { FileUtils.touch(bundled_app_gemfile) } + after { FileUtils.rm(bundled_app_gemfile) } it "returns path of the bundle Gemfile" do expect(subject.in_bundle?).to eq("#{bundled_app}/Gemfile") @@ -148,22 +151,24 @@ RSpec.describe Bundler::SharedHelpers do describe "#chdir" do let(:op_block) { proc { Dir.mkdir "nested_dir" } } - before { Dir.mkdir "chdir_test_dir" } + before { Dir.mkdir bundled_app("chdir_test_dir") } it "executes the passed block while in the specified directory" do - subject.chdir("chdir_test_dir", &op_block) - expect(Pathname.new("chdir_test_dir/nested_dir")).to exist + subject.chdir(bundled_app("chdir_test_dir"), &op_block) + expect(bundled_app("chdir_test_dir/nested_dir")).to exist end end describe "#pwd" do + let(:pwd_stub) { nil } + it "returns the current absolute path" do - expect(subject.pwd).to eq(bundled_app) + expect(subject.pwd).to eq(root) end end describe "#with_clean_git_env" do - let(:with_clean_git_env_block) { proc { Dir.mkdir "with_clean_git_env_test_dir" } } + let(:with_clean_git_env_block) { proc { Dir.mkdir bundled_app("with_clean_git_env_test_dir") } } before do ENV["GIT_DIR"] = "ORIGINAL_ENV_GIT_DIR" @@ -172,20 +177,20 @@ RSpec.describe Bundler::SharedHelpers do it "executes the passed block" do subject.with_clean_git_env(&with_clean_git_env_block) - expect(Pathname.new("with_clean_git_env_test_dir")).to exist + expect(bundled_app("with_clean_git_env_test_dir")).to exist end context "when a block is passed" do let(:with_clean_git_env_block) do proc do - Dir.mkdir "git_dir_test_dir" unless ENV["GIT_DIR"].nil? - Dir.mkdir "git_work_tree_test_dir" unless ENV["GIT_WORK_TREE"].nil? + Dir.mkdir bundled_app("git_dir_test_dir") unless ENV["GIT_DIR"].nil? + Dir.mkdir bundled_app("git_work_tree_test_dir") unless ENV["GIT_WORK_TREE"].nil? end end it "uses a fresh git env for execution" do subject.with_clean_git_env(&with_clean_git_env_block) - expect(Pathname.new("git_dir_test_dir")).to_not exist - expect(Pathname.new("git_work_tree_test_dir")).to_not exist + expect(bundled_app("git_dir_test_dir")).to_not exist + expect(bundled_app("git_work_tree_test_dir")).to_not exist end end @@ -225,7 +230,7 @@ RSpec.describe Bundler::SharedHelpers do end shared_examples_for "ENV['PATH'] gets set correctly" do - before { Dir.mkdir ".bundle" } + before { Dir.mkdir bundled_app(".bundle") } it "ensures bundle bin path is in ENV['PATH']" do subject.set_bundle_environment @@ -245,7 +250,7 @@ RSpec.describe Bundler::SharedHelpers do let(:ruby_lib_path) { "stubbed_ruby_lib_dir" } before do - allow(Bundler::SharedHelpers).to receive(:bundler_ruby_lib).and_return(ruby_lib_path) + allow(subject).to receive(:bundler_ruby_lib).and_return(ruby_lib_path) end it "ensures bundler's ruby version lib path is in ENV['RUBYLIB']" do @@ -264,7 +269,7 @@ RSpec.describe Bundler::SharedHelpers do end it "ignores if bundler_ruby_lib is same as rubylibdir" do - allow(Bundler::SharedHelpers).to receive(:bundler_ruby_lib).and_return(RbConfig::CONFIG["rubylibdir"]) + allow(subject).to receive(:bundler_ruby_lib).and_return(RbConfig::CONFIG["rubylibdir"]) subject.set_bundle_environment diff --git a/spec/cache/git_spec.rb b/spec/cache/git_spec.rb index 75525d405b..ecdc97f837 100644 --- a/spec/cache/git_spec.rb +++ b/spec/cache/git_spec.rb @@ -155,10 +155,8 @@ RSpec.describe "bundle cache with git" do s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", :dir => lib_path("has_submodule-1.0") + sys_exec "git commit -m \"submodulator\"", :dir => lib_path("has_submodule-1.0") install_gemfile <<-G git "#{lib_path("has_submodule-1.0")}", :submodules => true do diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb index 1d84b16524..f77e1772bb 100644 --- a/spec/commands/binstubs_spec.rb +++ b/spec/commands/binstubs_spec.rb @@ -86,7 +86,7 @@ RSpec.describe "bundle binstubs " do bundle "binstubs rack" - File.open("bin/bundle", "wb") do |file| + File.open(bundled_app("bin/bundle"), "wb") do |file| file.print "OMG" end @@ -301,7 +301,7 @@ RSpec.describe "bundle binstubs " do bundle "binstubs rack --shebang jruby" - expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env jruby\n") + expect(File.open(bundled_app("bin/rackup")).gets).to eq("#!/usr/bin/env jruby\n") end end end diff --git a/spec/commands/check_spec.rb b/spec/commands/check_spec.rb index 46a5aaa75a..0b5eae5d0b 100644 --- a/spec/commands/check_spec.rb +++ b/spec/commands/check_spec.rb @@ -18,8 +18,7 @@ RSpec.describe "bundle check" do gem "rails" G - Dir.chdir tmp - bundle "check --gemfile bundled_app/Gemfile" + bundle "check --gemfile bundled_app/Gemfile", :dir => tmp expect(out).to include("The Gemfile's dependencies are satisfied") end @@ -29,7 +28,7 @@ RSpec.describe "bundle check" do gem "rails" G - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) bundle "check" @@ -42,7 +41,7 @@ RSpec.describe "bundle check" do gem "rails" G - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) bundle "check --dry-run" diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb index ef580463e5..7a45dd0dd7 100644 --- a/spec/commands/config_spec.rb +++ b/spec/commands/config_spec.rb @@ -54,14 +54,13 @@ RSpec.describe ".bundle/config" do it "can provide a relative path with the environment variable" do FileUtils.mkdir_p bundled_app("omg") - Dir.chdir bundled_app("omg") ENV["BUNDLE_APP_CONFIG"] = "../foo" - bundle "install", forgotten_command_line_options(:path => "vendor/bundle") + bundle "install", forgotten_command_line_options(:path => "vendor/bundle").merge(:dir => bundled_app("omg")) expect(bundled_app(".bundle")).not_to exist expect(bundled_app("../foo/config")).to exist - expect(the_bundle).to include_gems "rack 1.0.0" + expect(the_bundle).to include_gems "rack 1.0.0", :dir => bundled_app("omg") end end @@ -138,7 +137,7 @@ RSpec.describe ".bundle/config" do it "expands the path at time of setting" do bundle "config set --global local.foo .." run "puts Bundler.settings['local.foo']" - expect(out).to eq(File.expand_path(Dir.pwd + "/..")) + expect(out).to eq(File.expand_path(bundled_app.to_s + "/..")) end it "saves with parseable option" do @@ -205,7 +204,7 @@ RSpec.describe ".bundle/config" do it "expands the path at time of setting" do bundle "config set --local local.foo .." run "puts Bundler.settings['local.foo']" - expect(out).to eq(File.expand_path(Dir.pwd + "/..")) + expect(out).to eq(File.expand_path(bundled_app.to_s + "/..")) end it "can be deleted with parseable option" do @@ -484,7 +483,7 @@ RSpec.describe "setting gemfile via config" do G bundle "config set --local gemfile #{bundled_app("NotGemfile")}" - expect(File.exist?(".bundle/config")).to eq(true) + expect(File.exist?(bundled_app(".bundle/config"))).to eq(true) bundle "config list" expect(out).to include("NotGemfile") diff --git a/spec/commands/doctor_spec.rb b/spec/commands/doctor_spec.rb index e62430d215..0731bb08db 100644 --- a/spec/commands/doctor_spec.rb +++ b/spec/commands/doctor_spec.rb @@ -32,6 +32,7 @@ RSpec.describe "bundle doctor" do before(:each) do stat = double("stat") unwritable_file = double("file") + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) allow(Find).to receive(:find).with(Bundler.bundle_path.to_s) { [unwritable_file] } allow(File).to receive(:stat).with(unwritable_file) { stat } allow(stat).to receive(:uid) { Process.uid } @@ -72,6 +73,7 @@ RSpec.describe "bundle doctor" do before(:each) do @stat = double("stat") @unwritable_file = double("file") + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) allow(Find).to receive(:find).with(Bundler.bundle_path.to_s) { [@unwritable_file] } allow(File).to receive(:stat).with(@unwritable_file) { @stat } end diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb index 69a0b33859..f27eb5ca42 100644 --- a/spec/commands/exec_spec.rb +++ b/spec/commands/exec_spec.rb @@ -129,11 +129,11 @@ RSpec.describe "bundle exec" do skip "https://github.com/bundler/bundler/issues/6898" if Gem.win_platform? install_gemfile 'gem "rack"' - File.open("--verbose", "w") do |f| + File.open(bundled_app("--verbose"), "w") do |f| f.puts "#!/bin/sh" f.puts "echo foobar" end - File.chmod(0o744, "--verbose") + File.chmod(0o744, bundled_app("--verbose")) with_path_as(".") do bundle "exec -- --verbose" end @@ -152,21 +152,17 @@ RSpec.describe "bundle exec" do gem "rack", "0.9.1" G - in_app_root2 do - install_gemfile bundled_app2("Gemfile"), <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack_two", "1.0.0" - G - end + install_gemfile bundled_app2("Gemfile"), <<-G, :dir => bundled_app2 + source "#{file_uri_for(gem_repo2)}" + gem "rack_two", "1.0.0" + G bundle! "exec rackup" expect(out).to eq("0.9.1") - in_app_root2 do - bundle! "exec rackup" - expect(out).to eq("1.0.0") - end + bundle! "exec rackup", :dir => bundled_app2 + expect(out).to eq("1.0.0") end context "with default gems" do @@ -260,12 +256,10 @@ RSpec.describe "bundle exec" do gem "rack", "0.9.1" G - in_app_root2 do - install_gemfile bundled_app2("Gemfile"), <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack_two", "1.0.0" - G - end + install_gemfile bundled_app2("Gemfile"), <<-G, :dir => bundled_app2 + source "#{file_uri_for(gem_repo2)}" + gem "rack_two", "1.0.0" + G bundle! "exec rackup" @@ -624,8 +618,8 @@ RSpec.describe "bundle exec" do RUBY before do - path.open("w") {|f| f << executable } - path.chmod(0o755) + bundled_app(path).open("w") {|f| f << executable } + bundled_app(path).chmod(0o755) install_gemfile <<-G gem "rack" @@ -798,7 +792,7 @@ __FILE__: #{path.to_s.inspect} end context "when the path is relative with a leading ./" do - let(:path) { Pathname.new("./#{super().relative_path_from(Pathname.pwd)}") } + let(:path) { Pathname.new("./#{super().relative_path_from(bundled_app)}") } pending "relative paths with ./ have absolute __FILE__" end diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index a01360a023..b70b711127 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -11,7 +11,7 @@ RSpec.describe "bundle info" do end it "creates a Gemfile.lock when invoked with a gem name" do - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) bundle! "info rails" diff --git a/spec/commands/init_spec.rb b/spec/commands/init_spec.rb index 1fb83827c2..ed52187115 100644 --- a/spec/commands/init_spec.rb +++ b/spec/commands/init_spec.rb @@ -32,9 +32,7 @@ RSpec.describe "bundle init" do FileUtils.mkdir bundled_app(subdir) - Dir.chdir bundled_app(subdir) do - bundle! :init - end + bundle! :init, :dir => bundled_app(subdir) expect(out).to include("Writing new Gemfile") expect(bundled_app("#{subdir}/Gemfile")).to be_file @@ -50,9 +48,7 @@ RSpec.describe "bundle init" do mode = File.stat(bundled_app(subdir)).mode ^ 0o222 FileUtils.chmod mode, bundled_app(subdir) - Dir.chdir bundled_app(subdir) do - bundle :init - end + bundle :init, :dir => bundled_app(subdir) expect(err).to include("directory is not writable") expect(Dir[bundled_app("#{subdir}/*")]).to be_empty @@ -133,9 +129,7 @@ RSpec.describe "bundle init" do FileUtils.mkdir bundled_app(subdir) - Dir.chdir bundled_app(subdir) do - bundle! :init - end + bundle! :init, :dir => bundled_app(subdir) expect(out).to include("Writing new gems.rb") expect(bundled_app("#{subdir}/gems.rb")).to be_file diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb index 8acf2202bb..9a4ce33a26 100644 --- a/spec/commands/install_spec.rb +++ b/spec/commands/install_spec.rb @@ -504,23 +504,20 @@ RSpec.describe "bundle install with gem sources" do end describe "when Bundler root contains regex chars" do - before do + it "doesn't blow up" do root_dir = tmp("foo[]bar") FileUtils.mkdir_p(root_dir) - Dir.chdir(root_dir) - end - it "doesn't blow up" do build_lib "foo" gemfile = <<-G gem 'foo', :path => "#{lib_path("foo-1.0")}" G - File.open("Gemfile", "w") do |file| + File.open("#{root_dir}/Gemfile", "w") do |file| file.puts gemfile end - bundle :install + bundle :install, :dir => root_dir expect(exitstatus).to eq(0) if exitstatus end diff --git a/spec/commands/lock_spec.rb b/spec/commands/lock_spec.rb index 1d9813a835..ceafeb1d7b 100644 --- a/spec/commands/lock_spec.rb +++ b/spec/commands/lock_spec.rb @@ -195,6 +195,8 @@ RSpec.describe "bundle lock" do gem 'foo' gem 'qux' G + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end it "single gem updates dependent gem to minor" do @@ -213,12 +215,15 @@ RSpec.describe "bundle lock" do it "supports adding new platforms" do bundle! "lock --add-platform java x86-mingw32" + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) lockfile = Bundler::LockfileParser.new(read_lockfile) expect(lockfile.platforms).to match_array(local_platforms.unshift(java, mingw).uniq) end it "supports adding the `ruby` platform" do bundle! "lock --add-platform ruby" + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) lockfile = Bundler::LockfileParser.new(read_lockfile) expect(lockfile.platforms).to match_array(local_platforms.unshift("ruby").uniq) end @@ -231,6 +236,7 @@ RSpec.describe "bundle lock" do it "allows removing platforms" do bundle! "lock --add-platform java x86-mingw32" + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) lockfile = Bundler::LockfileParser.new(read_lockfile) expect(lockfile.platforms).to match_array(local_platforms.unshift(java, mingw).uniq) diff --git a/spec/commands/newgem_spec.rb b/spec/commands/newgem_spec.rb index 13d1e7abd7..b8fbf8806a 100644 --- a/spec/commands/newgem_spec.rb +++ b/spec/commands/newgem_spec.rb @@ -162,13 +162,12 @@ RSpec.describe "bundle gem" do end it "includes rubocop in generated Gemfile" do - Dir.chdir(bundled_app(gem_name)) do - builder = Bundler::Dsl.new - builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) - builder.dependencies - rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" } - expect(rubocop_dep).not_to be_nil - end + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" } + expect(rubocop_dep).not_to be_nil end end @@ -186,13 +185,12 @@ RSpec.describe "bundle gem" do end it "does not include rubocop in generated Gemfile" do - Dir.chdir(bundled_app(gem_name)) do - builder = Bundler::Dsl.new - builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) - builder.dependencies - rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" } - expect(rubocop_dep).to be_nil - end + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + rubocop_dep = builder.dependencies.find {|d| d.name == "rubocop" } + expect(rubocop_dep).to be_nil end end @@ -253,11 +251,9 @@ RSpec.describe "bundle gem" do prepare_gemspec(bundled_app("newgem", "newgem.gemspec")) - Dir.chdir(bundled_app("newgem")) do - gems = ["rake-12.3.2"] - system_gems gems, :path => :bundle_path - bundle! "exec rake build" - end + gems = ["rake-12.3.2"] + system_gems gems, :path => :bundle_path, :bundle_dir => bundled_app("newgem") + bundle! "exec rake build", :dir => bundled_app("newgem") expect(last_command.stdboth).not_to include("ERROR") end @@ -266,7 +262,7 @@ RSpec.describe "bundle gem" do it "resolves ." do create_temporary_dir("tmp") - bundle! "gem ." + bundle! "gem .", :dir => bundled_app("tmp") expect(bundled_app("tmp/lib/tmp.rb")).to exist end @@ -274,7 +270,7 @@ RSpec.describe "bundle gem" do it "resolves .." do create_temporary_dir("temp/empty_dir") - bundle! "gem .." + bundle! "gem ..", :dir => bundled_app("temp/empty_dir") expect(bundled_app("temp/lib/temp.rb")).to exist end @@ -282,14 +278,13 @@ RSpec.describe "bundle gem" do it "resolves relative directory" do create_temporary_dir("tmp/empty/tmp") - bundle! "gem ../../empty" + bundle! "gem ../../empty", :dir => bundled_app("tmp/empty/tmp") expect(bundled_app("tmp/empty/lib/empty.rb")).to exist end def create_temporary_dir(dir) - FileUtils.mkdir_p(dir) - Dir.chdir(dir) + FileUtils.mkdir_p(bundled_app(dir)) end end @@ -326,8 +321,8 @@ RSpec.describe "bundle gem" do context "git config user.{name,email} is not set" do before do - `git config --unset user.name` - `git config --unset user.email` + sys_exec("git config --unset user.name", :dir => bundled_app) + sys_exec("git config --unset user.email", :dir => bundled_app) bundle! "gem #{gem_name}" end @@ -375,10 +370,8 @@ RSpec.describe "bundle gem" do file.puts rakefile end - Dir.chdir(bundled_app(gem_name)) do - sys_exec(rake) - expect(out).to include("SUCCESS") - end + sys_exec(rake, :dir => bundled_app(gem_name)) + expect(out).to include("SUCCESS") end context "--exe parameter set" do @@ -435,13 +428,12 @@ RSpec.describe "bundle gem" do end it "depends on a specific version of rspec in generated Gemfile" do - Dir.chdir(bundled_app(gem_name)) do - builder = Bundler::Dsl.new - builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) - builder.dependencies - rspec_dep = builder.dependencies.find {|d| d.name == "rspec" } - expect(rspec_dep).to be_specific - end + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + rspec_dep = builder.dependencies.find {|d| d.name == "rspec" } + expect(rspec_dep).to be_specific end it "requires the main file" do @@ -484,13 +476,12 @@ RSpec.describe "bundle gem" do end it "depends on a specific version of minitest" do - Dir.chdir(bundled_app(gem_name)) do - builder = Bundler::Dsl.new - builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) - builder.dependencies - minitest_dep = builder.dependencies.find {|d| d.name == "minitest" } - expect(minitest_dep).to be_specific - end + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + minitest_dep = builder.dependencies.find {|d| d.name == "minitest" } + expect(minitest_dep).to be_specific end it "builds spec skeleton" do @@ -541,13 +532,12 @@ RSpec.describe "bundle gem" do end it "depends on a specific version of test-unit" do - Dir.chdir(bundled_app(gem_name)) do - builder = Bundler::Dsl.new - builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) - builder.dependencies - test_unit_dep = builder.dependencies.find {|d| d.name == "test-unit" } - expect(test_unit_dep).to be_specific - end + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + builder = Bundler::Dsl.new + builder.eval_gemfile(bundled_app("#{gem_name}/Gemfile")) + builder.dependencies + test_unit_dep = builder.dependencies.find {|d| d.name == "test-unit" } + expect(test_unit_dep).to be_specific end it "builds spec skeleton" do @@ -610,7 +600,7 @@ RSpec.describe "bundle gem" do context "--edit option" do it "opens the generated gemspec in the user's text editor" do output = bundle "gem #{gem_name} --edit=echo" - gemspec_path = File.join(Dir.pwd, gem_name, "#{gem_name}.gemspec") + gemspec_path = File.join(bundled_app, gem_name, "#{gem_name}.gemspec") expect(output).to include("echo \"#{gemspec_path}\"") end end @@ -841,7 +831,7 @@ Usage: "bundle gem NAME [OPTIONS]" context "on conflicts with a previously created file", :readline do it "should fail gracefully" do - FileUtils.touch("conflict-foobar") + FileUtils.touch(bundled_app("conflict-foobar")) bundle "gem conflict-foobar" expect(err).to include("Errno::ENOTDIR") expect(exitstatus).to eql(32) if exitstatus @@ -850,7 +840,7 @@ Usage: "bundle gem NAME [OPTIONS]" context "on conflicts with a previously created directory", :readline do it "should succeed" do - FileUtils.mkdir_p("conflict-foobar/Gemfile") + FileUtils.mkdir_p(bundled_app("conflict-foobar/Gemfile")) bundle! "gem conflict-foobar" expect(out).to include("file_clash conflict-foobar/Gemfile"). and include "Initializing git repo in #{bundled_app("conflict-foobar")}" diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb index 1c267ab78f..15336137b6 100644 --- a/spec/commands/pristine_spec.rb +++ b/spec/commands/pristine_spec.rb @@ -28,6 +28,8 @@ RSpec.describe "bundle pristine", :ruby_repo do gemspec G + + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) end context "when sourced from RubyGems" do diff --git a/spec/commands/show_spec.rb b/spec/commands/show_spec.rb index 3a1fcc1a7a..7b329c8e7f 100644 --- a/spec/commands/show_spec.rb +++ b/spec/commands/show_spec.rb @@ -10,7 +10,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do end it "creates a Gemfile.lock if one did not exist" do - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) bundle! "show" @@ -18,7 +18,7 @@ RSpec.describe "bundle show", :bundler => "< 3" do end it "creates a Gemfile.lock when invoked with a gem name" do - FileUtils.rm("Gemfile.lock") + FileUtils.rm(bundled_app_lock) bundle! "show rails" @@ -143,13 +143,12 @@ RSpec.describe "bundle show", :bundler => "< 3" do context "in a fresh gem in a blank git repo" do before :each do build_git "foo", :path => lib_path("foo") - Dir.chdir lib_path("foo") - File.open("Gemfile", "w") {|f| f.puts "gemspec" } - sys_exec "rm -rf .git && git init" + File.open(lib_path("foo/Gemfile"), "w") {|f| f.puts "gemspec" } + sys_exec "rm -rf .git && git init", :dir => lib_path("foo") end it "does not output git errors" do - bundle :show + bundle :show, :dir => lib_path("foo") expect(err_without_deprecations).to be_empty end end diff --git a/spec/commands/update_spec.rb b/spec/commands/update_spec.rb index 8455d140fe..5a7d26353c 100644 --- a/spec/commands/update_spec.rb +++ b/spec/commands/update_spec.rb @@ -831,6 +831,7 @@ RSpec.describe "bundle update --bundler" do source "#{file_uri_for(gem_repo4)}" gem "rack" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) lockfile lockfile.sub(/(^\s*)#{Bundler::VERSION}($)/, '\11.0.0\2') FileUtils.rm_r gem_repo4 diff --git a/spec/install/deploy_spec.rb b/spec/install/deploy_spec.rb index ff32887c5e..5031bd9aa0 100644 --- a/spec/install/deploy_spec.rb +++ b/spec/install/deploy_spec.rb @@ -43,13 +43,12 @@ RSpec.describe "install with --deployment or --frozen" do it "still works if you are not in the app directory and specify --gemfile" do bundle! "install" - Dir.chdir tmp do - simulate_new_machine - bundle! :install, - forgotten_command_line_options(:gemfile => "#{tmp}/bundled_app/Gemfile", - :deployment => true, - :path => "vendor/bundle") - end + simulate_new_machine + bundle! :install, + forgotten_command_line_options(:gemfile => "#{tmp}/bundled_app/Gemfile", + :deployment => true, + :path => "vendor/bundle", + :dir => tmp) expect(the_bundle).to include_gems "rack 1.0" end diff --git a/spec/install/gemfile/eval_gemfile_spec.rb b/spec/install/gemfile/eval_gemfile_spec.rb index 7df94aaff5..69341250c3 100644 --- a/spec/install/gemfile/eval_gemfile_spec.rb +++ b/spec/install/gemfile/eval_gemfile_spec.rb @@ -28,8 +28,8 @@ RSpec.describe "bundle install with gemfile that uses eval_gemfile" do context "eval-ed Gemfile has relative-path gems" do before do - build_lib("a", :path => "gems/a") - create_file "nested/Gemfile-nested", <<-G + build_lib("a", :path => bundled_app("gems/a")) + create_file bundled_app("nested/Gemfile-nested"), <<-G gem "a", :path => "../gems/a" G diff --git a/spec/install/gemfile/gemspec_spec.rb b/spec/install/gemfile/gemspec_spec.rb index 2da53a5c13..bf1b84cf28 100644 --- a/spec/install/gemfile/gemspec_spec.rb +++ b/spec/install/gemfile/gemspec_spec.rb @@ -120,18 +120,16 @@ RSpec.describe "bundle install from an existing gemspec" do s.add_development_dependency "rake", "=12.3.2" end - Dir.chdir(tmp.join("foo")) do - bundle "install" - # This should really be able to rely on $stderr, but, it's not written - # right, so we can't. In fact, this is a bug negation test, and so it'll - # ghost pass in future, and will only catch a regression if the message - # doesn't change. Exit codes should be used correctly (they can be more - # than just 0 and 1). - output = bundle("install --deployment") - expect(output).not_to match(/You have added to the Gemfile/) - expect(output).not_to match(/You have deleted from the Gemfile/) - expect(output).not_to match(/install in deployment mode after changing/) - end + bundle "install", :dir => tmp.join("foo") + # This should really be able to rely on $stderr, but, it's not written + # right, so we can't. In fact, this is a bug negation test, and so it'll + # ghost pass in future, and will only catch a regression if the message + # doesn't change. Exit codes should be used correctly (they can be more + # than just 0 and 1). + output = bundle("install --deployment", :dir => tmp.join("foo")) + expect(output).not_to match(/You have added to the Gemfile/) + expect(output).not_to match(/You have deleted from the Gemfile/) + expect(output).not_to match(/install in deployment mode after changing/) end it "should match a lockfile without needing to re-resolve" do @@ -427,7 +425,7 @@ RSpec.describe "bundle install from an existing gemspec" do end end - build_lib "foo", :path => "." do |s| + build_lib "foo", :path => bundled_app do |s| if platform_specific_type == :runtime s.add_runtime_dependency dependency elsif platform_specific_type == :development diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb index 249ed48eab..067de1777d 100644 --- a/spec/install/gemfile/git_spec.rb +++ b/spec/install/gemfile/git_spec.rb @@ -57,22 +57,18 @@ RSpec.describe "bundle install with git sources" do it "does not update the git source implicitly" do update_git "foo" - in_app_root2 do - install_gemfile bundled_app2("Gemfile"), <<-G - git "#{lib_path("foo-1.0")}" do - gem 'foo' - end - G - end + install_gemfile bundled_app2("Gemfile"), <<-G, :dir => bundled_app2 + git "#{lib_path("foo-1.0")}" do + gem 'foo' + end + G - in_app_root do - run <<-RUBY - require 'foo' - puts "fail" if defined?(FOO_PREV_REF) - RUBY + run <<-RUBY + require 'foo' + puts "fail" if defined?(FOO_PREV_REF) + RUBY - expect(out).to be_empty - end + expect(out).to be_empty end it "sets up git gem executables on the path" do @@ -130,22 +126,18 @@ RSpec.describe "bundle install with git sources" do it "still works after moving the application directory" do bundle "install --path vendor/bundle" - Dir.chdir root FileUtils.mv bundled_app, tmp("bundled_app.bck") - Dir.chdir tmp("bundled_app.bck") - expect(the_bundle).to include_gems "foo 1.0" + expect(the_bundle).to include_gems "foo 1.0", :dir => tmp("bundled_app.bck") end it "can still install after moving the application directory" do bundle "install --path vendor/bundle" - Dir.chdir root FileUtils.mv bundled_app, tmp("bundled_app.bck") update_git "foo", "1.1", :path => lib_path("foo-1.0") - Dir.chdir tmp("bundled_app.bck") gemfile tmp("bundled_app.bck/Gemfile"), <<-G source "#{file_uri_for(gem_repo1)}" git "#{lib_path("foo-1.0")}" do @@ -155,9 +147,9 @@ RSpec.describe "bundle install with git sources" do gem "rack", "1.0" G - bundle "update foo" + bundle "update foo", :dir => tmp("bundled_app.bck") - expect(the_bundle).to include_gems "foo 1.1", "rack 1.0" + expect(the_bundle).to include_gems "foo 1.1", "rack 1.0", :dir => tmp("bundled_app.bck") end end @@ -224,9 +216,7 @@ RSpec.describe "bundle install with git sources" do s.write("lib/foo.rb", "raise 'FAIL'") end - Dir.chdir(lib_path("foo-1.0")) do - `git update-ref -m "Bundler Spec!" refs/bundler/1 master~1` - end + sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 master~1", :dir => lib_path("foo-1.0")) # want to ensure we don't fallback to HEAD update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s| @@ -260,9 +250,7 @@ RSpec.describe "bundle install with git sources" do s.write("lib/foo.rb", "raise 'FAIL'") end - Dir.chdir(lib_path("foo-1.0")) do - `git update-ref -m "Bundler Spec!" refs/bundler/1 master~1` - end + sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 master~1", :dir => lib_path("foo-1.0")) # want to ensure we don't fallback to HEAD update_git "foo", :path => lib_path("foo-1.0"), :branch => "rando" do |s| @@ -285,9 +273,7 @@ RSpec.describe "bundle install with git sources" do end it "does not download random non-head refs" do - Dir.chdir(lib_path("foo-1.0")) do - sys_exec!('git update-ref -m "Bundler Spec!" refs/bundler/1 master~1') - end + sys_exec("git update-ref -m \"Bundler Spec!\" refs/bundler/1 master~1", :dir => lib_path("foo-1.0")) bundle! "config set global_gem_cache true" @@ -300,9 +286,7 @@ RSpec.describe "bundle install with git sources" do # ensure we also git fetch after cloning bundle! :update, :all => true - Dir.chdir(Dir[home(".bundle/cache/git/foo-*")].first) do - sys_exec("git ls-remote .") - end + sys_exec("git ls-remote .", :dir => Dir[home(".bundle/cache/git/foo-*")].first) expect(out).not_to include("refs/bundler/1") end @@ -837,9 +821,7 @@ RSpec.describe "bundle install with git sources" do bundle "update", :all => true expect(the_bundle).to include_gems "forced 1.1" - Dir.chdir(lib_path("forced-1.0")) do - `git reset --hard HEAD^` - end + sys_exec("git reset --hard HEAD^", :dir => lib_path("forced-1.0")) bundle "update", :all => true expect(the_bundle).to include_gems "forced 1.0" @@ -850,10 +832,8 @@ RSpec.describe "bundle install with git sources" do build_git "has_submodule", "1.0" do |s| s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", :dir => lib_path("has_submodule-1.0") + sys_exec "git commit -m \"submodulator\"", :dir => lib_path("has_submodule-1.0") install_gemfile <<-G git "#{lib_path("has_submodule-1.0")}" do @@ -870,10 +850,8 @@ RSpec.describe "bundle install with git sources" do build_git "has_submodule", "1.0" do |s| s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", :dir => lib_path("has_submodule-1.0") + sys_exec "git commit -m \"submodulator\"", :dir => lib_path("has_submodule-1.0") install_gemfile <<-G git "#{lib_path("has_submodule-1.0")}", :submodules => true do @@ -1172,16 +1150,15 @@ RSpec.describe "bundle install with git sources" do end 2.times do |i| - Dir.chdir(git_reader.path) do - File.open("ext/foo.c", "w") do |file| - file.write <<-C - #include "ruby.h" - VALUE foo() { return INT2FIX(#{i}); } - void Init_foo() { rb_define_global_function("foo", &foo, 0); } - C - end - `git commit -m "commit for iteration #{i}" ext/foo.c` + File.open(git_reader.path.join("ext/foo.c"), "w") do |file| + file.write <<-C + #include "ruby.h" + VALUE foo() { return INT2FIX(#{i}); } + void Init_foo() { rb_define_global_function("foo", &foo, 0); } + C end + sys_exec("git commit -m \"commit for iteration #{i}\" ext/foo.c", :dir => git_reader.path) + git_commit_sha = git_reader.ref_for("HEAD") install_gemfile <<-G diff --git a/spec/install/gemfile/path_spec.rb b/spec/install/gemfile/path_spec.rb index e1ca389dc4..a733c02512 100644 --- a/spec/install/gemfile/path_spec.rb +++ b/spec/install/gemfile/path_spec.rb @@ -37,7 +37,7 @@ RSpec.describe "bundle install with explicit source paths" do it "supports relative paths" do build_lib "foo" - relative_path = lib_path("foo-1.0").relative_path_from(Pathname.new(Dir.pwd)) + relative_path = lib_path("foo-1.0").relative_path_from(bundled_app) install_gemfile <<-G gem 'foo', :path => "#{relative_path}" @@ -79,10 +79,7 @@ RSpec.describe "bundle install with explicit source paths" do gem 'foo', :path => "./foo-1.0" G - bundled_app("subdir").mkpath - Dir.chdir(bundled_app("subdir")) do - expect(the_bundle).to include_gems("foo 1.0") - end + expect(the_bundle).to include_gems("foo 1.0", :dir => bundled_app("subdir").mkpath) end it "sorts paths consistently on install and update when they start with ./" do @@ -121,12 +118,10 @@ RSpec.describe "bundle install with explicit source paths" do #{Bundler::VERSION} L - Dir.chdir(lib_path("demo")) do - bundle :install - expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) - bundle :update, :all => true - expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) - end + bundle :install, :dir => lib_path("demo") + expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) + bundle :update, :all => true, :dir => lib_path("demo") + expect(lib_path("demo/Gemfile.lock")).to have_lockfile(lockfile) end it "expands paths when comparing locked paths to Gemfile paths" do @@ -249,11 +244,9 @@ RSpec.describe "bundle install with explicit source paths" do File.open(lib_path("foo/Gemfile"), "w") {|f| f.puts gemfile } - Dir.chdir(lib_path("foo")) do - bundle "install" - expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" - end + bundle "install", :dir => lib_path("foo") + expect(the_bundle).to include_gems "foo 1.0", :dir => lib_path("foo") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("foo") end it "supports gemspec syntax with an alternative path" do @@ -275,19 +268,17 @@ RSpec.describe "bundle install with explicit source paths" do s.add_dependency "rack", ">= 1.0" end - Dir.chdir lib_path("foo") - - install_gemfile lib_path("foo/Gemfile"), <<-G + install_gemfile lib_path("foo/Gemfile"), <<-G, :dir => lib_path("foo") source "#{file_uri_for(gem_repo1)}" gemspec G build_gem "rack", "1.0.1", :to_system => true - bundle "install" + bundle "install", :dir => lib_path("foo") - expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "foo 1.0", :dir => lib_path("foo") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("foo") end it "doesn't automatically unlock dependencies when using the gemspec syntax and the gem has development dependencies" do @@ -296,19 +287,17 @@ RSpec.describe "bundle install with explicit source paths" do s.add_development_dependency "activesupport" end - Dir.chdir lib_path("foo") - - install_gemfile lib_path("foo/Gemfile"), <<-G + install_gemfile lib_path("foo/Gemfile"), <<-G, :dir => lib_path("foo") source "#{file_uri_for(gem_repo1)}" gemspec G build_gem "rack", "1.0.1", :to_system => true - bundle "install" + bundle "install", :dir => lib_path("foo") - expect(the_bundle).to include_gems "foo 1.0" - expect(the_bundle).to include_gems "rack 1.0" + expect(the_bundle).to include_gems "foo 1.0", :dir => lib_path("foo") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("foo") end it "raises if there are multiple gemspecs" do @@ -426,7 +415,7 @@ RSpec.describe "bundle install with explicit source paths" do remote: http://rubygems.org L - in_app_root { FileUtils.mkdir_p("vendor/bar") } + FileUtils.mkdir_p(bundled_app("vendor/bar")) install_gemfile <<-G gem "bar", "1.0.0", path: "vendor/bar", require: "bar/nyard" @@ -658,13 +647,11 @@ RSpec.describe "bundle install with explicit source paths" do G File.open(lib_path("private_lib/Gemfile"), "w") {|f| f.puts gemfile } - Dir.chdir(lib_path("private_lib")) do - bundle :install, :env => { "DEBUG" => "1" }, :artifice => "endpoint" - expect(out).to match(%r{^HTTP GET http://localgemserver\.test/api/v1/dependencies\?gems=rack$}) - expect(out).not_to match(/^HTTP GET.*private_lib/) - expect(the_bundle).to include_gems "private_lib 2.2" - expect(the_bundle).to include_gems "rack 1.0" - end + bundle :install, :env => { "DEBUG" => "1" }, :artifice => "endpoint", :dir => lib_path("private_lib") + expect(out).to match(%r{^HTTP GET http://localgemserver\.test/api/v1/dependencies\?gems=rack$}) + expect(out).not_to match(/^HTTP GET.*private_lib/) + expect(the_bundle).to include_gems "private_lib 2.2", :dir => lib_path("private_lib") + expect(the_bundle).to include_gems "rack 1.0", :dir => lib_path("private_lib") end end diff --git a/spec/install/gemfile/ruby_spec.rb b/spec/install/gemfile/ruby_spec.rb index d1e9fc7e05..d6ac4e3827 100644 --- a/spec/install/gemfile/ruby_spec.rb +++ b/spec/install/gemfile/ruby_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "ruby requirement" do def locked_ruby_version - Bundler::RubyVersion.from_string(Bundler::LockfileParser.new(lockfile).ruby_version) + Bundler::RubyVersion.from_string(Bundler::LockfileParser.new(File.read(bundled_app_lock)).ruby_version) end # As discovered by https://github.com/bundler/bundler/issues/4147, there is @@ -51,6 +51,7 @@ RSpec.describe "ruby requirement" do gem "rack" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) simulate_ruby_version "5100" @@ -72,6 +73,7 @@ RSpec.describe "ruby requirement" do gem "rack" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) simulate_ruby_version "5100" diff --git a/spec/install/gemfile/specific_platform_spec.rb b/spec/install/gemfile/specific_platform_spec.rb index 24b602589f..a1cc6b3551 100644 --- a/spec/install/gemfile/specific_platform_spec.rb +++ b/spec/install/gemfile/specific_platform_spec.rb @@ -58,6 +58,7 @@ RSpec.describe "bundle install with specific_platform enabled" do it "locks to both the specific darwin platform and ruby" do install_gemfile!(google_protobuf) + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(the_bundle.locked_gems.platforms).to eq([pl("ruby"), pl("x86_64-darwin-15")]) expect(the_bundle).to include_gem("google-protobuf 3.0.0.alpha.5.0.5.1 universal-darwin") expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[ @@ -78,6 +79,7 @@ RSpec.describe "bundle install with specific_platform enabled" do source "#{file_uri_for(gem_repo2)}" gem "facter" G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) expect(the_bundle.locked_gems.platforms).to eq([pl("ruby"), pl("x86_64-darwin-15")]) expect(the_bundle).to include_gems("facter 2.4.6 universal-darwin", "CFPropertyList 1.0") @@ -87,6 +89,10 @@ RSpec.describe "bundle install with specific_platform enabled" do end context "when adding a platform via lock --add_platform" do + before do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + end + it "adds the foreign platform" do install_gemfile!(google_protobuf) bundle! "lock --add-platform=#{x64_mingw}" diff --git a/spec/install/gemfile_spec.rb b/spec/install/gemfile_spec.rb index 76704b387d..e760f87ec1 100644 --- a/spec/install/gemfile_spec.rb +++ b/spec/install/gemfile_spec.rb @@ -44,12 +44,10 @@ RSpec.describe "bundle install" do end it "uses the gemfile while in a subdirectory" do bundled_app("subdir").mkpath - Dir.chdir(bundled_app("subdir")) do - bundle "install" - bundle "list" + bundle "install", :dir => bundled_app("subdir") + bundle "list", :dir => bundled_app("subdir") - expect(out).to include("rack (1.0.0)") - end + expect(out).to include("rack (1.0.0)") end end diff --git a/spec/install/gems/standalone_spec.rb b/spec/install/gems/standalone_spec.rb index 2745fe671c..c7c9d2a6a9 100644 --- a/spec/install/gems/standalone_spec.rb +++ b/spec/install/gems/standalone_spec.rb @@ -21,15 +21,12 @@ RSpec.shared_examples "bundle install --standalone" do testrb << "\nrequire \"#{k}\"" testrb << "\nputs #{k.upcase}" end - Dir.chdir(bundled_app) do - ruby testrb, :no_lib => true - end + ruby testrb, :no_lib => true expect(out).to eq(expected_gems.values.join("\n")) end it "works on a different system" do - Dir.chdir root FileUtils.mv(bundled_app, "#{bundled_app}2") testrb = String.new <<-RUBY @@ -41,9 +38,7 @@ RSpec.shared_examples "bundle install --standalone" do testrb << "\nrequire \"#{k}\"" testrb << "\nputs #{k.upcase}" end - in_app_root2 do - ruby testrb, :no_lib => true - end + ruby testrb, :no_lib => true, :dir => "#{bundled_app}2" expect(out).to eq(expected_gems.values.join("\n")) end @@ -55,7 +50,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{file_uri_for(gem_repo1)}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) end let(:expected_gems) do @@ -70,7 +65,7 @@ RSpec.shared_examples "bundle install --standalone" do describe "with gems with native extension", :ruby_repo do before do - install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) source "#{file_uri_for(gem_repo1)}" gem "very_simple_binary" G @@ -103,7 +98,7 @@ RSpec.shared_examples "bundle install --standalone" do end G end - install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + install_gemfile <<-G, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) gem "bar", :git => "#{lib_path("bar-1.0")}" G end @@ -123,7 +118,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rails" gem "devise", :git => "#{lib_path("devise-1.0")}" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) end let(:expected_gems) do @@ -150,7 +145,7 @@ RSpec.shared_examples "bundle install --standalone" do gem "rack-test" end G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) end let(:expected_gems) do @@ -163,88 +158,63 @@ RSpec.shared_examples "bundle install --standalone" do include_examples "common functionality" it "allows creating a standalone file with limited groups" do - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => "default") + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => "default", :dir => cwd) - Dir.chdir(bundled_app) do - load_error_ruby <<-RUBY, "spec", :no_lib => true - $:.unshift File.expand_path("bundle") - require "bundler/setup" + load_error_ruby <<-RUBY, "spec", :no_lib => true + $:.unshift File.expand_path("bundle") + require "bundler/setup" - require "actionpack" - puts ACTIONPACK - require "spec" - RUBY - end + require "actionpack" + puts ACTIONPACK + require "spec" + RUBY expect(out).to eq("2.3.2") expect(err).to eq("ZOMG LOAD ERROR") end it "allows --without to limit the groups used in a standalone" do - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle"), :without => "test").merge(:standalone => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle"), :without => "test").merge(:standalone => true, :dir => cwd) - Dir.chdir(bundled_app) do - load_error_ruby <<-RUBY, "spec", :no_lib => true - $:.unshift File.expand_path("bundle") - require "bundler/setup" + load_error_ruby <<-RUBY, "spec", :no_lib => true + $:.unshift File.expand_path("bundle") + require "bundler/setup" - require "actionpack" - puts ACTIONPACK - require "spec" - RUBY - end + require "actionpack" + puts ACTIONPACK + require "spec" + RUBY expect(out).to eq("2.3.2") expect(err).to eq("ZOMG LOAD ERROR") end - it "allows --path to change the location of the standalone bundle", :bundler => "< 3" do - bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true) + it "allows --path to change the location of the standalone bundle" do + bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true, :dir => cwd) - Dir.chdir(bundled_app) do - ruby <<-RUBY, :no_lib => true - $:.unshift File.expand_path("path/to/bundle") - require "bundler/setup" + ruby <<-RUBY, :no_lib => true + $:.unshift File.expand_path("path/to/bundle") + require "bundler/setup" - require "actionpack" - puts ACTIONPACK - RUBY - end + require "actionpack" + puts ACTIONPACK + RUBY expect(out).to eq("2.3.2") end - it "allows --path to change the location of the standalone bundle", :bundler => "3" do - bundle! "install", forgotten_command_line_options(:path => "path/to/bundle").merge(:standalone => true) - path = File.expand_path("path/to/bundle") - - Dir.chdir(bundled_app) do - ruby <<-RUBY, :no_lib => true - $:.unshift File.expand_path(#{path.dump}) - require "bundler/setup" - - require "actionpack" - puts ACTIONPACK - RUBY - end + it "allows remembered --without to limit the groups used in a standalone" do + bundle! :install, forgotten_command_line_options(:without => "test").merge(:dir => cwd) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :dir => cwd) - expect(out).to eq("2.3.2") - end + load_error_ruby <<-RUBY, "spec", :no_lib => true + $:.unshift File.expand_path("bundle") + require "bundler/setup" - it "allows remembered --without to limit the groups used in a standalone" do - bundle! :install, forgotten_command_line_options(:without => "test") - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true) - - Dir.chdir(bundled_app) do - load_error_ruby <<-RUBY, "spec", :no_lib => true - $:.unshift File.expand_path("bundle") - require "bundler/setup" - - require "actionpack" - puts ACTIONPACK - require "spec" - RUBY - end + require "actionpack" + puts ACTIONPACK + require "spec" + RUBY expect(out).to eq("2.3.2") expect(err).to eq("ZOMG LOAD ERROR") @@ -262,7 +232,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{source_uri}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :artifice => "endpoint") + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :artifice => "endpoint", :dir => cwd) end let(:expected_gems) do @@ -282,7 +252,7 @@ RSpec.shared_examples "bundle install --standalone" do source "#{file_uri_for(gem_repo1)}" gem "rails" G - bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :binstubs => true) + bundle! :install, forgotten_command_line_options(:path => bundled_app("bundle")).merge(:standalone => true, :binstubs => true, :dir => cwd) end let(:expected_gems) do @@ -297,19 +267,15 @@ RSpec.shared_examples "bundle install --standalone" do it "creates stubs that use the standalone load path" do skip "exec format error" if Gem.win_platform? - Dir.chdir(bundled_app) do - expect(`bin/rails -v`.chomp).to eql "2.3.2" - end + expect(sys_exec("bin/rails -v").chomp).to eql "2.3.2" end it "creates stubs that can be executed from anywhere" do skip "exec format error" if Gem.win_platform? require "tmpdir" - Dir.chdir(Dir.tmpdir) do - sys_exec!(%(#{bundled_app("bin/rails")} -v)) - expect(out).to eq("2.3.2") - end + sys_exec!(%(#{bundled_app("bin/rails")} -v), :dir => Dir.tmpdir) + expect(out).to eq("2.3.2") end it "creates stubs that can be symlinked" do @@ -332,13 +298,13 @@ RSpec.shared_examples "bundle install --standalone" do end RSpec.describe "bundle install --standalone" do + let(:cwd) { bundled_app } + include_examples("bundle install --standalone") end RSpec.describe "bundle install --standalone run in a subdirectory" do - before do - Dir.chdir(bundled_app("bob").tap(&:mkpath)) - end + let(:cwd) { bundled_app("bob").tap(&:mkpath) } include_examples("bundle install --standalone") end diff --git a/spec/install/global_cache_spec.rb b/spec/install/global_cache_spec.rb index 253079a1eb..15987bdf53 100644 --- a/spec/install/global_cache_spec.rb +++ b/spec/install/global_cache_spec.rb @@ -169,28 +169,26 @@ RSpec.describe "global gem caching" do expect(source_global_cache("rack-1.0.0.gem")).to exist expect(source_global_cache("activesupport-2.3.5.gem")).to exist - in_app_root2 do - create_file bundled_app2("gems.rb"), <<-G - source "#{source}" - gem "activesupport" - G - - # Neither gem is installed and both are in the global cache - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(the_bundle).not_to include_gems "activesupport 2.3.5" - expect(source_global_cache("rack-1.0.0.gem")).to exist - expect(source_global_cache("activesupport-2.3.5.gem")).to exist - - # Install using the global cache instead of by downloading the .gem - # from the server - bundle! :install, :artifice => "compact_index_no_gem" - - # activesupport is installed and both are in the global cache - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(the_bundle).to include_gems "activesupport 2.3.5" - expect(source_global_cache("rack-1.0.0.gem")).to exist - expect(source_global_cache("activesupport-2.3.5.gem")).to exist - end + create_file bundled_app2("gems.rb"), <<-G + source "#{source}" + gem "activesupport" + G + + # Neither gem is installed and both are in the global cache + expect(the_bundle).not_to include_gems "rack 1.0.0", :dir => bundled_app2 + expect(the_bundle).not_to include_gems "activesupport 2.3.5", :dir => bundled_app2 + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist + + # Install using the global cache instead of by downloading the .gem + # from the server + bundle! :install, :artifice => "compact_index_no_gem", :dir => bundled_app2 + + # activesupport is installed and both are in the global cache + expect(the_bundle).not_to include_gems "rack 1.0.0", :dir => bundled_app2 + expect(the_bundle).to include_gems "activesupport 2.3.5", :dir => bundled_app2 + expect(source_global_cache("rack-1.0.0.gem")).to exist + expect(source_global_cache("activesupport-2.3.5.gem")).to exist end end end diff --git a/spec/install/path_spec.rb b/spec/install/path_spec.rb index 89a441d0f4..bed28ed3e2 100644 --- a/spec/install/path_spec.rb +++ b/spec/install/path_spec.rb @@ -22,10 +22,8 @@ RSpec.describe "bundle install" do dir = bundled_app("bun++dle") dir.mkpath - Dir.chdir(dir) do - bundle! :install, forgotten_command_line_options(:path => dir.join("vendor/bundle")) - expect(out).to include("installed into `./vendor/bundle`") - end + bundle! :install, forgotten_command_line_options(:path => dir.join("vendor/bundle")).merge(:dir => dir) + expect(out).to include("installed into `./vendor/bundle`") dir.rmtree end @@ -54,30 +52,24 @@ RSpec.describe "bundle install" do before { bundle! "config set path_relative_to_cwd true" } it "installs the bundle relatively to current working directory", :bundler => "< 3" do - Dir.chdir(bundled_app.parent) do - bundle! "install --gemfile='#{bundled_app}/Gemfile' --path vendor/bundle" - expect(out).to include("installed into `./vendor/bundle`") - expect(bundled_app("../vendor/bundle")).to be_directory - end + bundle! "install --gemfile='#{bundled_app}/Gemfile' --path vendor/bundle", :dir => bundled_app.parent + expect(out).to include("installed into `./vendor/bundle`") + expect(bundled_app("../vendor/bundle")).to be_directory expect(the_bundle).to include_gems "rack 1.0.0" end it "installs the standalone bundle relative to the cwd" do - Dir.chdir(bundled_app.parent) do - bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true - expect(out).to include("installed into `./bundled_app/bundle`") - expect(bundled_app("bundle")).to be_directory - expect(bundled_app("bundle/ruby")).to be_directory - end + bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true, :dir => bundled_app.parent + expect(out).to include("installed into `./bundled_app/bundle`") + expect(bundled_app("bundle")).to be_directory + expect(bundled_app("bundle/ruby")).to be_directory bundle! "config unset path" - Dir.chdir(bundled_app("subdir").tap(&:mkpath)) do - bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true - expect(out).to include("installed into `../bundle`") - expect(bundled_app("bundle")).to be_directory - expect(bundled_app("bundle/ruby")).to be_directory - end + bundle! :install, :gemfile => bundled_app_gemfile, :standalone => true, :dir => bundled_app("subdir").tap(&:mkpath) + expect(out).to include("installed into `../bundle`") + expect(bundled_app("bundle")).to be_directory + expect(bundled_app("bundle/ruby")).to be_directory end end end @@ -137,9 +129,7 @@ RSpec.describe "bundle install" do set_bundle_path(type, "vendor") FileUtils.mkdir_p bundled_app("lol") - Dir.chdir(bundled_app("lol")) do - bundle! :install - end + bundle! :install, :dir => bundled_app("lol") expect(bundled_app("vendor", Bundler.ruby_scope, "gems/rack-1.0.0")).to be_directory expect(the_bundle).to include_gems "rack 1.0.0" @@ -203,9 +193,7 @@ RSpec.describe "bundle install" do describe "to a file" do before do - in_app_root do - FileUtils.touch "bundle" - end + FileUtils.touch bundled_app("bundle") end it "reports the file exists" do diff --git a/spec/plugins/install_spec.rb b/spec/plugins/install_spec.rb index 669ed09fb5..663363ca21 100644 --- a/spec/plugins/install_spec.rb +++ b/spec/plugins/install_spec.rb @@ -155,6 +155,10 @@ RSpec.describe "bundler plugin install" do end context "Gemfile eval" do + before do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) + end + it "installs plugins listed in gemfile" do gemfile <<-G source '#{file_uri_for(gem_repo2)}' @@ -245,6 +249,7 @@ RSpec.describe "bundler plugin install" do describe "local plugin" do it "is installed when inside an app" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) gemfile "" bundle "plugin install foo --source #{file_uri_for(gem_repo2)}" @@ -287,21 +292,16 @@ RSpec.describe "bundler plugin install" do end # outside the app - Dir.chdir tmp - bundle "plugin install fubar --source #{file_uri_for(gem_repo2)}" + bundle "plugin install fubar --source #{file_uri_for(gem_repo2)}", :dir => tmp end it "inside the app takes precedence over global plugin" do - Dir.chdir bundled_app - bundle "shout" expect(out).to eq("local_one") end it "outside the app global plugin is used" do - Dir.chdir tmp - - bundle "shout" + bundle "shout", :dir => tmp expect(out).to eq("global_one") end end diff --git a/spec/plugins/source/example_spec.rb b/spec/plugins/source/example_spec.rb index f2151a5a73..aac506dc9a 100644 --- a/spec/plugins/source/example_spec.rb +++ b/spec/plugins/source/example_spec.rb @@ -215,6 +215,8 @@ RSpec.describe "real source plugins" do build_repo2 do build_plugin "bundler-source-gitp" do |s| s.write "plugins.rb", <<-RUBY + require "open3" + class SPlugin < Bundler::Plugin::API source "gitp" @@ -254,9 +256,7 @@ RSpec.describe "real source plugins" do mkdir_p(install_path.dirname) rm_rf(install_path) `git clone --no-checkout --quiet "\#{cache_path}" "\#{install_path}"` - Dir.chdir install_path do - `git reset --hard \#{revision}` - end + Open3.capture2e("git reset --hard \#{revision}", :chdir => install_path) spec_path = install_path.join("\#{spec.full_name}.gemspec") spec_path.open("wb") {|f| f.write spec.to_ruby } @@ -310,9 +310,8 @@ RSpec.describe "real source plugins" do cache_repo end - Dir.chdir cache_path do - `git rev-parse --verify \#{@ref}`.strip - end + output, _status = Open3.capture2e("git rev-parse --verify \#{@ref}", :chdir => cache_path) + output.strip end def base_name diff --git a/spec/plugins/source_spec.rb b/spec/plugins/source_spec.rb index c8deee96b1..14643e5c81 100644 --- a/spec/plugins/source_spec.rb +++ b/spec/plugins/source_spec.rb @@ -21,6 +21,7 @@ RSpec.describe "bundler source plugin" do end G + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) plugin_should_be_installed("bundler-source-psource") end @@ -75,6 +76,7 @@ RSpec.describe "bundler source plugin" do end it "installs the explicit one" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) plugin_should_be_installed("another-psource") end @@ -100,6 +102,7 @@ RSpec.describe "bundler source plugin" do end it "installs the default one" do + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) plugin_should_be_installed("bundler-source-psource") end end diff --git a/spec/quality_es_spec.rb b/spec/quality_es_spec.rb index c1cb028ee1..ab2e2983aa 100644 --- a/spec/quality_es_spec.rb +++ b/spec/quality_es_spec.rb @@ -40,12 +40,10 @@ RSpec.describe "La biblioteca si misma" do it "mantiene la calidad de lenguaje de la documentación" do included = /ronn/ error_messages = [] - in_repo_root do - man_tracked_files.split("\x0").each do |filename| - next unless filename =~ included - error_messages << check_for_expendable_words(filename) - error_messages << check_for_specific_pronouns(filename) - end + man_tracked_files.split("\x0").each do |filename| + next unless filename =~ included + error_messages << check_for_expendable_words(filename) + error_messages << check_for_specific_pronouns(filename) end expect(error_messages.compact).to be_well_formed end @@ -53,12 +51,10 @@ RSpec.describe "La biblioteca si misma" do it "mantiene la calidad de lenguaje de oraciones usadas en el código fuente" do error_messages = [] exempt = /vendor/ - in_repo_root do - lib_tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_expendable_words(filename) - error_messages << check_for_specific_pronouns(filename) - end + lib_tracked_files.split("\x0").each do |filename| + next if filename =~ exempt + error_messages << check_for_expendable_words(filename) + error_messages << check_for_specific_pronouns(filename) end expect(error_messages.compact).to be_well_formed end diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index 95ab31dae0..e94addae5e 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -107,12 +107,10 @@ RSpec.describe "The library itself" do it "has no malformed whitespace" do exempt = /\.gitmodules|fixtures|vendor|LICENSE|vcr_cassettes|rbreadline\.diff|\.txt$/ error_messages = [] - in_repo_root do - tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_tab_characters(filename) - error_messages << check_for_extra_spaces(filename) - end + tracked_files.split("\x0").each do |filename| + next if filename =~ exempt + error_messages << check_for_tab_characters(filename) + error_messages << check_for_extra_spaces(filename) end expect(error_messages.compact).to be_well_formed end @@ -120,11 +118,9 @@ RSpec.describe "The library itself" do it "has no estraneous quotes" do exempt = /vendor|vcr_cassettes|LICENSE|rbreadline\.diff/ error_messages = [] - in_repo_root do - tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_straneous_quotes(filename) - end + tracked_files.split("\x0").each do |filename| + next if filename =~ exempt + error_messages << check_for_straneous_quotes(filename) end expect(error_messages.compact).to be_well_formed end @@ -132,11 +128,9 @@ RSpec.describe "The library itself" do it "does not include any leftover debugging or development mechanisms" do exempt = %r{quality_spec.rb|support/helpers|vcr_cassettes|\.md|\.ronn|\.txt|\.5|\.1} error_messages = [] - in_repo_root do - tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_debugging_mechanisms(filename) - end + tracked_files.split("\x0").each do |filename| + next if filename =~ exempt + error_messages << check_for_debugging_mechanisms(filename) end expect(error_messages.compact).to be_well_formed end @@ -144,11 +138,9 @@ RSpec.describe "The library itself" do it "does not include any unresolved merge conflicts" do error_messages = [] exempt = %r{lock/lockfile_spec|quality_spec|vcr_cassettes|\.ronn|lockfile_parser\.rb} - in_repo_root do - tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_git_merge_conflicts(filename) - end + tracked_files.split("\x0").each do |filename| + next if filename =~ exempt + error_messages << check_for_git_merge_conflicts(filename) end expect(error_messages.compact).to be_well_formed end @@ -156,12 +148,10 @@ RSpec.describe "The library itself" do it "maintains language quality of the documentation" do included = /ronn/ error_messages = [] - in_repo_root do - man_tracked_files.split("\x0").each do |filename| - next unless filename =~ included - error_messages << check_for_expendable_words(filename) - error_messages << check_for_specific_pronouns(filename) - end + man_tracked_files.split("\x0").each do |filename| + next unless filename =~ included + error_messages << check_for_expendable_words(filename) + error_messages << check_for_specific_pronouns(filename) end expect(error_messages.compact).to be_well_formed end @@ -169,12 +159,10 @@ RSpec.describe "The library itself" do it "maintains language quality of sentences used in source code" do error_messages = [] exempt = /vendor|vcr_cassettes/ - in_repo_root do - lib_tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - error_messages << check_for_expendable_words(filename) - error_messages << check_for_specific_pronouns(filename) - end + lib_tracked_files.split("\x0").each do |filename| + next if filename =~ exempt + error_messages << check_for_expendable_words(filename) + error_messages << check_for_specific_pronouns(filename) end expect(error_messages.compact).to be_well_formed end @@ -197,15 +185,13 @@ RSpec.describe "The library itself" do Bundler::Settings::NUMBER_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::NUMBER_KEYS" } Bundler::Settings::ARRAY_KEYS.each {|k| all_settings[k] << "in Bundler::Settings::ARRAY_KEYS" } - in_repo_root do - key_pattern = /([a-z\._-]+)/i - lib_tracked_files.split("\x0").each do |filename| - each_line(filename) do |line, number| - line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" } - end + key_pattern = /([a-z\._-]+)/i + lib_tracked_files.split("\x0").each do |filename| + each_line(filename) do |line, number| + line.scan(/Bundler\.settings\[:#{key_pattern}\]/).flatten.each {|s| all_settings[s] << "referenced at `#{filename}:#{number.succ}`" } end - documented_settings = File.read("man/bundle-config.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten end + documented_settings = File.read("man/bundle-config.ronn")[/LIST OF AVAILABLE KEYS.*/m].scan(/^\* `#{key_pattern}`/).flatten documented_settings.each do |s| all_settings.delete(s) @@ -231,54 +217,48 @@ RSpec.describe "The library itself" do end it "ships the correct set of files" do - in_repo_root do - git_list = shipped_files.split("\x0") + git_list = shipped_files.split("\x0") - gem_list = Gem::Specification.load(gemspec.to_s).files + gem_list = Gem::Specification.load(gemspec.to_s).files - expect(git_list.to_set).to eq(gem_list.to_set) - end + expect(git_list.to_set).to eq(gem_list.to_set) end it "does not contain any warnings" do - in_repo_root do - exclusions = %w[ - lib/bundler/capistrano.rb - lib/bundler/deployment.rb - lib/bundler/gem_tasks.rb - lib/bundler/vlad.rb - lib/bundler/templates/gems.rb - ] - files_to_require = lib_tracked_files.split("\x0").grep(/\.rb$/) - exclusions - files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") } - files_to_require.map! {|f| File.expand_path("../#{f}", __dir__) } - sys_exec!("ruby -w") do |input, _, _| - files_to_require.each do |f| - input.puts "require '#{f}'" - end + exclusions = %w[ + lib/bundler/capistrano.rb + lib/bundler/deployment.rb + lib/bundler/gem_tasks.rb + lib/bundler/vlad.rb + lib/bundler/templates/gems.rb + ] + files_to_require = lib_tracked_files.split("\x0").grep(/\.rb$/) - exclusions + files_to_require.reject! {|f| f.start_with?("lib/bundler/vendor") } + files_to_require.map! {|f| File.expand_path("../#{f}", __dir__) } + sys_exec!("ruby -w") do |input, _, _| + files_to_require.each do |f| + input.puts "require '#{f}'" end + end - warnings = last_command.stdboth.split("\n") - # ignore warnings around deprecated Object#=~ method in RubyGems - warnings.reject! {|w| w =~ %r{rubygems\/version.rb.*deprecated\ Object#=~} } + warnings = last_command.stdboth.split("\n") + # ignore warnings around deprecated Object#=~ method in RubyGems + warnings.reject! {|w| w =~ %r{rubygems\/version.rb.*deprecated\ Object#=~} } - expect(warnings).to be_well_formed - end + expect(warnings).to be_well_formed end it "does not use require internally, but require_relative" do - in_repo_root do - exempt = %r{templates/|vendor/} - all_bad_requires = [] - lib_tracked_files.split("\x0").each do |filename| - next if filename =~ exempt - each_line(filename) do |line, number| - line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" } - end + exempt = %r{templates/|vendor/} + all_bad_requires = [] + lib_tracked_files.split("\x0").each do |filename| + next if filename =~ exempt + each_line(filename) do |line, number| + line.scan(/^ *require "bundler/).each { all_bad_requires << "#{filename}:#{number.succ}" } end - - expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}" end + + expect(all_bad_requires).to be_empty, "#{all_bad_requires.size} internal requires that should use `require_relative`: #{all_bad_requires}" end private diff --git a/spec/runtime/executable_spec.rb b/spec/runtime/executable_spec.rb index 96197a52b8..e420594f52 100644 --- a/spec/runtime/executable_spec.rb +++ b/spec/runtime/executable_spec.rb @@ -44,14 +44,14 @@ RSpec.describe "Running bin/* commands" do it "uses the default ruby install name when shebang is not specified" do bundle! "binstubs rack" - expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env #{RbConfig::CONFIG["ruby_install_name"]}\n") + expect(File.open(bundled_app("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 skip "not created with custom name :/" if Gem.win_platform? bundle! "binstubs rack", :shebang => "ruby-foo" - expect(File.open("bin/rackup").gets).to eq("#!/usr/bin/env ruby-foo\n") + expect(File.open(bundled_app("bin/rackup")).gets).to eq("#!/usr/bin/env ruby-foo\n") end it "runs the bundled command when out of the bundle" do @@ -63,10 +63,8 @@ RSpec.describe "Running bin/* commands" do s.executables = "rackup" end - Dir.chdir(tmp) do - gembin "rackup" - expect(out).to eq("1.0.0") - end + gembin "rackup", :dir => tmp + expect(out).to eq("1.0.0") end it "works with gems in path" do diff --git a/spec/runtime/gem_tasks_spec.rb b/spec/runtime/gem_tasks_spec.rb index 91ea5cf189..4fe9d43e73 100644 --- a/spec/runtime/gem_tasks_spec.rb +++ b/spec/runtime/gem_tasks_spec.rb @@ -59,15 +59,12 @@ RSpec.describe "require 'bundler/gem_tasks'" do context "rake build when path has spaces" do before do - Dir.chdir(root) spaced_bundled_app = tmp.join("bundled app") FileUtils.mv bundled_app, spaced_bundled_app - Dir.chdir(spaced_bundled_app) + bundle! "exec rake build", :dir => spaced_bundled_app end it "still runs successfully" do - bundle! "exec rake build" - expect(err).to be_empty end end diff --git a/spec/runtime/inline_spec.rb b/spec/runtime/inline_spec.rb index def258ec66..fb6c6e90ad 100644 --- a/spec/runtime/inline_spec.rb +++ b/spec/runtime/inline_spec.rb @@ -233,16 +233,14 @@ RSpec.describe "bundler/inline#gemfile" do 1.13.6 G - in_app_root do - script <<-RUBY - gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" - end + script <<-RUBY + gemfile do + source "#{file_uri_for(gem_repo1)}" + gem "rack" + end - puts RACK - RUBY - end + puts RACK + RUBY expect(err).to be_empty expect(exitstatus).to be_zero if exitstatus @@ -265,16 +263,14 @@ RSpec.describe "bundler/inline#gemfile" do it "installs inline gems when BUNDLE_GEMFILE is set to an empty string" do ENV["BUNDLE_GEMFILE"] = "" - in_app_root do - script <<-RUBY - gemfile do - source "#{file_uri_for(gem_repo1)}" - gem "rack" - end + script <<-RUBY + gemfile do + source "#{file_uri_for(gem_repo1)}" + gem "rack" + end - puts RACK - RUBY - end + puts RACK + RUBY expect(err).to be_empty expect(exitstatus).to be_zero if exitstatus diff --git a/spec/runtime/load_spec.rb b/spec/runtime/load_spec.rb index 7de67e247c..a406fbaf49 100644 --- a/spec/runtime/load_spec.rb +++ b/spec/runtime/load_spec.rb @@ -7,6 +7,7 @@ RSpec.describe "Bundler.load" do source "#{file_uri_for(gem_repo1)}" gem "rack" G + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) end it "provides a list of the env dependencies" do @@ -32,6 +33,7 @@ RSpec.describe "Bundler.load" do gem "rack" G bundle! :install + allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app) end it "provides a list of the env dependencies" do @@ -101,7 +103,7 @@ RSpec.describe "Bundler.load" do source "#{file_uri_for(gem_repo1)}" gem "activerecord" G - + allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile) Bundler.load.specs.each do |spec| expect(spec.to_yaml).not_to match(/^\s+source:/) expect(spec.to_yaml).not_to match(/^\s+groups:/) diff --git a/spec/runtime/platform_spec.rb b/spec/runtime/platform_spec.rb index f7e93eacf1..ad9c56d14e 100644 --- a/spec/runtime/platform_spec.rb +++ b/spec/runtime/platform_spec.rb @@ -117,7 +117,7 @@ RSpec.describe "Bundler.setup with multi platform stuff" do end it "allows specifying only-ruby-platform on windows with gemspec dependency" do - build_lib("foo", "1.0", :path => ".") do |s| + build_lib("foo", "1.0", :path => bundled_app) do |s| s.add_dependency "rack" end diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index 8c2c55ac5b..f94efbea6a 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -489,15 +489,16 @@ RSpec.describe "Bundler.setup" do it "does not randomly change the path when specifying --path and the bundle directory becomes read only" do bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") - with_read_only("**/*") do + with_read_only("#{bundled_app}/**/*") do expect(the_bundle).to include_gems "rack 1.0.0" end end it "finds git gem when default bundle path becomes read only" do + bundle "config set --local path .bundle" bundle "install" - with_read_only("#{Bundler.bundle_path}/**/*") do + with_read_only("#{bundled_app(".bundle")}/**/*") do expect(the_bundle).to include_gems "rack 1.0.0" end end @@ -865,11 +866,9 @@ end gem 'foo', '1.2.3', :path => 'vendor/foo' G - Dir.chdir(bundled_app.parent) do - run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s } - require 'foo' - R - end + run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s }, :dir => bundled_app.parent + require 'foo' + R expect(err).to be_empty end @@ -889,11 +888,9 @@ end bundle :install - Dir.chdir(bundled_app.parent) do - run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s } - require 'foo' - R - end + run <<-R, :env => { "BUNDLE_GEMFILE" => bundled_app_gemfile.to_s }, :dir => bundled_app.parent + require 'foo' + R expect(err).to be_empty end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2b975cf5fc..0074cb81d8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -58,7 +58,6 @@ RSpec.configure do |config| config.bisect_runner = :shell - original_wd = Dir.pwd original_env = ENV.to_hash config.expect_with :rspec do |c| @@ -105,8 +104,6 @@ RSpec.configure do |config| reset! system_gems [] - Dir.chdir(bundled_app) - @command_executions = [] Bundler.ui.silence { example.run } @@ -119,8 +116,6 @@ RSpec.configure do |config| message end end - - Dir.chdir(original_wd) end config.after :suite do diff --git a/spec/support/builders.rb b/spec/support/builders.rb index 021057cc3c..467a9f2ccd 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -394,7 +394,7 @@ module Spec @_build_repo = File.basename(path) yield with_gem_path_as Path.base_system_gems do - Dir.chdir(path) { gem_command! :generate_index } + gem_command! :generate_index, :dir => path end ensure @_build_path = nil @@ -551,6 +551,11 @@ module Spec @files = {} end + def capture(cmd, dir) + output, _status = Open3.capture2e(cmd, :chdir => dir) + output + end + def method_missing(*args, &blk) @spec.send(*args, &blk) end @@ -660,14 +665,12 @@ module Spec path = options[:path] || _default_path source = options[:source] || "git@#{path}" super(options.merge(:path => path, :source => source)) - Dir.chdir(path) do - `git init` - `git add *` - `git config user.email "lol@wut.com"` - `git config user.name "lolwut"` - `git config commit.gpgsign false` - `git commit -m "OMG INITIAL COMMIT"` - end + capture("git init", path) + capture("git add *", path) + capture("git config user.email \"lol@wut.com\"", path) + capture("git config user.name \"lolwut\"", path) + capture("git config commit.gpgsign false", path) + capture("git commit -m \"OMG INITIAL COMMIT\"", path) end end @@ -675,15 +678,14 @@ module Spec def _build(options) path = options[:path] || _default_path super(options.merge(:path => path)) - Dir.chdir(path) do - `git init --bare` - end + capture("git init --bare", path) end end class GitUpdater < LibBuilder - def silently(str) - `#{str} 2>#{Bundler::NULL}` + def silently(str, dir) + output, _error, _status = Open3.capture3(str, :chdir => dir) + output end def _build(options) @@ -691,34 +693,32 @@ module Spec update_gemspec = options[:gemspec] || false source = options[:source] || "git@#{libpath}" - Dir.chdir(libpath) do - silently "git checkout master" + silently "git checkout master", libpath - if branch = options[:branch] - raise "You can't specify `master` as the branch" if branch == "master" - escaped_branch = Shellwords.shellescape(branch) + if branch = options[:branch] + raise "You can't specify `master` as the branch" if branch == "master" + escaped_branch = Shellwords.shellescape(branch) - if `git branch | grep #{escaped_branch}`.empty? - silently("git branch #{escaped_branch}") - end - - silently("git checkout #{escaped_branch}") - elsif tag = options[:tag] - `git tag #{Shellwords.shellescape(tag)}` - elsif options[:remote] - silently("git remote add origin #{options[:remote]}") - elsif options[:push] - silently("git push origin #{options[:push]}") + if capture("git branch | grep #{escaped_branch}", libpath).empty? + silently("git branch #{escaped_branch}", libpath) end - current_ref = `git rev-parse HEAD`.strip - _default_files.keys.each do |path| - _default_files[path] += "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'" - end - super(options.merge(:path => libpath, :gemspec => update_gemspec, :source => source)) - `git add *` - `git commit -m "BUMP"` + silently("git checkout #{escaped_branch}", libpath) + elsif tag = options[:tag] + capture("git tag #{Shellwords.shellescape(tag)}", libpath) + elsif options[:remote] + silently("git remote add origin #{options[:remote]}", libpath) + elsif options[:push] + silently("git push origin #{options[:push]}", libpath) + end + + current_ref = silently("git rev-parse HEAD", libpath).strip + _default_files.keys.each do |path| + _default_files[path] += "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'" end + super(options.merge(:path => libpath, :gemspec => update_gemspec, :source => source)) + capture("git add *", libpath) + capture("git commit -m \"BUMP\"", libpath) end end @@ -739,7 +739,7 @@ module Spec def git(cmd) Bundler::SharedHelpers.with_clean_git_env do - Dir.chdir(@path) { `git #{cmd}`.strip } + Open3.capture2e("git #{cmd}", :chdir => path)[0].strip end end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 4180a2f1ae..dde8daaf6f 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -114,6 +114,8 @@ module Spec load_path << spec_dir load_path_str = "-I#{load_path.join(File::PATH_SEPARATOR)}" + dir = options.delete(:dir) || bundled_app + args = options.map do |k, v| case v when nil @@ -128,7 +130,7 @@ module Spec end.join cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" - sys_exec(cmd, { :env => env }, &block) + sys_exec(cmd, { :env => env, :dir => dir }, &block) end bang :bundle @@ -170,17 +172,17 @@ module Spec R end - def gembin(cmd) + def gembin(cmd, options = {}) old = ENV["RUBYOPT"] ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{lib_dir}" cmd = bundled_app("bin/#{cmd}") unless cmd.to_s.include?("/") - sys_exec(cmd.to_s) + sys_exec(cmd.to_s, options) ensure ENV["RUBYOPT"] = old end - def gem_command(command) - sys_exec("#{Path.gem_bin} #{command}") + def gem_command(command, options = {}) + sys_exec("#{Path.gem_bin} #{command}", options) end bang :gem_command @@ -190,11 +192,12 @@ module Spec def sys_exec(cmd, options = {}) env = options[:env] || {} - command_execution = CommandExecution.new(cmd.to_s, Dir.pwd) + dir = options[:dir] || bundled_app + command_execution = CommandExecution.new(cmd.to_s, dir) require "open3" require "shellwords" - Open3.popen3(env, *cmd.shellsplit) do |stdin, stdout, stderr, wait_thr| + Open3.popen3(env, *cmd.shellsplit, :chdir => dir) do |stdin, stdout, stderr, wait_thr| yield stdin, stdout, wait_thr if block_given? stdin.close @@ -238,7 +241,7 @@ module Spec contents = args.shift if contents.nil? - File.open("Gemfile", "r", &:read) + File.open(bundled_app_gemfile, "r", &:read) else create_file("Gemfile", contents, *args) end @@ -248,7 +251,7 @@ module Spec contents = args.shift if contents.nil? - File.open("Gemfile.lock", "r", &:read) + File.open(bundled_app_lock, "r", &:read) else create_file("Gemfile.lock", contents, *args) end @@ -297,7 +300,7 @@ module Spec def with_built_bundler with_root_gemspec do |gemspec| - in_repo_root { gem_command! "build #{gemspec}" } + gem_command! "build #{gemspec}", :dir => root end bundler_path = root + "bundler-#{Bundler::VERSION}.gem" @@ -357,7 +360,8 @@ module Spec opts = gems.last.is_a?(Hash) ? gems.last : {} path = opts.fetch(:path, system_gem_path) if path == :bundle_path - path = ruby!(<<-RUBY) + bundle_dir = opts.fetch(:bundle_dir, bundled_app) + path = ruby!(<<-RUBY, :dir => bundle_dir) require "bundler" begin puts Bundler.bundle_path @@ -494,7 +498,7 @@ module Spec end def revision_for(path) - Dir.chdir(path) { `git rev-parse HEAD`.strip } + sys_exec("git rev-parse HEAD", :dir => path).strip end def with_read_only(pattern) diff --git a/spec/support/path.rb b/spec/support/path.rb index a645aa6ffd..25206c9832 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -48,13 +48,13 @@ module Spec def lib_tracked_files skip "not in git working directory" unless git_root_dir? - @lib_tracked_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb` : `git ls-files -z -- lib` + @lib_tracked_files ||= ruby_core? ? sys_exec("git ls-files -z -- lib/bundler lib/bundler.rb", :dir => root) : sys_exec("git ls-files -z -- lib", :dir => root) end def man_tracked_files skip "not in git working directory" unless git_root_dir? - @man_tracked_files ||= `git ls-files -z -- man` + @man_tracked_files ||= sys_exec("git ls-files -z -- man", :dir => root) end def tmp(*path) @@ -194,14 +194,6 @@ module Spec end end - def in_app_root - Dir.chdir(bundled_app) { yield } - end - - def in_app_root2 - Dir.chdir(bundled_app2) { yield } - end - def in_repo_root Dir.chdir(root) { yield } end diff --git a/spec/support/rubygems_version_manager.rb b/spec/support/rubygems_version_manager.rb index 854bce890d..8eab7749f9 100644 --- a/spec/support/rubygems_version_manager.rb +++ b/spec/support/rubygems_version_manager.rb @@ -44,10 +44,8 @@ private def switch_local_copy_if_needed return unless local_copy_switch_needed? - Dir.chdir(local_copy_path) do - sys_exec!("git remote update") - sys_exec!("git checkout #{target_tag} --quiet") - end + sys_exec!("git remote update", :dir => local_copy_path) + sys_exec!("git checkout #{target_tag} --quiet", :dir => local_copy_path) ENV["RGV"] = local_copy_path.to_s end @@ -65,9 +63,7 @@ private end def local_copy_tag - Dir.chdir(local_copy_path) do - sys_exec!("git rev-parse --abbrev-ref HEAD") - end + sys_exec!("git rev-parse --abbrev-ref HEAD", :dir => local_copy_path) end def local_copy_path diff --git a/spec/update/gemfile_spec.rb b/spec/update/gemfile_spec.rb index 8c2bd9ccbf..4a902e59e2 100644 --- a/spec/update/gemfile_spec.rb +++ b/spec/update/gemfile_spec.rb @@ -38,12 +38,10 @@ RSpec.describe "bundle update" do it "uses the gemfile while in a subdirectory" do bundled_app("subdir").mkpath - Dir.chdir(bundled_app("subdir")) do - bundle! "update", :all => true - bundle "list" + bundle! "update", :all => true, :dir => bundled_app("subdir") + bundle "list", :dir => bundled_app("subdir") - expect(out).to include("rack (1.0.0)") - end + expect(out).to include("rack (1.0.0)") end end end diff --git a/spec/update/git_spec.rb b/spec/update/git_spec.rb index 752033c842..58cf18bba0 100644 --- a/spec/update/git_spec.rb +++ b/spec/update/git_spec.rb @@ -131,10 +131,8 @@ RSpec.describe "bundle update" do s.add_dependency "submodule" end - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0", :dir => lib_path("has_submodule-1.0") + sys_exec "git commit -m \"submodulator\"", :dir => lib_path("has_submodule-1.0") end it "it unlocks the source when submodules are added to a git source" do @@ -259,14 +257,12 @@ RSpec.describe "bundle update" do bundle "update --source foo" - in_app_root do - run <<-RUBY - require 'foo' - puts "WIN" if defined?(FOO_PREV_REF) - RUBY + run <<-RUBY + require 'foo' + puts "WIN" if defined?(FOO_PREV_REF) + RUBY - expect(out).to eq("WIN") - end + expect(out).to eq("WIN") end it "unlocks gems that were originally pulled in by the source" do -- cgit v1.2.1