diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-05-20 17:15:15 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-05-20 17:32:19 +0900 |
commit | aeea88174d88264469b406003765c7efdcd53edf (patch) | |
tree | a4d9de6d1a0027f5b9c2f2050bca2586b87596bb /spec/bundler | |
parent | bd8df25cdc8e0e94cbc2eacc492a764e6b90833c (diff) | |
download | ruby-aeea88174d88264469b406003765c7efdcd53edf.tar.gz |
Merge RubyGems and Bundler HEAD
https://github.com/rubygems/rubygems/commit/125415593ead9ab69a9f0bb5392c9d7ec61b1f51
Diffstat (limited to 'spec/bundler')
-rw-r--r-- | spec/bundler/runtime/inline_spec.rb | 2 | ||||
-rw-r--r-- | spec/bundler/spec_helper.rb | 4 | ||||
-rw-r--r-- | spec/bundler/support/path.rb | 8 | ||||
-rw-r--r-- | spec/bundler/support/rubygems_ext.rb | 20 | ||||
-rw-r--r-- | spec/bundler/support/sudo.rb | 4 |
5 files changed, 32 insertions, 6 deletions
diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index 9029c9b854..dd22c86f90 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -89,7 +89,7 @@ RSpec.describe "bundler/inline#gemfile" do expect(out).to include("Installing activesupport") err_lines = err.split("\n") - err_lines.reject!{|line| line =~ /\.rb:\d+: warning: / } unless RUBY_VERSION < "2.7" + err_lines.reject! {|line| line =~ /\.rb:\d+: warning: / } unless RUBY_VERSION < "2.7" expect(err_lines).to be_empty end diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb index dce2939e83..23db133b67 100644 --- a/spec/bundler/spec_helper.rb +++ b/spec/bundler/spec_helper.rb @@ -113,6 +113,10 @@ RSpec.configure do |config| end end + config.before :each, :sudo => true do + Spec::Sudo.write_safe_config + end + config.after :suite do FileUtils.rm_r Spec::Path.pristine_system_gem_path end diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb index 41b36997b2..a39e46c78a 100644 --- a/spec/bundler/support/path.rb +++ b/spec/bundler/support/path.rb @@ -258,6 +258,10 @@ module Spec end end + def git_root + ruby_core? ? source_root : source_root.parent + end + private def git_ls_files(glob) @@ -278,10 +282,6 @@ module Spec ruby_core? ? "man/bundle* man/gemfile*" : "lib/bundler/man/bundle*.1 lib/bundler/man/gemfile*.5" end - def git_root - ruby_core? ? source_root : source_root.parent - end - def ruby_core_tarball? !git_root.join(".git").directory? end diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index fd5f06b14f..eb7e321080 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -18,6 +18,12 @@ module Spec gem_load_and_activate(gem_name, bin_container) end + def gem_load_and_possibly_install(gem_name, bin_container) + require_relative "switch_rubygems" + + gem_load_activate_and_possibly_install(gem_name, bin_container) + end + def gem_require(gem_name) gem_activate(gem_name) require gem_name @@ -99,9 +105,21 @@ module Spec abort "We couldn't activate #{gem_name} (#{e.requirement}). Run `gem install #{gem_name}:'#{e.requirement}'`" end + def gem_load_activate_and_possibly_install(gem_name, bin_container) + gem_activate_and_possibly_install(gem_name) + load Gem.bin_path(gem_name, bin_container) + end + + def gem_activate_and_possibly_install(gem_name) + gem_activate(gem_name) + rescue Gem::LoadError => e + Gem.install(gem_name, e.requirement) + retry + end + def gem_activate(gem_name) require "bundler" - gem_requirement = Bundler::LockfileParser.new(File.read(dev_lockfile)).dependencies[gem_name]&.requirement + gem_requirement = Bundler::LockfileParser.new(File.read(dev_lockfile)).specs.find {|spec| spec.name == gem_name }.version gem gem_name, gem_requirement end diff --git a/spec/bundler/support/sudo.rb b/spec/bundler/support/sudo.rb index 04e9443945..7b9b392754 100644 --- a/spec/bundler/support/sudo.rb +++ b/spec/bundler/support/sudo.rb @@ -6,6 +6,10 @@ module Spec @which_sudo ||= Bundler.which("sudo") end + def self.write_safe_config + File.write(Spec::Path.tmp("gitconfig"), "[safe]\n\tdirectory = #{Spec::Path.git_root}") + end + def sudo(cmd) raise "sudo not present" unless Sudo.present? sys_exec("sudo #{cmd}") |