Skip to content
Permalink
Browse files

[Require] Call #gem explicitly on Kernel

This avoids conflicts if #gem happens to be defined on self
  • Loading branch information...
segiddins committed Jan 22, 2017
1 parent 4c0dc4b commit 439c4464890958fec17b3aa65b9d3a4dbdd3bf90
Showing with 26 additions and 1 deletion.
  1. +1 −1 lib/rubygems/core_ext/kernel_require.rb
  2. +25 −0 test/rubygems/test_require.rb
@@ -43,7 +43,7 @@ def require path

if spec = Gem.find_unresolved_default_spec(path)
Gem.remove_unresolved_default_spec(spec)
gem(spec.name)
Kernel.send(:gem, spec.name)
end

# If there are no unresolved deps, then we can use just try
@@ -341,6 +341,31 @@ class << ::Gem
Kernel::RUBYGEMS_ACTIVATION_MONITOR.exit
end

def test_require_when_gem_defined
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
install_default_specs(default_gem_spec)
c = Class.new do
def self.gem(*args)
raise "received #gem with #{args.inspect}"
end
end
assert c.send(:require, "default/gem")
assert_equal %w(default-2.0.0.0), loaded_spec_names
end

def test_require_default_when_gem_defined
a = new_spec("a", "1", nil, "lib/a.rb")
install_specs a
c = Class.new do
def self.gem(*args)
raise "received #gem with #{args.inspect}"
end
end
assert c.send(:require, "a")
assert_equal %w(a-1), loaded_spec_names
end

def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, false
yield

0 comments on commit 439c446

Please sign in to comment.
You can’t perform that action at this time.