Skip to content

Commit 7dcfdf1

Browse files
committed
1 parent bc2e95e commit 7dcfdf1

File tree

6 files changed

+87
-62
lines changed

6 files changed

+87
-62
lines changed

spec/bundler/bin/parallel_rspec

Lines changed: 0 additions & 7 deletions
This file was deleted.

spec/bundler/spec_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def self.ruby=(ruby)
9595

9696
extend(Spec::Builders)
9797

98+
check_test_gems!
99+
98100
build_repo1
99101

100102
reset_paths!
@@ -117,4 +119,8 @@ def self.ruby=(ruby)
117119
ensure
118120
reset!
119121
end
122+
123+
config.after :suite do
124+
FileUtils.rm_r Spec::Path.pristine_system_gem_path
125+
end
120126
end

spec/bundler/support/builders.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ def build_repo(path, **kwargs, &blk)
276276
update_repo(path,**kwargs, &blk)
277277
end
278278

279+
def check_test_gems!
280+
if rake_path.nil?
281+
Spec::Rubygems.install_test_deps
282+
end
283+
284+
Helpers.install_dev_bundler unless pristine_system_gem_path.exist?
285+
end
286+
279287
def update_repo(path, build_compact_index: true)
280288
exempted_caller = Gem.ruby_version >= Gem::Version.new("3.4.0.dev") ? "#{Module.nesting.first}#build_repo" : "build_repo"
281289
if path == gem_repo1 && caller_locations(1, 1).first.label != exempted_caller
@@ -445,7 +453,6 @@ def _build(options = {})
445453
build_path = @context.tmp + full_name
446454
bundler_path = build_path + "#{full_name}.gem"
447455

448-
require "fileutils"
449456
FileUtils.mkdir_p build_path
450457

451458
@context.shipped_files.each do |shipped_file|
@@ -454,7 +461,7 @@ def _build(options = {})
454461
target_shipped_file = build_path + target_shipped_file
455462
target_shipped_dir = File.dirname(target_shipped_file)
456463
FileUtils.mkdir_p target_shipped_dir unless File.directory?(target_shipped_dir)
457-
FileUtils.cp File.expand_path(shipped_file, @context.source_root), target_shipped_file, preserve: true
464+
FileUtils.cp shipped_file, target_shipped_file, preserve: true
458465
end
459466

460467
@context.replace_version_file(@version, dir: build_path)

spec/bundler/support/path.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ def relative_gemspec
2525
@relative_gemspec ||= ruby_core? ? "lib/bundler/bundler.gemspec" : "bundler.gemspec"
2626
end
2727

28+
def gemspec_dir
29+
@gemspec_dir ||= gemspec.parent
30+
end
31+
2832
def loaded_gemspec
29-
@loaded_gemspec ||= Dir.chdir(source_root) { Gem::Specification.load(gemspec.to_s) }
33+
@loaded_gemspec ||= Gem::Specification.load(gemspec.to_s)
3034
end
3135

3236
def test_gemfile
@@ -98,11 +102,11 @@ def man_tracked_files
98102
end
99103

100104
def tmp(*path)
101-
tmp_root.join("#{test_env_version}.#{scope}").join(*path)
105+
tmp_root(scope).join(*path)
102106
end
103107

104-
def tmp_root
105-
source_root.join("tmp")
108+
def tmp_root(scope)
109+
source_root.join("tmp", "#{test_env_version}.#{scope}")
106110
end
107111

108112
# Bump this version whenever you make a breaking change to the spec setup
@@ -176,15 +180,15 @@ def base_system_gem_path
176180
end
177181

178182
def base_system_gems
179-
tmp_root.join("gems/base")
183+
tmp("gems/base")
180184
end
181185

182186
def rubocop_gems
183-
tmp_root.join("gems/rubocop")
187+
tmp("gems/rubocop")
184188
end
185189

186190
def standard_gems
187-
tmp_root.join("gems/standard")
191+
tmp("gems/standard")
188192
end
189193

190194
def file_uri_for(path)
@@ -223,7 +227,7 @@ def system_gem_path(*path)
223227
end
224228

225229
def pristine_system_gem_path
226-
tmp_root.join("gems/pristine_system")
230+
tmp("gems/base_system")
227231
end
228232

229233
def local_gem_path(*path, base: bundled_app)
@@ -277,7 +281,7 @@ def git_root
277281
end
278282

279283
def rake_path
280-
Dir["#{base_system_gems}/*/*/**/rake*.gem"].first
284+
Dir["#{base_system_gems}/#{Bundler.ruby_scope}/**/rake*.gem"].first
281285
end
282286

283287
def sinatra_dependency_paths

spec/bundler/support/rubygems_ext.rb

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ module Spec
1010
module Rubygems
1111
extend self
1212

13+
def dev_setup
14+
install_gems(dev_gemfile)
15+
end
16+
1317
def gem_load(gem_name, bin_container)
1418
require_relative "switch_rubygems"
1519

@@ -46,19 +50,41 @@ def test_setup
4650
Gem::DefaultUserInteraction.ui = Gem::SilentUI.new
4751
end
4852

53+
def install_parallel_test_deps
54+
Gem.clear_paths
55+
56+
require "parallel"
57+
require "fileutils"
58+
59+
install_test_deps
60+
61+
(2..Parallel.processor_count).each do |n|
62+
source = Path.tmp_root("1")
63+
destination = Path.tmp_root(n.to_s)
64+
65+
FileUtils.cp_r source, destination, remove_destination: true
66+
end
67+
end
68+
4969
def setup_test_paths
70+
Gem.clear_paths
71+
5072
ENV["BUNDLE_PATH"] = nil
73+
ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gem_path.to_s
5174
ENV["PATH"] = [Path.system_gem_path("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
5275
ENV["PATH"] = [Path.bindir, ENV["PATH"]].join(File::PATH_SEPARATOR) if Path.ruby_core?
5376
end
5477

5578
def install_test_deps
56-
dev_bundle("install", gemfile: test_gemfile, path: Path.base_system_gems.to_s)
57-
dev_bundle("install", gemfile: rubocop_gemfile, path: Path.rubocop_gems.to_s)
58-
dev_bundle("install", gemfile: standard_gemfile, path: Path.standard_gems.to_s)
79+
Gem.clear_paths
80+
81+
install_gems(test_gemfile, Path.base_system_gems.to_s)
82+
install_gems(rubocop_gemfile, Path.rubocop_gems.to_s)
83+
install_gems(standard_gemfile, Path.standard_gems.to_s)
5984

60-
require_relative "helpers"
61-
Helpers.install_dev_bundler
85+
# For some reason, doing this here crashes on JRuby + Windows. So defer to
86+
# when the test suite is running in that case.
87+
Helpers.install_dev_bundler unless Gem.win_platform? && RUBY_ENGINE == "jruby"
6288
end
6389

6490
def check_source_control_changes(success_message:, error_message:)
@@ -81,36 +107,6 @@ def check_source_control_changes(success_message:, error_message:)
81107
end
82108
end
83109

84-
def dev_bundle(*args, gemfile: dev_gemfile, path: nil)
85-
old_gemfile = ENV["BUNDLE_GEMFILE"]
86-
old_orig_gemfile = ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"]
87-
ENV["BUNDLE_GEMFILE"] = gemfile.to_s
88-
ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"] = nil
89-
90-
if path
91-
old_path = ENV["BUNDLE_PATH"]
92-
ENV["BUNDLE_PATH"] = path
93-
else
94-
old_path__system = ENV["BUNDLE_PATH__SYSTEM"]
95-
ENV["BUNDLE_PATH__SYSTEM"] = "true"
96-
end
97-
98-
require "shellwords"
99-
# We don't use `Open3` here because it does not work on JRuby + Windows
100-
output = `ruby #{File.expand_path("support/bundle.rb", Path.spec_dir)} #{args.shelljoin}`
101-
raise output unless $?.success?
102-
output
103-
ensure
104-
if path
105-
ENV["BUNDLE_PATH"] = old_path
106-
else
107-
ENV["BUNDLE_PATH__SYSTEM"] = old_path__system
108-
end
109-
110-
ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"] = old_orig_gemfile
111-
ENV["BUNDLE_GEMFILE"] = old_gemfile
112-
end
113-
114110
private
115111

116112
def gem_load_and_activate(gem_name, bin_container)
@@ -139,6 +135,34 @@ def gem_activate(gem_name)
139135
gem gem_name, gem_requirement
140136
end
141137

138+
def install_gems(gemfile, path = nil)
139+
old_gemfile = ENV["BUNDLE_GEMFILE"]
140+
old_orig_gemfile = ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"]
141+
ENV["BUNDLE_GEMFILE"] = gemfile.to_s
142+
ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"] = nil
143+
144+
if path
145+
old_path = ENV["BUNDLE_PATH"]
146+
ENV["BUNDLE_PATH"] = path
147+
else
148+
old_path__system = ENV["BUNDLE_PATH__SYSTEM"]
149+
ENV["BUNDLE_PATH__SYSTEM"] = "true"
150+
end
151+
152+
# We don't use `Open3` here because it does not work on JRuby + Windows
153+
output = `#{Gem.ruby} #{File.expand_path("support/bundle.rb", Path.spec_dir)} install`
154+
raise output unless $?.success?
155+
ensure
156+
if path
157+
ENV["BUNDLE_PATH"] = old_path
158+
else
159+
ENV["BUNDLE_PATH__SYSTEM"] = old_path__system
160+
end
161+
162+
ENV["BUNDLER_ORIG_BUNDLE_GEMFILE"] = old_orig_gemfile
163+
ENV["BUNDLE_GEMFILE"] = old_gemfile
164+
end
165+
142166
def test_gemfile
143167
Path.test_gemfile
144168
end

spec/bundler/support/setup.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)