Comments (8)
So currently when we run
Faker::Internet.email(name: "Alexis O'MConnell")
#=> [email protected]
This might not be what we expect. But I'm not sure what is the correct representation for this?
from faker.
Is it [email protected]
?
from faker.
@keshavbiswa exactly...
So this generator will return all of these possible permutations of the username:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
and the test regex is only validating these possibilities:
alexis.o'[email protected]
o'[email protected]
alexis_o'[email protected]
o'[email protected]
Here is the relevant code that generates these values within Faker::Internet.email
(code edited below for brevity):
def email(name: nil, separators: nil, domain: nil)
local_part = username(specifier: name, separators: separators)
generate_domain = domain_name(domain: domain)
return [local_part, generate_domain].join('@')
end
def username(specifier: nil, separators: %w[. _])
return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase
end
What's happening here is that Faker::Internet.email
will accept a name
and split the string attempting to find the different parts, shuffle the different parts, then join them back together with a random separator of a period or underscore. The issue is the apostrophe in O'Connell
being treated as a word separator and the O
is being independently shuffled as part of the username.
This issue has what appears to be several cascading problems that could be solved different ways:
-
An apostrophe is valid within an email address, so this generator could be adjusted to keep
O'Connell
together and not shuffle theO
within the username, then adjust theemail_regex
to accommodate. This would allow the test to still verify the provided username and returned email address without stripping the apostrophe. -
The
email_regex
could be adjusted to just verify ANY valid email address instead of all possible[email protected]
permutations. However, this would reduce the test suites ability to detect the expected outcome of including the user's full name within the generated email address. -
Strip the apostrophe from the last name within the test suite and just return permutations of
[email protected]
. This will still shuffle last names with an apostrophe when they are provided in real-world scenarios.
from faker.
@keshavbiswa exactly...
So this generator will return all of these possible permutations of the username:
[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
and the test regex is only validating these possibilities:
alexis.o'[email protected] o'[email protected] alexis_o'[email protected] o'[email protected]
Here is the relevant code that generates these values within
Faker::Internet.email
(code edited below for brevity):def email(name: nil, separators: nil, domain: nil) local_part = username(specifier: name, separators: separators) generate_domain = domain_name(domain: domain) return [local_part, generate_domain].join('@') end def username(specifier: nil, separators: %w[. _]) return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase endWhat's happening here is that
Faker::Internet.email
will accept aname
and split the string attempting to find the different parts, shuffle the different parts, then join them back together with a random separator of a period or underscore. The issue is the apostrophe inO'Connell
being treated as a word separator and theO
is being independently shuffled as part of the username.This issue has what appears to be several cascading problems that could be solved different ways:
- An apostrophe is valid within an email address, so this generator could be adjusted to keep
O'Connell
together and not shuffle theO
within the username, then adjust theemail_regex
to accommodate. This would allow the test to still verify the provided username and returned email address without stripping the apostrophe.- The
email_regex
could be adjusted to just verify ANY valid email address instead of all possible[email protected]
permutations. However, this would reduce the test suites ability to detect the expected outcome of including the user's full name within the generated email address.- Strip the apostrophe from the last name within the test suite and just return permutations of
[email protected]
. This will still shuffle last names with an apostrophe when they are provided in real-world scenarios.
I think I'll try the 3rd approach, although apostrophe's are valid, it might still look weird for others, so maybe it's best to keep it simple? Also like you mentioned, it might not be a good idea to verify just any valid email address.
from faker.
On second thought, I feel even the 3rd approach might not be a good idea since we're not covering all the scenarios. Maybe we keep the apostrophe together, do we want [email protected]
, seems incorrect to me.
from faker.
Oh, this is an interesting issue. An apostrophe is not a valid character per Google so I don't think it makes sense keeping it around for the email.
I think it makes sense to just drop the apostrophe when generating the email address and merge it into the last name. Although we could use .
, I don't think it would make sense to split it out of the last name. So dropping it and merging it with the last name seems to be the simplest approach to take. So the only permutations would be:
from faker.
@stefannibrasil It is completely valid to include an apostrophe within an email address and I'd suggest keeping this character within the Faker
email generator. I'd suggest that it's important to guide these decisions based upon the IETF RFC standards.
If you strip out the apostrophe you will still have to accommodate for random test failures when checking with the current Omniauth regex:
def email_regex(first_name, last_name)
/(#{first_name}(.|_)#{last_name}|#{last_name}(.|_)#{first_name})@(.*).(example|test)/i
end
You can get around this issue by also stripping apostrophes from the first and last names within the test data, but generally speaking I think it's an easier fix to include the apostrophe instead of stripping it. Keeping the apostrophe and fixing the broken test seems to be as simple as replacing specifier.scan(/[[:word:]]+/)
with specifier.split
within the Faker::Internet.username
method.
from faker.
Ah, thank you! I was mainly concerned about separating the apostrophe from the last name but confirmed that is handled in the linked PR.
from faker.
Related Issues (20)
- Improve testing of locales files HOT 2
- New generator request: Faker::Company.indian_gst_number HOT 3
- Outdated country names and inconsistencies in en/address.yml HOT 5
- Add benchmarking to faker-ruby HOT 6
- Deprecate Generators with External Calls HOT 3
- Fix/Deprecate `FmaBrotherhood` Generator HOT 2
- Reproducing "Faker::Base#regexify does not work with non-capturing groups or + repeat operator" on v 3.2.1 HOT 2
- `Faker::Time.backward (.forward)` may generate time which is greater (less) than the current time HOT 4
- Fix flaky spec on `TestFakerFile#test_file_name` HOT 6
- Translation missing | en.faker.company.indian_gst_number HOT 6
- Consistent addresses HOT 3
- Drop support for Ruby 2.7 HOT 8
- Invalid GB phone number from `Faker::PhoneNumber.phone_number` HOT 3
- Fake Zip Codes HOT 6
- v3.2.3 correct? HOT 9
- Faker 3.3.0 generating invalid phone numbers HOT 8
- Invalid Timezone: Atlantic/Cabo_Verde HOT 1
- Add option to silence deprecation warnings when running the tests HOT 4
- Add id method to Faker::Internet module HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faker.