From c5e9c8133098daeba03e3a43cb26c758f08709ff Mon Sep 17 00:00:00 2001 From: sergioperezcheco Date: Thu, 15 Oct 2026 11:34:57 +0800 Subject: [PATCH] Fix HTML table generation with lazy loading Resolve Lorem through Faker's existing lazy loader when generating table cells. Exercise the documented API in a fresh process so earlier tests cannot mask the unresolved constant. Assisted-by: Hermes Agent Signed-off-by: sergioperezcheco --- lib/faker/default/html.rb | 2 +- test/faker/default/test_faker_html.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/faker/default/html.rb b/lib/faker/default/html.rb index bf94c2b1d9..2630b277ef 100644 --- a/lib/faker/default/html.rb +++ b/lib/faker/default/html.rb @@ -220,7 +220,7 @@ def available_methods def generate_table_row(tag, cell_count) row = "\n" cell_count.times do - row += "<#{tag == 'th' ? 'th' : 'td'}>#{Lorem.word}\n" + row += "<#{tag == 'th' ? 'th' : 'td'}>#{Faker::Lorem.word}\n" end row += "\n" row diff --git a/test/faker/default/test_faker_html.rb b/test/faker/default/test_faker_html.rb index 69235a03ed..bfd5af5fb7 100644 --- a/test/faker/default/test_faker_html.rb +++ b/test/faker/default/test_faker_html.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'open3' +require 'rbconfig' require_relative '../../test_helper' class TestFakerHTML < Test::Unit::TestCase @@ -51,6 +53,22 @@ def test_table assert_equal(12, count_occurrences(table_html, '')) end + def test_table_with_lazy_loading + # A fresh process ensures another generator has not already loaded Lorem. + code = <<~RUBY + require 'faker' + abort 'Lorem was already loaded' if Faker.const_defined?(:Lorem, false) + puts Faker::HTML.table + RUBY + lib_dir = File.expand_path('../../../lib', __dir__) + output, status = Open3.capture2e({ 'FAKER_LAZY_LOAD' => '1' }, RbConfig.ruby, "-I#{lib_dir}", '-e', code) + + assert_predicate status, :success?, output + assert_equal 3, count_occurrences(output, '') + assert_equal 12, count_occurrences(output, '') + assert_equal 5, count_occurrences(output, '') + end + def test_script assert_match(/