diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/bundler/commands/binstubs_spec.rb | 75 | ||||
-rw-r--r-- | spec/bundler/install/binstubs_spec.rb | 1 | ||||
-rw-r--r-- | spec/bundler/install/gemfile/git_spec.rb | 3 | ||||
-rw-r--r-- | spec/bundler/install/gemfile/path_spec.rb | 3 | ||||
-rw-r--r-- | spec/bundler/lock/lockfile_spec.rb | 2 | ||||
-rw-r--r-- | spec/bundler/other/major_deprecation_spec.rb | 4 | ||||
-rw-r--r-- | spec/bundler/other/platform_spec.rb | 4 | ||||
-rw-r--r-- | spec/bundler/rubygems/rubygems.rb | 9 | ||||
-rw-r--r-- | spec/bundler/runtime/inline_spec.rb | 2 | ||||
-rw-r--r-- | spec/bundler/runtime/setup_spec.rb | 4 | ||||
-rw-r--r-- | spec/bundler/spec_helper.rb | 2 | ||||
-rw-r--r-- | spec/bundler/support/hax.rb | 6 | ||||
-rw-r--r-- | spec/bundler/support/helpers.rb | 3 | ||||
-rw-r--r-- | spec/bundler/support/matchers.rb | 3 | ||||
-rw-r--r-- | spec/bundler/support/path.rb | 2 | ||||
-rw-r--r-- | spec/bundler/support/rubygems.rb | 7 | ||||
-rw-r--r-- | spec/bundler/support/rubygems_ext.rb | 5 | ||||
-rw-r--r-- | spec/bundler/support/rubygems_version_manager.rb | 2 |
18 files changed, 74 insertions, 63 deletions
diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb index 81b4d99064..df10bd3498 100644 --- a/spec/bundler/commands/binstubs_spec.rb +++ b/spec/bundler/commands/binstubs_spec.rb @@ -141,38 +141,61 @@ RSpec.describe "bundle binstubs <gem>" do end context "when a lockfile exists with a locked bundler version" do - it "runs the correct version of bundler when the version is newer" do - lockfile lockfile.gsub(system_bundler_version, "999.999.999") - sys_exec "#{bundled_app("bin/bundle")} install" - 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'`") + context "and the version is newer" do + before do + lockfile lockfile.gsub(system_bundler_version, "999.999") + end + + it "runs the correct version of bundler" do + sys_exec "#{bundled_app("bin/bundle")} install" + 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'`") + end end - it "runs the correct version of bundler when the version is older and a different major" do - simulate_bundler_version "55" - lockfile lockfile.gsub(system_bundler_version, "44.0") - sys_exec "#{bundled_app("bin/bundle")} install" - expect(exitstatus).to eq(42) if exitstatus - expect(err).to include("Activating bundler (~> 44.0) failed:"). - and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`") + context "and the version is older and a different major" do + let(:system_bundler_version) { "55" } + + before do + lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 44.0") + end + + it "runs the correct version of bundler" do + sys_exec "#{bundled_app("bin/bundle")} install" + expect(exitstatus).to eq(42) if exitstatus + expect(err).to include("Activating bundler (~> 44.0) failed:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 44.0'`") + end end - it "runs the available version of bundler when the version is older and the same major" do - simulate_bundler_version "55.1" - lockfile lockfile.gsub(system_bundler_version, "55.0") - sys_exec "#{bundled_app("bin/bundle")} install" - expect(exitstatus).not_to eq(42) if exitstatus - expect(err).not_to include("Activating bundler (~> 55.0) failed:") + context "and the version is older and the same major" do + let(:system_bundler_version) { "55.1" } + + before do + lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 55.0") + end + + it "runs the available version of bundler when the version is older and the same major" do + sys_exec "#{bundled_app("bin/bundle")} install" + expect(exitstatus).not_to eq(42) if exitstatus + expect(err).not_to include("Activating bundler (~> 55.0) failed:") + end end - it "runs the correct version of bundler when the version is a pre-release" do - simulate_bundler_version "55" - lockfile lockfile.gsub(system_bundler_version, "2.12.0.a") - sys_exec "#{bundled_app("bin/bundle")} install" - expect(exitstatus).to eq(42) if exitstatus - expect(err).to include("Activating bundler (~> 2.12.a) failed:"). - and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 2.12.a'`") + context "and the version is a pre-releaser" do + let(:system_bundler_version) { "55" } + + before do + lockfile lockfile.gsub(/BUNDLED WITH\n .*$/m, "BUNDLED WITH\n 2.12.0.a") + end + + it "runs the correct version of bundler when the version is a pre-release" do + sys_exec "#{bundled_app("bin/bundle")} install" + expect(exitstatus).to eq(42) if exitstatus + expect(err).to include("Activating bundler (~> 2.12.a) failed:"). + and include("To install the version of bundler this project requires, run `gem install bundler -v '~> 2.12.a'`") + end end end diff --git a/spec/bundler/install/binstubs_spec.rb b/spec/bundler/install/binstubs_spec.rb index e7aa577077..78ee893b81 100644 --- a/spec/bundler/install/binstubs_spec.rb +++ b/spec/bundler/install/binstubs_spec.rb @@ -7,7 +7,6 @@ RSpec.describe "bundle install" do it "overrides Gem.bindir" do expect(Pathname.new("/usr/bin")).not_to be_writable unless Process.euid == 0 gemfile <<-G - require 'rubygems' def Gem.bindir; "/usr/bin"; end source "#{file_uri_for(gem_repo1)}" gem "rack" diff --git a/spec/bundler/install/gemfile/git_spec.rb b/spec/bundler/install/gemfile/git_spec.rb index 08789820d8..00f8e96625 100644 --- a/spec/bundler/install/gemfile/git_spec.rb +++ b/spec/bundler/install/gemfile/git_spec.rb @@ -1056,7 +1056,6 @@ RSpec.describe "bundle install with git sources" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require '#{spec_dir}/support/rubygems' Gem.pre_install_hooks << lambda do |inst| STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}" end @@ -1076,7 +1075,6 @@ RSpec.describe "bundle install with git sources" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require '#{spec_dir}/support/rubygems' Gem.post_install_hooks << lambda do |inst| STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}" end @@ -1096,7 +1094,6 @@ RSpec.describe "bundle install with git sources" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require '#{spec_dir}/support/rubygems' Gem.pre_install_hooks << lambda do |inst| false end diff --git a/spec/bundler/install/gemfile/path_spec.rb b/spec/bundler/install/gemfile/path_spec.rb index 5261e18bbe..786b767354 100644 --- a/spec/bundler/install/gemfile/path_spec.rb +++ b/spec/bundler/install/gemfile/path_spec.rb @@ -672,7 +672,6 @@ RSpec.describe "bundle install with explicit source paths" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require '#{spec_dir}/support/rubygems' Gem.pre_install_hooks << lambda do |inst| STDERR.puts "Ran pre-install hook: \#{inst.spec.full_name}" end @@ -692,7 +691,6 @@ RSpec.describe "bundle install with explicit source paths" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require '#{spec_dir}/support/rubygems' Gem.post_install_hooks << lambda do |inst| STDERR.puts "Ran post-install hook: \#{inst.spec.full_name}" end @@ -712,7 +710,6 @@ RSpec.describe "bundle install with explicit source paths" do File.open(lib_path("install_hooks.rb"), "w") do |h| h.write <<-H - require '#{spec_dir}/support/rubygems' Gem.pre_install_hooks << lambda do |inst| false end diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb index e291fb7917..ddab4831a5 100644 --- a/spec/bundler/lock/lockfile_spec.rb +++ b/spec/bundler/lock/lockfile_spec.rb @@ -1418,7 +1418,6 @@ RSpec.describe "the lockfile format" do it "preserves Gemfile.lock \\n line endings" do expect do ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup RUBY @@ -1432,7 +1431,6 @@ RSpec.describe "the lockfile format" do expect do ruby <<-RUBY - require 'rubygems' require 'bundler' Bundler.setup RUBY diff --git a/spec/bundler/other/major_deprecation_spec.rb b/spec/bundler/other/major_deprecation_spec.rb index 57b68fdb97..f743bccb92 100644 --- a/spec/bundler/other/major_deprecation_spec.rb +++ b/spec/bundler/other/major_deprecation_spec.rb @@ -356,9 +356,7 @@ RSpec.describe "major deprecations" do G ruby <<-RUBY - require 'rubygems' - require 'bundler' - require 'bundler/vendored_thor' + require '#{lib_dir}/bundler' Bundler.setup Bundler.setup diff --git a/spec/bundler/other/platform_spec.rb b/spec/bundler/other/platform_spec.rb index 4feec14d76..8b02505ad8 100644 --- a/spec/bundler/other/platform_spec.rb +++ b/spec/bundler/other/platform_spec.rb @@ -1086,7 +1086,6 @@ G FileUtils.rm(bundled_app("Gemfile.lock")) ruby <<-R - require 'rubygems' require 'bundler/setup' R @@ -1106,7 +1105,6 @@ G FileUtils.rm(bundled_app("Gemfile.lock")) ruby <<-R - require 'rubygems' require 'bundler/setup' R @@ -1127,7 +1125,6 @@ G FileUtils.rm(bundled_app("Gemfile.lock")) ruby <<-R - require 'rubygems' require 'bundler/setup' R @@ -1148,7 +1145,6 @@ G FileUtils.rm(bundled_app("Gemfile.lock")) ruby <<-R - require 'rubygems' require 'bundler/setup' R diff --git a/spec/bundler/rubygems/rubygems.rb b/spec/bundler/rubygems/rubygems.rb new file mode 100644 index 0000000000..6fa63013bf --- /dev/null +++ b/spec/bundler/rubygems/rubygems.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require_relative "../support/rubygems_version_manager" + +RubygemsVersionManager.new(ENV["RGV"]).switch + +$:.delete("#{Spec::Path.spec_dir}/rubygems") + +require "rubygems" diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index e5569fec94..06be2ef83d 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -115,7 +115,7 @@ RSpec.describe "bundler/inline#gemfile" do it "has an option for quiet installation" do script <<-RUBY, :artifice => "endpoint" - require 'bundler' + require '#{lib_dir}/bundler/inline' gemfile(true, :quiet => true) do source "https://notaserver.com" diff --git a/spec/bundler/runtime/setup_spec.rb b/spec/bundler/runtime/setup_spec.rb index 72ad06a43a..4a754945b7 100644 --- a/spec/bundler/runtime/setup_spec.rb +++ b/spec/bundler/runtime/setup_spec.rb @@ -985,9 +985,7 @@ end build_git "bar", :gemspec => false do |s| s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0') s.write "bar.gemspec", <<-G - lib = File.expand_path('../lib/', __FILE__) - $:.unshift lib unless $:.include?(lib) - require 'bar/version' + require_relative 'lib/bar/version' Gem::Specification.new do |s| s.name = 'bar' diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index ba21d22fbd..9702ab71f5 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -82,7 +82,7 @@ RSpec.configure do |config| config.before :suite do require_relative "support/rubygems_ext" Spec::Rubygems.setup - ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.spec_dir}/support/hax.rb" + ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{Spec::Path.spec_dir}/rubygems -r#{Spec::Path.spec_dir}/support/hax.rb" ENV["BUNDLE_SPEC_RUN"] = "true" ENV["BUNDLE_USER_CONFIG"] = ENV["BUNDLE_USER_CACHE"] = ENV["BUNDLE_USER_PLUGIN"] = nil ENV["GEMRC"] = nil diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb index 3e1ece2f0a..c18470acd2 100644 --- a/spec/bundler/support/hax.rb +++ b/spec/bundler/support/hax.rb @@ -28,7 +28,8 @@ module Gem end if ENV["BUNDLER_SPEC_VERSION"] - require "bundler/version" + require_relative "path" + require "#{Spec::Path.lib_dir}/bundler/version" module Bundler remove_const(:VERSION) if const_defined?(:VERSION) @@ -37,7 +38,8 @@ if ENV["BUNDLER_SPEC_VERSION"] end if ENV["BUNDLER_SPEC_WINDOWS"] == "true" - require "bundler/constants" + require_relative "path" + require "#{Spec::Path.lib_dir}/bundler/constants" module Bundler remove_const :WINDOWS if defined?(WINDOWS) diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index 8bf76bba89..911f734d8b 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -110,7 +110,6 @@ module Spec env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler requires = options.delete(:requires) || [] - requires << "support/rubygems" requires << "support/hax" artifice = options.delete(:artifice) do @@ -144,7 +143,7 @@ module Spec end end.join - cmd = "#{sudo} #{Gem.ruby} --disable-gems #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" + cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}" sys_exec(cmd, env) {|i, o, thr| yield i, o, thr if block_given? } end bang :bundle diff --git a/spec/bundler/support/matchers.rb b/spec/bundler/support/matchers.rb index 69d3be4a3d..e1a08a30cc 100644 --- a/spec/bundler/support/matchers.rb +++ b/spec/bundler/support/matchers.rb @@ -128,9 +128,10 @@ module Spec groups << opts @errors = names.map do |name| name, version, platform = name.split(/\s+/) + require_path = name == "bundler" ? "#{lib_dir}/bundler" : name version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name) begin - run! "require '#{name}.rb'; puts #{version_const}", *groups + run! "require '#{require_path}.rb'; puts #{version_const}", *groups rescue StandardError => e next "#{name} is not installed:\n#{indent(e)}" end diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb index b957e24abe..cc5aebb01b 100644 --- a/spec/bundler/support/path.rb +++ b/spec/bundler/support/path.rb @@ -22,7 +22,7 @@ module Spec end def gem_bin - @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} --disable-gems -r#{spec_dir}/support/rubygems -S gem --backtrace" + @gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} -I#{spec_dir}/rubygems -S gem --backtrace" end def spec_dir diff --git a/spec/bundler/support/rubygems.rb b/spec/bundler/support/rubygems.rb deleted file mode 100644 index e60f9a928e..0000000000 --- a/spec/bundler/support/rubygems.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -require_relative "rubygems_version_manager" - -RubygemsVersionManager.new(ENV["RGV"]).switch - -require "rubygems" diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index 1093362d81..d237897b67 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require_relative "path" -require "fileutils" module Spec module Rubygems @@ -40,7 +39,7 @@ module Spec end def gem_load(gem_name, bin_container) - require_relative "rubygems" + require_relative "../rubygems/rubygems" gem_load_and_activate(gem_name, bin_container) end @@ -50,6 +49,8 @@ module Spec end def setup + require "fileutils" + Gem.clear_paths ENV["BUNDLE_PATH"] = nil diff --git a/spec/bundler/support/rubygems_version_manager.rb b/spec/bundler/support/rubygems_version_manager.rb index 31f7cc4b08..356d391c08 100644 --- a/spec/bundler/support/rubygems_version_manager.rb +++ b/spec/bundler/support/rubygems_version_manager.rb @@ -56,7 +56,7 @@ private end def rubygems_unrequire_needed? - defined?(Gem) && Gem::VERSION != target_gem_version + defined?(Gem::VERSION) && Gem::VERSION != target_gem_version end def local_copy_switch_needed? |