Skip to content

Commit 9a85907

Browse files
Refactor some logic to create extconf files for tests
1 parent 395df77 commit 9a85907

2 files changed

Lines changed: 21 additions & 37 deletions

File tree

test/rubygems/helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,14 @@ def write_file(path)
683683
path
684684
end
685685

686+
def write_dummy_extconf(gem_name)
687+
write_file File.join(@tempdir, "extconf.rb") do |io|
688+
io.puts "require 'mkmf'"
689+
yield io if block_given?
690+
io.puts "create_makefile '#{gem_name}'"
691+
end
692+
end
693+
686694
##
687695
# Load a YAML string, the psych 3 way
688696

test/rubygems/test_gem_installer.rb

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,12 +1478,7 @@ def test_install_extension_dir
14781478

14791479
@spec = setup_base_spec
14801480
@spec.extensions << "extconf.rb"
1481-
write_file File.join(@tempdir, "extconf.rb") do |io|
1482-
io.write <<-RUBY
1483-
require "mkmf"
1484-
create_makefile("#{@spec.name}")
1485-
RUBY
1486-
end
1481+
write_dummy_extconf @spec.name
14871482

14881483
@spec.files += %w[extconf.rb]
14891484

@@ -1503,12 +1498,7 @@ def test_install_extension_dir_is_removed_on_reinstall
15031498
@spec = setup_base_spec
15041499

15051500
@spec.extensions << "extconf.rb"
1506-
write_file File.join(@tempdir, "extconf.rb") do |io|
1507-
io.write <<-RUBY
1508-
require "mkmf"
1509-
create_makefile("#{@spec.name}")
1510-
RUBY
1511-
end
1501+
write_dummy_extconf @spec.name
15121502

15131503
@spec.files += %w[extconf.rb]
15141504

@@ -1539,12 +1529,7 @@ def test_install_extension_dir_is_removed_on_reinstall
15391529
def test_install_user_extension_dir
15401530
@spec = setup_base_spec
15411531
@spec.extensions << "extconf.rb"
1542-
write_file File.join(@tempdir, "extconf.rb") do |io|
1543-
io.write <<-RUBY
1544-
require "mkmf"
1545-
create_makefile("#{@spec.name}")
1546-
RUBY
1547-
end
1532+
write_dummy_extconf @spec.name
15481533

15491534
@spec.files += %w[extconf.rb]
15501535

@@ -1571,15 +1556,13 @@ def test_find_lib_file_after_install
15711556

15721557
@spec = setup_base_spec
15731558
@spec.extensions << "extconf.rb"
1574-
write_file File.join(@tempdir, "extconf.rb") do |io|
1559+
write_dummy_extconf @spec.name do |io|
15751560
io.write <<-RUBY
1576-
require "mkmf"
15771561
15781562
CONFIG['CC'] = '$(TOUCH) $@ ||'
15791563
CONFIG['LDSHARED'] = '$(TOUCH) $@ ||'
15801564
$ruby = '#{Gem.ruby}'
15811565
1582-
create_makefile("#{@spec.name}")
15831566
RUBY
15841567
end
15851568

@@ -1618,12 +1601,7 @@ def test_install_extension_and_script
16181601

16191602
@spec = setup_base_spec
16201603
@spec.extensions << "extconf.rb"
1621-
write_file File.join(@tempdir, "extconf.rb") do |io|
1622-
io.write <<-RUBY
1623-
require "mkmf"
1624-
create_makefile("#{@spec.name}")
1625-
RUBY
1626-
end
1604+
write_dummy_extconf @spec.name
16271605

16281606
rb = File.join("lib", "#{@spec.name}.rb")
16291607
@spec.files += [rb]
@@ -1663,15 +1641,13 @@ def test_install_extension_flat
16631641

16641642
@spec.extensions << "extconf.rb"
16651643

1666-
write_file File.join(@tempdir, "extconf.rb") do |io|
1644+
write_dummy_extconf @spec.name do |io|
16671645
io.write <<-RUBY
1668-
require "mkmf"
16691646
16701647
CONFIG['CC'] = '$(TOUCH) $@ ||'
16711648
CONFIG['LDSHARED'] = '$(TOUCH) $@ ||'
16721649
$ruby = '#{Gem.ruby}'
16731650
1674-
create_makefile("#{@spec.name}")
16751651
RUBY
16761652
end
16771653

@@ -1698,13 +1674,13 @@ def test_install_extension_clean_intermediate_files
16981674
@spec.require_paths = ["."]
16991675
@spec.extensions << "extconf.rb"
17001676

1701-
File.write File.join(@tempdir, "extconf.rb"), <<-RUBY
1702-
require "mkmf"
1703-
CONFIG['CC'] = '$(TOUCH) $@ ||'
1704-
CONFIG['LDSHARED'] = '$(TOUCH) $@ ||'
1705-
$ruby = '#{Gem.ruby}'
1706-
create_makefile("#{@spec.name}")
1707-
RUBY
1677+
write_dummy_extconf @spec.name do |io|
1678+
io.write <<~RUBY
1679+
CONFIG['CC'] = '$(TOUCH) $@ ||'
1680+
CONFIG['LDSHARED'] = '$(TOUCH) $@ ||'
1681+
$ruby = '#{Gem.ruby}'
1682+
RUBY
1683+
end
17081684

17091685
# empty depend file for no auto dependencies
17101686
@spec.files += %W[depend #{@spec.name}.c].each do |file|

0 commit comments

Comments
 (0)