Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/faker/default/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def available_methods
def generate_table_row(tag, cell_count)
row = "<tr>\n"
cell_count.times do
row += "<#{tag == 'th' ? 'th' : 'td'}>#{Lorem.word}</#{tag == 'th' ? 'th' : 'td'}>\n"
row += "<#{tag == 'th' ? 'th' : 'td'}>#{Faker::Lorem.word}</#{tag == 'th' ? 'th' : 'td'}>\n"
end
row += "</tr>\n"
row
Expand Down
18 changes: 18 additions & 0 deletions test/faker/default/test_faker_html.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'open3'
require 'rbconfig'
require_relative '../../test_helper'

class TestFakerHTML < Test::Unit::TestCase
Expand Down Expand Up @@ -51,6 +53,22 @@ def test_table
assert_equal(12, count_occurrences(table_html, '<td>'))
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, '<th>')
assert_equal 12, count_occurrences(output, '<td>')
assert_equal 5, count_occurrences(output, '<tr>')
end

def test_script
assert_match(/<script src=".+"><\/script>/, @tester.script)
end
Expand Down