summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2025-04-08 16:24:01 +0200
committerHiroshi SHIBATA <[email protected]>2025-04-10 19:21:51 +0900
commit756479324fcbf609b401cefafd2911268d4a7851 (patch)
tree83dc74221104960c46188d27ff05fc6b20b05b23 /spec
parent684cfa42d77f8b667333f5efa3bd52463985b9d4 (diff)
Sync Bundler and adapt to new spec setup
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13083
Diffstat (limited to 'spec')
-rwxr-xr-xspec/bin/parallel_rspec7
-rw-r--r--spec/bundler/spec_helper.rb6
-rw-r--r--spec/bundler/support/builders.rb11
-rw-r--r--spec/bundler/support/path.rb22
-rw-r--r--spec/bundler/support/rubygems_ext.rb94
-rw-r--r--spec/bundler/support/setup.rb9
6 files changed, 56 insertions, 93 deletions
diff --git a/spec/bin/parallel_rspec b/spec/bin/parallel_rspec
index 3b2b003579..412defa58b 100755
--- a/spec/bin/parallel_rspec
+++ b/spec/bin/parallel_rspec
@@ -1,12 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
-require_relative "../../spec/bundler/support/rubygems_ext"
-
-require_relative "../../spec/bundler/support/switch_rubygems"
-
-require "rubygems"
-$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
+require_relative "../bundler/support/setup"
require "turbo_tests"
TurboTests::CLI.new(ARGV).run
diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb
index 470bf3e414..56f20999fd 100644
--- a/spec/bundler/spec_helper.rb
+++ b/spec/bundler/spec_helper.rb
@@ -95,8 +95,6 @@ RSpec.configure do |config|
extend(Spec::Builders)
- check_test_gems!
-
build_repo1
reset_paths!
@@ -119,8 +117,4 @@ RSpec.configure do |config|
ensure
reset!
end
-
- config.after :suite do
- FileUtils.rm_r Spec::Path.pristine_system_gem_path
- end
end
diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb
index 13c21bf5cc..c566f87e56 100644
--- a/spec/bundler/support/builders.rb
+++ b/spec/bundler/support/builders.rb
@@ -276,14 +276,6 @@ module Spec
update_repo(path,**kwargs, &blk)
end
- def check_test_gems!
- if rake_path.nil?
- Spec::Rubygems.install_test_deps
- end
-
- Helpers.install_dev_bundler unless pristine_system_gem_path.exist?
- end
-
def update_repo(path, build_compact_index: true)
exempted_caller = Gem.ruby_version >= Gem::Version.new("3.4.0.dev") ? "#{Module.nesting.first}#build_repo" : "build_repo"
if path == gem_repo1 && caller_locations(1, 1).first.label != exempted_caller
@@ -453,6 +445,7 @@ module Spec
build_path = @context.tmp + full_name
bundler_path = build_path + "#{full_name}.gem"
+ require "fileutils"
FileUtils.mkdir_p build_path
@context.shipped_files.each do |shipped_file|
@@ -461,7 +454,7 @@ module Spec
target_shipped_file = build_path + target_shipped_file
target_shipped_dir = File.dirname(target_shipped_file)
FileUtils.mkdir_p target_shipped_dir unless File.directory?(target_shipped_dir)
- FileUtils.cp shipped_file, target_shipped_file, preserve: true
+ FileUtils.cp File.expand_path(shipped_file, @context.source_root), target_shipped_file, preserve: true
end
@context.replace_version_file(@version, dir: build_path)
diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb
index 9b67ab0229..98320259f7 100644
--- a/spec/bundler/support/path.rb
+++ b/spec/bundler/support/path.rb
@@ -25,12 +25,8 @@ module Spec
@relative_gemspec ||= ruby_core? ? "lib/bundler/bundler.gemspec" : "bundler.gemspec"
end
- def gemspec_dir
- @gemspec_dir ||= gemspec.parent
- end
-
def loaded_gemspec
- @loaded_gemspec ||= Gem::Specification.load(gemspec.to_s)
+ @loaded_gemspec ||= Dir.chdir(source_root) { Gem::Specification.load(gemspec.to_s) }
end
def test_gemfile
@@ -102,11 +98,11 @@ module Spec
end
def tmp(*path)
- tmp_root(scope).join(*path)
+ tmp_root.join("#{test_env_version}.#{scope}").join(*path)
end
- def tmp_root(scope)
- source_root.join("tmp", "#{test_env_version}.#{scope}")
+ def tmp_root
+ source_root.join("tmp")
end
# Bump this version whenever you make a breaking change to the spec setup
@@ -180,15 +176,15 @@ module Spec
end
def base_system_gems
- tmp("gems/base")
+ tmp_root.join("gems/base")
end
def rubocop_gems
- tmp("gems/rubocop")
+ tmp_root.join("gems/rubocop")
end
def standard_gems
- tmp("gems/standard")
+ tmp_root.join("gems/standard")
end
def file_uri_for(path)
@@ -227,7 +223,7 @@ module Spec
end
def pristine_system_gem_path
- tmp("gems/base_system")
+ tmp_root.join("gems/pristine_system")
end
def local_gem_path(*path, base: bundled_app)
@@ -281,7 +277,7 @@ module Spec
end
def rake_path
- Dir["#{base_system_gems}/#{Bundler.ruby_scope}/**/rake*.gem"].first
+ Dir["#{base_system_gems}/*/*/**/rake*.gem"].first
end
def sinatra_dependency_paths
diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb
index 67d49ac363..46261493db 100644
--- a/spec/bundler/support/rubygems_ext.rb
+++ b/spec/bundler/support/rubygems_ext.rb
@@ -10,10 +10,6 @@ module Spec
module Rubygems
extend self
- def dev_setup
- install_gems(dev_gemfile)
- end
-
def gem_load(gem_name, bin_container)
require_relative "switch_rubygems"
@@ -50,41 +46,19 @@ module Spec
Gem::DefaultUserInteraction.ui = Gem::SilentUI.new
end
- def install_parallel_test_deps
- Gem.clear_paths
-
- require "parallel"
- require "fileutils"
-
- install_test_deps
-
- (2..Parallel.processor_count).each do |n|
- source = Path.tmp_root("1")
- destination = Path.tmp_root(n.to_s)
-
- FileUtils.cp_r source, destination, remove_destination: true
- end
- end
-
def setup_test_paths
- Gem.clear_paths
-
ENV["BUNDLE_PATH"] = nil
- ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gem_path.to_s
ENV["PATH"] = [Path.system_gem_path("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
ENV["PATH"] = [Path.bindir, ENV["PATH"]].join(File::PATH_SEPARATOR) if Path.ruby_core?
end
def install_test_deps
- Gem.clear_paths
-
- install_gems(test_gemfile, Path.base_system_gems.to_s)
- install_gems(rubocop_gemfile, Path.rubocop_gems.to_s)
- install_gems(standard_gemfile, Path.standard_gems.to_s)
+ dev_bundle("install", gemfile: test_gemfile, path: Path.base_system_gems.to_s)
+ dev_bundle("install", gemfile: rubocop_gemfile, path: Path.rubocop_gems.to_s)
+ dev_bundle("install", gemfile: standard_gemfile, path: Path.standard_gems.to_s)
- # For some reason, doing this here crashes on JRuby + Windows. So defer to
- # when the test suite is running in that case.
- Helpers.install_dev_bundler unless Gem.win_platform? && RUBY_ENGINE == "jruby"
+ require_relative "helpers"
+ Helpers.install_dev_bundler
end
def check_source_control_changes(success_message:, error_message:)
@@ -107,6 +81,36 @@ module Spec
end
end
+ def dev_bundle(*args, gemfile: dev_gemfile, path: nil)
+ old_gemfile = ENV["BUNDLE_GEMFILE"]
+ old_orig_gemfile = ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"]
+ ENV["BUNDLE_GEMFILE"] = gemfile.to_s
+ ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"] = nil
+
+ if path
+ old_path = ENV["BUNDLE_PATH"]
+ ENV["BUNDLE_PATH"] = path
+ else
+ old_path__system = ENV["BUNDLE_PATH__SYSTEM"]
+ ENV["BUNDLE_PATH__SYSTEM"] = "true"
+ end
+
+ require "shellwords"
+ # We don't use `Open3` here because it does not work on JRuby + Windows
+ output = `ruby #{File.expand_path("support/bundle.rb", Path.spec_dir)} #{args.shelljoin}`
+ raise output unless $?.success?
+ output
+ ensure
+ if path
+ ENV["BUNDLE_PATH"] = old_path
+ else
+ ENV["BUNDLE_PATH__SYSTEM"] = old_path__system
+ end
+
+ ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"] = old_orig_gemfile
+ ENV["BUNDLE_GEMFILE"] = old_gemfile
+ end
+
private
def gem_load_and_activate(gem_name, bin_container)
@@ -135,34 +139,6 @@ module Spec
gem gem_name, gem_requirement
end
- def install_gems(gemfile, path = nil)
- old_gemfile = ENV["BUNDLE_GEMFILE"]
- old_orig_gemfile = ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"]
- ENV["BUNDLE_GEMFILE"] = gemfile.to_s
- ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"] = nil
-
- if path
- old_path = ENV["BUNDLE_PATH"]
- ENV["BUNDLE_PATH"] = path
- else
- old_path__system = ENV["BUNDLE_PATH__SYSTEM"]
- ENV["BUNDLE_PATH__SYSTEM"] = "true"
- end
-
- # We don't use `Open3` here because it does not work on JRuby + Windows
- output = `#{Gem.ruby} #{File.expand_path("support/bundle.rb", Path.spec_dir)} install`
- raise output unless $?.success?
- ensure
- if path
- ENV["BUNDLE_PATH"] = old_path
- else
- ENV["BUNDLE_PATH__SYSTEM"] = old_path__system
- end
-
- ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"] = old_orig_gemfile
- ENV["BUNDLE_GEMFILE"] = old_gemfile
- end
-
def test_gemfile
Path.test_gemfile
end
diff --git a/spec/bundler/support/setup.rb b/spec/bundler/support/setup.rb
new file mode 100644
index 0000000000..4ac2e5b472
--- /dev/null
+++ b/spec/bundler/support/setup.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require_relative "switch_rubygems"
+
+require_relative "rubygems_ext"
+Spec::Rubygems.install_test_deps
+
+require_relative "path"
+$LOAD_PATH.unshift(File.expand_path("../../lib", __dir__)) if Spec::Path.ruby_core?