summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVít Ondruch <vondruch@redhat.com>2023-11-08 16:10:27 +0100
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-11-09 10:34:48 +0900
commit54547417129b2f3448dddcfba22d3f443f373da4 (patch)
tree7039bbb89c9f651cdfbf67e2b688cbf7383e80ea
parenta1d0c048df2a4bd9fd85bd241fbf343f04ee2ae8 (diff)
[rubygems/rubygems] Use `extension_in_lib` helper instead of custom code
`extension_in_lib` helper improves readibility and it also uses `stub` on on background instead of custom code. https://github.com/rubygems/rubygems/commit/aacc8ac22c
-rw-r--r--test/rubygems/helper.rb8
-rw-r--r--test/rubygems/test_gem_ext_builder.rb63
2 files changed, 33 insertions, 38 deletions
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb
index a9c1438272..b55e526d77 100644
--- a/test/rubygems/helper.rb
+++ b/test/rubygems/helper.rb
@@ -158,6 +158,14 @@ class Gem::TestCase < Test::Unit::TestCase
end
##
+ # Overrides the Gem.install_extension_in_lib function and restores the
+ # original when the block ends
+ #
+ def extension_in_lib(value = true) # :nodoc:
+ Gem.stub(:install_extension_in_lib, value) { yield }
+ end
+
+ ##
# Sets the vendordir entry in RbConfig::CONFIG to +value+ and restores the
# original value when the block ends
#
diff --git a/test/rubygems/test_gem_ext_builder.rb b/test/rubygems/test_gem_ext_builder.rb
index 14b470de97..7e9cd71dc7 100644
--- a/test/rubygems/test_gem_ext_builder.rb
+++ b/test/rubygems/test_gem_ext_builder.rb
@@ -153,54 +153,41 @@ install:
end
def test_build_extensions_install_ext_only
- class << Gem
- alias_method :orig_install_extension_in_lib, :install_extension_in_lib
-
- remove_method :install_extension_in_lib
-
- def Gem.install_extension_in_lib
- false
- end
- end
pend "terminates on mswin" if vc_windows? && ruby_repo?
- @spec.extensions << "ext/extconf.rb"
-
- ext_dir = File.join @spec.gem_dir, "ext"
+ extension_in_lib(false) do
+ @spec.extensions << "ext/extconf.rb"
- FileUtils.mkdir_p ext_dir
+ ext_dir = File.join @spec.gem_dir, "ext"
- extconf_rb = File.join ext_dir, "extconf.rb"
+ FileUtils.mkdir_p ext_dir
- File.open extconf_rb, "w" do |f|
- f.write <<-'RUBY'
- require 'mkmf'
+ extconf_rb = File.join ext_dir, "extconf.rb"
- create_makefile 'a'
- RUBY
- end
+ File.open extconf_rb, "w" do |f|
+ f.write <<-'RUBY'
+ require 'mkmf'
- ext_lib_dir = File.join ext_dir, "lib"
- FileUtils.mkdir ext_lib_dir
- FileUtils.touch File.join ext_lib_dir, "a.rb"
- FileUtils.mkdir File.join ext_lib_dir, "a"
- FileUtils.touch File.join ext_lib_dir, "a", "b.rb"
+ create_makefile 'a'
+ RUBY
+ end
- use_ui @ui do
- @builder.build_extensions
- end
+ ext_lib_dir = File.join ext_dir, "lib"
+ FileUtils.mkdir ext_lib_dir
+ FileUtils.touch File.join ext_lib_dir, "a.rb"
+ FileUtils.mkdir File.join ext_lib_dir, "a"
+ FileUtils.touch File.join ext_lib_dir, "a", "b.rb"
- assert_path_exist @spec.extension_dir
- assert_path_exist @spec.gem_build_complete_path
- assert_path_exist File.join @spec.extension_dir, "gem_make.out"
- assert_path_exist File.join @spec.extension_dir, "a.rb"
- assert_path_not_exist File.join @spec.gem_dir, "lib", "a.rb"
- assert_path_not_exist File.join @spec.gem_dir, "lib", "a", "b.rb"
- ensure
- class << Gem
- remove_method :install_extension_in_lib
+ use_ui @ui do
+ @builder.build_extensions
+ end
- alias_method :install_extension_in_lib, :orig_install_extension_in_lib
+ assert_path_exist @spec.extension_dir
+ assert_path_exist @spec.gem_build_complete_path
+ assert_path_exist File.join @spec.extension_dir, "gem_make.out"
+ assert_path_exist File.join @spec.extension_dir, "a.rb"
+ assert_path_not_exist File.join @spec.gem_dir, "lib", "a.rb"
+ assert_path_not_exist File.join @spec.gem_dir, "lib", "a", "b.rb"
end
end