Skip to content
Merged
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/internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def username(specifier: nil, separators: %w[. _])
with_locale(:en) do
case specifier
when ::String
names = specifier&.gsub("'", '')&.split
names = specifier.gsub("'", '').scan(/[[:word:]]+/)
shuffled_names = shuffle(names)

return shuffled_names.join(sample(separators)).downcase
Expand Down
16 changes: 16 additions & 0 deletions test/faker/default/test_faker_internet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def test_email_with_apostrophes
end
end

def test_email_with_abbreviations
name = 'Mr. Faker'

deterministically_verify -> { @tester.email(name: name) } do |email|
assert_email_regex 'Mr', 'Faker', email
end
end

def test_email_against_name_generator
deterministically_verify -> { @tester.email(name: Faker::Name.unique.name) } do |email|
# reject emails with duplicated punctuation
# e.g.: "mr._faker.jr.@example.com"
refute_match(/[\p{Punct}]{2,}/, email)
end
end

def test_email_with_separators
deterministically_verify -> { @tester.email(name: 'jane doe', separators: '+') } do |result|
name, domain = result.split('@')
Expand Down