Faker: How to avoid special characters in faker string field

Created on 26 Jun 2016  路  6Comments  路  Source: faker-ruby/faker

I used faker to dump data. But i don't want special character in faker data. Sometimes Faker::Name.first_name return data with single quotes.

Example :
Faker::Name.first_name -> "O'Hara"

Most helpful comment

Maybe use something like

Faker::Name.first_name.gsub(/\W/, '')

since it's returning a string

All 6 comments

@elangovan91 Here data is coming from here

And if you don't want special characters to be present in name I think this name should be removed from fake data but that is valid name and currently I didn't find option to reject such names.

Sometimes having special characters in test data can make your code more robust if it can deal with those. I would argue there aren't enough special characters

Maybe use something like

Faker::Name.first_name.gsub(/\W/, '')

since it's returning a string

Thank You guys for your suggestion. @Jack-Barry I used your concept.

In case of filename, I replaced the special character with alternative character using this: randomFileName = getFaker().file().fileName().replace("\",randomFileNameDelimiter);

It seems really odd, that I have to add this...

    first_name { Faker::Name.last_name.gsub(/\W/, '').gsub("\u0000", '') }
    last_name { Faker::Name.last_name.gsub(/\W/, '').gsub("\u0000", '') }

to guarantee these work correctly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

huyderman picture huyderman  路  4Comments

ggrillone picture ggrillone  路  6Comments

CJAdeszko picture CJAdeszko  路  6Comments

benpolinsky picture benpolinsky  路  5Comments

zyrthofar picture zyrthofar  路  6Comments