summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_installer.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-02-01 11:14:04 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-02-01 11:14:57 +0900
commit600a715c9bde99fe2e9a669465d78833445273e8 (patch)
tree8244622e8cc02b40dd0dad29d30fc60a11342396 /test/rubygems/test_gem_installer.rb
parentadc303131187654d8ce83f3db17eefa3d5bae26c (diff)
Merge the current master branch of rubygems/rubygems.
Just started to develop RubyGems 3.2.0.
Diffstat (limited to 'test/rubygems/test_gem_installer.rb')
-rw-r--r--test/rubygems/test_gem_installer.rb74
1 files changed, 71 insertions, 3 deletions
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 731a1ac01d..eaeff4a8fc 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -744,6 +744,70 @@ gem 'other', version
assert_match(/#{default_shebang}/, shebang_line)
end
+ def test_generate_plugins
+ installer = util_setup_installer do |spec|
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
+ io.write "puts __FILE__"
+ end
+
+ spec.files += %w[lib/rubygems_plugin.rb]
+ end
+
+ build_rake_in do
+ installer.install
+ end
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+
+ FileUtils.rm plugin_path
+
+ installer.generate_plugins
+
+ assert File.exist?(plugin_path), 'plugin not written'
+ end
+
+ def test_keeps_plugins_up_to_date
+ # NOTE: version a-2 is already installed by setup hooks
+
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
+ io.write "puts __FILE__"
+ end
+
+ build_rake_in do
+ util_setup_installer do |spec|
+ spec.version = '1'
+ spec.files += %w[lib/rubygems_plugin.rb]
+ end.install
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+ refute File.exist?(plugin_path), 'old version installed while newer version without plugin also installed, but plugin written'
+
+ util_setup_installer do |spec|
+ spec.version = '2'
+ spec.files += %w[lib/rubygems_plugin.rb]
+ end.install
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+ assert File.exist?(plugin_path), 'latest version reinstalled, but plugin not written'
+ assert_match %r{\Arequire.*a-2/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'written plugin has incorrect content'
+
+ util_setup_installer do |spec|
+ spec.version = '3'
+ spec.files += %w[lib/rubygems_plugin.rb]
+ end.install
+
+ plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+ assert File.exist?(plugin_path), 'latest version installed, but plugin removed'
+ assert_match %r{\Arequire.*a-3/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'written plugin has incorrect content'
+
+ util_setup_installer do |spec|
+ spec.version = '4'
+ end.install
+
+ refute File.exist?(plugin_path), 'new version installed without a plugin while older version with a plugin installed, but plugin not removed'
+ end
+ end
+
def test_initialize
spec = util_spec 'a' do |s|
s.platform = Gem::Platform.new 'mswin32'
@@ -940,7 +1004,13 @@ gem 'other', version
end
def test_install_creates_binstub_that_prefers_user_installed_gem_to_default
- install_default_gems new_default_spec('default', '2')
+ default_spec = new_default_spec('default', '2', nil, 'exe/executable')
+ default_spec.executables = 'executable'
+ install_default_gems default_spec
+
+ exe = File.join @gemhome, 'bin', 'executable'
+
+ assert_path_exists exe, "default gem's executable not installed"
installer = util_setup_installer do |spec|
spec.name = 'default'
@@ -958,8 +1028,6 @@ gem 'other', version
end
end
- exe = File.join @gemhome, 'bin', 'executable'
-
e = assert_raises RuntimeError do
instance_eval File.read(exe)
end