Skip to content

Commit

Permalink
[rubygems/rubygems] Also load user installed rubygems plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and hsbt committed Aug 31, 2021
1 parent 21db587 commit 9fa5c4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rubygems.rb
Expand Up @@ -1050,7 +1050,9 @@ def self.load_plugin_files(plugins) # :nodoc:
# Find rubygems plugin files in the standard location and load them

def self.load_plugins
load_plugin_files Gem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}", plugindir)
Gem.path.each do |gem_path|
load_plugin_files Gem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}", plugindir(gem_path))
end
end

##
Expand Down
25 changes: 25 additions & 0 deletions test/rubygems/test_gem.rb
Expand Up @@ -1578,6 +1578,31 @@ def test_load_plugins
assert_equal %w[plugin], PLUGINS_LOADED
end

def test_load_user_installed_plugins
plugin_path = File.join "lib", "rubygems_plugin.rb"

Dir.chdir @tempdir do
FileUtils.mkdir_p 'lib'
File.open plugin_path, "w" do |fp|
fp.puts "class TestGem; PLUGINS_LOADED << 'plugin'; end"
end

foo = util_spec 'foo', '1' do |s|
s.files << plugin_path
end

install_gem_user foo
end

Gem.paths = { "GEM_PATH" => [Gem.dir, Gem.user_dir].join(File::PATH_SEPARATOR) }

gem 'foo'

Gem.load_plugins

assert_equal %w[plugin], PLUGINS_LOADED
end

def test_load_env_plugins
with_plugin('load') { Gem.load_env_plugins }
assert_equal :loaded, TEST_PLUGIN_LOAD rescue nil
Expand Down

0 comments on commit 9fa5c4c

Please sign in to comment.