ruby-changes:61562
From: Yuki <ko1@a...>
Date: Fri, 5 Jun 2020 07:34:44 +0900 (JST)
Subject: [ruby-changes:61562] 77ba8a1d61 (master): [rubygems/rubygems] Use LoadError#path to figure out the argument passed to 'require'
https://git.ruby-lang.org/ruby.git/commit/?id=77ba8a1d61 From 77ba8a1d610114cdaf59993dceeb3ebf6f624436 Mon Sep 17 00:00:00 2001 From: Yuki Nishijima <yk.nishijima@g...> Date: Mon, 25 May 2020 20:34:56 -0400 Subject: [rubygems/rubygems] Use LoadError#path to figure out the argument passed to 'require' https://github.com/rubygems/rubygems/commit/5995394ec4 diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 115ae0c..faf9886 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -148,7 +148,7 @@ module Kernel https://github.com/ruby/ruby/blob/trunk/lib/rubygems/core_ext/kernel_require.rb#L148 RUBYGEMS_ACTIVATION_MONITOR.enter begin - if load_error.message.end_with?(path) and Gem.try_activate(path) + if load_error.path == path and Gem.try_activate(path) require_again = true end ensure diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb index 2b11e26..d1767cb 100644 --- a/test/rubygems/test_require.rb +++ b/test/rubygems/test_require.rb @@ -509,6 +509,33 @@ class TestGemRequire < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_require.rb#L509 assert_equal %w[default-3.0], loaded_spec_names end + def test_normal_gems_with_overridden_load_error_message + normal_gem_spec = util_spec("normal", "3.0", nil, "lib/normal/gem.rb") + + install_specs(normal_gem_spec) + + File.write("require_with_overridden_load_error_message.rb", <<-RUBY) + LoadError.class_eval do + def message + "Overridden message" + end + end + + require 'normal/gem' + RUBY + + require "open3" + + output, exit_status = Open3.capture2e( + { "GEM_HOME" => Gem.paths.home }, + *ruby_with_rubygems_in_load_path, + "-r", + "./require_with_overridden_load_error_message.rb" + ) + + assert exit_status.success?, "Require failed due to #{output}" + end + def test_default_gem_prerelease default_gem_spec = new_default_spec("default", "2.0.0", nil, "default/gem.rb") -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/