summaryrefslogtreecommitdiff
path: root/test/rubygems/test_rubygems.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2021-08-18 19:37:11 +0900
committernagachika <nagachika@ruby-lang.org>2021-08-19 15:46:40 +0900
commit37f824377fce1bb0fb3ae94f858e2b9417b67b56 (patch)
tree262faa7f44212747afc4b694b0c67165d3f288ca /test/rubygems/test_rubygems.rb
parent41a28637807bef9b15c404c93a778aaa6266ace7 (diff)
Merge RubyGems 3.2.26 and Bundler 2.2.26
Diffstat (limited to 'test/rubygems/test_rubygems.rb')
-rw-r--r--test/rubygems/test_rubygems.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/rubygems/test_rubygems.rb b/test/rubygems/test_rubygems.rb
new file mode 100644
index 0000000000..493b9fdf4a
--- /dev/null
+++ b/test/rubygems/test_rubygems.rb
@@ -0,0 +1,44 @@
+require_relative 'helper'
+
+class GemTest < Gem::TestCase
+ def test_rubygems_normal_behaviour
+ _ = Gem::Util.popen(*ruby_with_rubygems_in_load_path, '-e', "'require \"rubygems\"'", {:err => [:child, :out]}).strip
+ assert $?.success?
+ end
+
+ def test_operating_system_other_exceptions
+ pend "does not apply to truffleruby" if RUBY_ENGINE == 'truffleruby'
+
+ path = util_install_operating_system_rb <<-RUBY
+ intentionally_not_implemented_method
+ RUBY
+
+ output = Gem::Util.popen(*ruby_with_rubygems_and_fake_operating_system_in_load_path(path), '-e', "'require \"rubygems\"'", {:err => [:child, :out]}).strip
+ assert !$?.success?
+ assert_includes output, "undefined local variable or method `intentionally_not_implemented_method'"
+ assert_includes output, "Loading the rubygems/defaults/operating_system.rb file caused an error. " \
+ "This file is owned by your OS, not by rubygems upstream. " \
+ "Please find out which OS package this file belongs to and follow the guidelines from your OS to report " \
+ "the problem and ask for help."
+ end
+
+ private
+
+ def util_install_operating_system_rb(content)
+ dir_lib = Dir.mktmpdir("test_operating_system_lib", @tempdir)
+ dir_lib_arg = File.join dir_lib
+
+ dir_lib_rubygems_defaults_arg = File.join dir_lib_arg, "lib", "rubygems", "defaults"
+ FileUtils.mkdir_p dir_lib_rubygems_defaults_arg
+
+ operating_system_rb = File.join dir_lib_rubygems_defaults_arg, "operating_system.rb"
+
+ File.open(operating_system_rb, 'w') {|f| f.write content }
+
+ File.join dir_lib_arg, "lib"
+ end
+
+ def ruby_with_rubygems_and_fake_operating_system_in_load_path(operating_system_path)
+ [Gem.ruby, "-I", operating_system_path, "-I" , $LOAD_PATH.find{|p| p == File.dirname($LOADED_FEATURES.find{|f| f.end_with?("/rubygems.rb") }) }]
+ end
+end