@@ -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
0 commit comments