summaryrefslogtreecommitdiff
path: root/spec/bundler/support
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/support')
-rw-r--r--spec/bundler/support/bundle.rb8
-rw-r--r--spec/bundler/support/hax.rb2
-rw-r--r--spec/bundler/support/helpers.rb2
-rw-r--r--spec/bundler/support/path.rb24
-rw-r--r--spec/bundler/support/rubygems_ext.rb63
5 files changed, 62 insertions, 37 deletions
diff --git a/spec/bundler/support/bundle.rb b/spec/bundler/support/bundle.rb
new file mode 100644
index 0000000000..bb21526d35
--- /dev/null
+++ b/spec/bundler/support/bundle.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+require "rubygems"
+require_relative "path"
+bundler_gemspec = Spec::Path.loaded_gemspec
+bundler_gemspec.instance_variable_set(:@full_gem_path, Spec::Path.source_root)
+bundler_gemspec.activate if bundler_gemspec.respond_to?(:activate)
+load File.expand_path("bundle", Spec::Path.bindir)
diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb
index fc8e0ad55d..8fd35890ae 100644
--- a/spec/bundler/support/hax.rb
+++ b/spec/bundler/support/hax.rb
@@ -29,7 +29,7 @@ module Gem
end
# We only need this hack for rubygems versions without the BundlerVersionFinder
- if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
+ if Gem.rubygems_version < Gem::Version.new("2.7.0")
@path_to_default_spec_map.delete_if do |_path, spec|
spec.name == "bundler"
end
diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb
index 7e2e92a1ec..73dd508e54 100644
--- a/spec/bundler/support/helpers.rb
+++ b/spec/bundler/support/helpers.rb
@@ -10,7 +10,7 @@ module Spec
def reset!
Dir.glob("#{tmp}/{gems/*,*}", File::FNM_DOTMATCH).each do |dir|
- next if %w[base base_system remote1 gems rubygems . ..].include?(File.basename(dir))
+ next if %w[base base_system remote1 rubocop gems rubygems . ..].include?(File.basename(dir))
FileUtils.rm_rf(dir)
end
FileUtils.mkdir_p(home)
diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb
index 56d3c71f3c..483c7da347 100644
--- a/spec/bundler/support/path.rb
+++ b/spec/bundler/support/path.rb
@@ -6,7 +6,7 @@ require "rbconfig"
module Spec
module Path
def source_root
- @source_root ||= Pathname.new(ruby_core? ? "../../../.." : "../../..").expand_path(__FILE__)
+ @source_root ||= Pathname.new(ruby_core? ? "../../.." : "../..").expand_path(__dir__)
end
def root
@@ -30,7 +30,11 @@ module Spec
end
def test_gemfile
- @test_gemfile ||= source_root.join(ruby_core? ? "tool/bundler/test_gems.rb" : "test_gems.rb")
+ @test_gemfile ||= source_root.join("tool/bundler/test_gems.rb")
+ end
+
+ def rubocop_gemfile
+ @rubocop_gemfile ||= source_root.join(rubocop_gemfile_basename)
end
def dev_gemfile
@@ -119,7 +123,7 @@ module Spec
end
def vendored_gems(path = nil)
- bundled_app(*["vendor/bundle", Gem.ruby_engine, RbConfig::CONFIG["ruby_version"], path].compact)
+ scoped_gem_path(bundled_app("vendor/bundle")).join(*[path].compact)
end
def cached_gem(path)
@@ -138,6 +142,10 @@ module Spec
tmp.join("gems/base")
end
+ def rubocop_gems
+ tmp.join("gems/rubocop")
+ end
+
def file_uri_for(path)
protocol = "file://"
root = Gem.win_platform? ? "/" : ""
@@ -178,7 +186,11 @@ module Spec
end
def local_gem_path(*path, base: bundled_app)
- base.join(*[".bundle", Gem.ruby_engine, RbConfig::CONFIG["ruby_version"], *path].compact)
+ scoped_gem_path(base.join(".bundle")).join(*path)
+ end
+
+ def scoped_gem_path(base)
+ base.join(Gem.ruby_engine, RbConfig::CONFIG["ruby_version"])
end
def lib_path(*args)
@@ -251,6 +263,10 @@ module Spec
!git_root.join(".git").directory?
end
+ def rubocop_gemfile_basename
+ source_root.join("tool/bundler/#{RUBY_VERSION.start_with?("2.3") ? "rubocop23_gems.rb" : "rubocop_gems.rb"}")
+ end
+
extend self
end
end
diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb
index d743a76391..c6202ebb1f 100644
--- a/spec/bundler/support/rubygems_ext.rb
+++ b/spec/bundler/support/rubygems_ext.rb
@@ -9,7 +9,7 @@ module Spec
extend self
def dev_setup
- install_gems(dev_gemfile, dev_lockfile)
+ install_gems(dev_gemfile)
end
def gem_load(gem_name, bin_container)
@@ -39,18 +39,19 @@ module Spec
end
def install_parallel_test_deps
+ Gem.clear_paths
+
require "parallel"
+ require "fileutils"
- prev_env_test_number = ENV["TEST_ENV_NUMBER"]
+ install_test_deps
- begin
- Parallel.processor_count.times do |n|
- ENV["TEST_ENV_NUMBER"] = (n + 1).to_s
+ (2..Parallel.processor_count).each do |n|
+ source = Path.source_root.join("tmp", "1")
+ destination = Path.source_root.join("tmp", n.to_s)
- install_test_deps
- end
- ensure
- ENV["TEST_ENV_NUMBER"] = prev_env_test_number
+ FileUtils.rm_rf destination
+ FileUtils.cp_r source, destination
end
end
@@ -66,25 +67,12 @@ module Spec
def install_test_deps
setup_test_paths
- workaround_loaded_specs_issue
-
- install_gems(test_gemfile, test_lockfile)
+ install_gems(test_gemfile)
+ install_gems(rubocop_gemfile, Path.rubocop_gems.to_s)
end
private
- # Some rubygems versions include loaded specs when loading gemspec stubs
- # from the file system. In this situation, that makes bundler incorrectly
- # assume that `rake` is already installed at `tmp/` because it's installed
- # globally, and makes it skip installing it to the proper location for our
- # tests. To workaround, we remove `rake` from the loaded specs when running
- # under those versions, so that `bundler` does the right thing.
- def workaround_loaded_specs_issue
- current_rubygems_version = Gem::Version.new(Gem::VERSION)
-
- Gem.loaded_specs.delete("rake") if current_rubygems_version >= Gem::Version.new("3.0.0.beta2") && current_rubygems_version < Gem::Version.new("3.2.0")
- end
-
def gem_load_and_activate(gem_name, bin_container)
gem_activate(gem_name)
load Gem.bin_path(gem_name, bin_container)
@@ -98,14 +86,27 @@ module Spec
gem gem_name, gem_requirement
end
- def install_gems(gemfile, lockfile)
+ def install_gems(gemfile, path = nil)
old_gemfile = ENV["BUNDLE_GEMFILE"]
ENV["BUNDLE_GEMFILE"] = gemfile.to_s
- require "bundler"
- definition = Bundler::Definition.build(gemfile, lockfile, nil)
- definition.validate_runtime!
- Bundler::Installer.install(Path.source_root, definition, :path => ENV["GEM_HOME"])
+
+ 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
+
+ output = `#{Gem.ruby} #{File.expand_path("support/bundle.rb", Path.spec_dir)} install`
+ raise "Error when installing gems in #{gemfile}: #{output}" unless $?.success?
ensure
+ if path
+ ENV["BUNDLE_PATH"] = old_path
+ else
+ ENV["BUNDLE_PATH__SYSTEM"] = old_path__system
+ end
+
ENV["BUNDLE_GEMFILE"] = old_gemfile
end
@@ -113,8 +114,8 @@ module Spec
Path.test_gemfile
end
- def test_lockfile
- lockfile_for(test_gemfile)
+ def rubocop_gemfile
+ Path.rubocop_gemfile
end
def dev_gemfile