faker-ruby / faker Goto Github PK
View Code? Open in Web Editor NEWA library for generating fake data such as names, addresses, and phone numbers.
License: MIT License
A library for generating fake data such as names, addresses, and phone numbers.
License: MIT License
test body
I created a en-us.yml file with this content
en-us:
faker:
phone_number:
formats:
- "(#{PhoneNumber.area_code}) #{PhoneNumber.exchange_code}-#{PhoneNumber.subscriber_number}"
Then this is what I get:
[1] pry(main)> Faker::Config.locale = 'en-us'
=> "en-us"
[2] pry(main)> Faker::PhoneNumber.cell_phone
=> "(9{PhoneNumber.area_code}) 8{PhoneNumber.exchange_code}-9{PhoneNumber.subscriber_number}"
Any idea why?
Thanks,
SB
The latest version upgrade broke my specs with this error:
uninitialized constant I18n::Backend::Fallbacks (NameError)
Has this been implemented in the current faker released or master branch? I really like these methods and makes it so much easier to use. I can't find these methods any where in the source code.
Loading ja.yml with Syck parser fails:
ArgumentError: syntax error on line 4, col 586: ` state: ["北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県","茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県","新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県","静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県","徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県"]'
Syck is default parser in ruby 1.8.7 and switched on in 1.9.3 by some gems. Even worse, for some unknown reason ja.yml is parsed even if Rails project does not use Japanese locale.
Problem is reproducible without any gems installed. Tested under OSX and Linux.
Assuming ja.yml is in current directory and ruby version is 1.9.3, run in irb:
require 'rubygems'
require 'yaml'
YAML.load_file('ja.yml') # loaded without error
YAML::ENGINE.yamler = 'syck'
YAML.load_file('ja.yml') # throws ArgumentError
Hello!
Just inform that Homepage link from https://rubygems.org/gems/faker is broken.
I'm using the phone library to parse phone numbers, and it does not allow invalidly-formatted phone numbers. An example is that US area codes are not allowed to start with 1
(and 0
, I believe), but Faker will generate numbers with these invalid area codes. Would it be possible to restrict the range of numbers used in generating area codes for Faker phone numbers?
Hi, stympy
I am using the newest version of faker, seems the extension of array method :sample breaks the default ruby :sample when the array is empty and there gives an argument.
Though this example seems a little wired, I really meet this error in my project. Please fix it.
As far as I know this is not valid:
rails [3.2.16]$ Faker::VERSION
=> "1.2.0"
rails [3.2.16]$ Faker::PhoneNumber.cell_phone
=> "903.706.7054 x438"
Using faker (1.2.0) on Rails 4.0.0 I get:
undefined method `Number' for Faker:Module
I am using it to populate my model attribute as such:
:year => Faker::Number.number(4)
Anyone encountered this problem?
irb(main):002:0> Faker::Lorem.words(500).size
=> 249
I had to spend couple of hours before I could figured why my test were failing.
Ideally I would expect lib to throw an error or auto include supplement words if the size of standard words is smaller than requested number of words.
What would be the right way? throw an error or auto include additional words?
When setting the local to the UK
Faker::Config.locale = "en-gb"
Using
Faker::Address.street_address
causes the following error NoMethodError: undefined method 'building_number' for Faker::Address:Class
I tried to set a different locale as follows;
def make_clients
Faker::Config.locale = :fr
99.times do |n|
firstname = Faker::Name.first_name
lastname = Faker::Name.last_name
street = Faker::Address.street_name
house = Faker::Address.building_number
city = Faker::Address.city
zipcode = Faker::Address.zip_code
puts "zipcode: #{zipcode}"
country = Faker::Address.country
password = "password"
Client.create!(firstname: firstname,
lastname: lastname,
street: street,
house: house, zipcode: zipcode,
city: city, country: country)
end
end
The zip code generated was:
zipcode: 79623-1275
rake aborted!
Validation failed: Zipcode is too long (maximum is 5 characters). In France zipcodes are of 5 digits only. How to fix that ?
Thank you.
French names (first and last name) are completely broken: Faker::Name.first_name
always returns the same (extremely long) string.
Tests done with Faker 1.1.2 :
Faker::Address.street_name
=> "Place Faker::Address"
Faker::Address.city
=> ""
Faker::Name.first_name
=> "Enzo Lucas Mathis Nathan Thomas Hugo Théo Tom Louis Raphaël Clément Léo Mathéo Maxime Alexandre Antoine Yanis Paul Baptiste Alexis Gabriel Arthur Jules Ethan Noah Quentin Axel Evan Mattéo Romain Valentin Maxence Noa Adam Nicolas Julien Mael Pierre Rayan Victor Mohamed Adrien Kylian Sacha Benjamin Léa Clara Manon Chloé Camille Ines Sarah Jade Lola Anaïs Lucie Océane Lilou Marie Eva Romane Lisa Zoe Julie Mathilde Louise Juliette Clémence Célia Laura Lena Maëlys Charlotte Ambre Maeva Pauline Lina Jeanne Lou Noémie Justine Louna Elisa Alice Emilie Carla Maëlle Alicia Mélissa"
Faker::Company.buzzwords
=> ["Adaptive", "Advanced", "Ameliorated", "Assimilated", "Automated", "Balanced", "Business-focused", "Centralized", "Cloned", "Compatible", "Configurable", "Cross-group", "Cross-platform", "Customer-focused", "Customizable", "Decentralized", "De-engineered", "Devolved", "Digitized", "Distributed", "Diverse", "Down-sized", "Enhanced", "Enterprise-wide", "Ergonomic", "Exclusive", "Expanded", "Extended", "Face to face", "Focused", "Front-line", "Fully-configurable", "Function-based", "Fundamental", "Future-proofed", "Grass-roots", "Horizontal", "Implemented", "Innovative", "Integrated", "Intuitive", "Inverse", "Managed", "Mandatory", "Monitored", "Multi-channelled", "Multi-lateral", "Multi-layered", "Multi-tiered", "Networked", "Object-based", "Open-architected", "Open-source", "Operative", "Optimized", "Optional", "Organic", "Organized", "Persevering", "Persistent", "Phased", "Polarised", "Pre-emptive", "Proactive", "Profit-focused", "Profound", "Programmable", "Progressive", "Public-key", "Quality-focused", "Reactive", "Realigned", "Re-contextualized", "Re-engineered", "Reduced", "Reverse-engineered", "Right-sized", "Robust", "Seamless", "Secured", "Self-enabling", "Sharable", "Stand-alone", "Streamlined", "Switchable", "Synchronised", "Synergistic", "Synergized", "Team-oriented", "Total", "Triple-buffered", "Universal", "Up-sized", "Upgradable", "User-centric", "User-friendly", "Versatile", "Virtual", "Visionary", "Vision-oriented"]
Hi,
I've this error when calling Faker::Name.name
in a rspec :
I18n::MissingTranslationData:
translation missing: en.faker.name.name_name
There is no error when calling this method from rails console.
I'm using fr
locale via
Faker::Config.locale = 'fr'
It seems all is fine if I switch to en
or it
for example.
Hi all,
thank you for Faker.
I'm using faker 1.1.2 in Rails 4 and it seems I get really long names:
irb(main):013:0> Faker::Name.name
=> "Enzo Lucas Mathis Nathan Thomas Hugo Théo Tom Louis Raphaël Clément Léo Mathéo Maxime Alexandre Antoine Yanis Paul Baptiste Alexis Gabriel Arthur Jules Ethan Noah Quentin Axel Evan Mattéo Romain Valentin Maxence Noa Adam Nicolas Julien Mael Pierre Rayan Victor Mohamed Adrien Kylian Sacha Benjamin Léa Clara Manon Chloé Camille Ines Sarah Jade Lola Anaïs Lucie Océane Lilou Marie Eva Romane Lisa Zoe Julie Mathilde Louise Juliette Clémence Célia Laura Lena Maëlys Charlotte Ambre Maeva Pauline Lina Jeanne Lou Noémie Justine Louna Elisa Alice Emilie Carla Maëlle Alicia Mélissa Martin Bernard Dubois Thomas Robert Richard Petit Durand Leroy Moreau Simon Laurent Lefebvre Michel Garcia David Bertrand Roux Vincent Fournier Morel Girard Andre Lefevre Mercier Dupont Lambert Bonnet Francois Martinez Legrand Garnier Faure Rousseau Blanc Guerin Muller Henry Roussel Nicolas Perrin Morin Mathieu Clement Gauthier Dumont Lopez Fontaine Chevalier Robin Masson Sanchez Gerard Nguyen Boyer Denis Lemaire Duval Joly Gautier Roger Roche Roy Noel Meyer Lucas Meunier Jean Perez Marchand Dufour Blanchard Marie Barbier Brun Dumas Brunet Schmitt Leroux Colin Fernandez Pierre Renard Arnaud Rolland Caron Aubert Giraud Leclerc Vidal Bourgeois Renaud Lemoine Picard Gaillard Philippe Leclercq Lacroix Fabre Dupuis Olivier Rodriguez Da silva Hubert Louis Charles Guillot Riviere Le gall Guillaume Adam Rey Moulin Gonzalez Berger Lecomte Menard Fleury Deschamps Carpentier Julien Benoit Paris Maillard Marchal Aubry Vasseur Le roux Renault Jacquet Collet Prevost Poirier Charpentier Royer Huet Baron Dupuy Pons Paul Laine Carre Breton Remy Schneider Perrot Guyot Barre Marty Cousin"
Faker::Company.name returns "" (empty string) always. I tried with :pl and :en locale.
Faker::Config.locale attempts to use downcase, a method that isn't isn't present in Ruby v1.8.7 but in v1.9+:
module Faker
class Config
@locale = nil
class << self
attr_writer :locale
def locale
@locale || I18n.locale.downcase
end
end
git-commit-notifier works around this issue like so:
One commited spanish locale to node.js port or Faker. https://github.com/nodeca/charlatan/tree/master/lib/locales . Feel free to take back into your mainstream :) .
using Rails 3.2.3 / Ruby 1.9.3
tested in console :
re = /^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}$/
re.class
=> Regexp
Faker::Base.regexify(re)
NoMethodError: undefined method []' for nil:NilClass from /Users/yves/.rvm/gems/ruby-1.9.3-p125@rails32/gems/faker-1.0.1/lib/faker.rb:89:in
method_missing'
I forked Faker and removed the comments in the regexify(re) method .., then tested again :
re = /^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}$/
re.class
=> Regexp
Faker::Base.regexify(re)
=> "ZOM 6BB"
In Faker::Config.locale the value from I18n.locale is downcased. This is the source for failures if regional extensions are used, which are usually uppercase (e.g. de-CH). So the correct implementation should be:
@Locale || I18n.locale
If a phone number starts with 911, phony_rails, a gem dedicated to validating phone numbers, reports that the Faker-produced number is invalid. The gem is correct and no number that begins with 911 should be created by Faker.
Is there any reason to continue producing numbers beginning with 911?
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
with ruby 1.9.3p194 (2012-04-20) [i386-mingw32]
Will try and push a demo app with test tomorrow if I get time. However, (quick and dirty) steps to reproduce are:
gem 'rails'
and gem 'faker'
;bundle install
;script/console
;"%{a}" % {:a => 1}
The result will be:
ArgumentError: malformed format string - %{
from (irb):1:in `%'
from (irb):1
The various :require => nil
and I18n.reload!
workarounds suggested in issue 5 do not seem to sort the problem.
2.0.0-p247 > Faker::Address.postcode
=> "R3V 9JY"
There are two space characters, when there should only be one. So far I've only encountered this for postcodes in the UK.
Hi,
I think Faker should implement something like a Provider to provides coherent objects.
#Easy example
user = Faker::User
user.firstname #Gina
user.gender #female
The firstname and the gender are coherent.
#Really complex example
addr = Faker::Address
addr.lattitude=48.858545
addr.longitude=2.294470
addr.fullAdress=Champ de Mars 5 Avenue Anatole France 75007 Paris
The GPS and the adress are coherent.
UPDATE:
Duh! I am stupid. :ru is not part of 1.2.0 release. misunderstanding
Issue:
env
ruby 2.0
faker 1.2.0
I18n 0.6.9)
test in irb:
require 'faker'
Faker::Config.locale = :ru
Faker::Name.name
I would appreciate if somebody can tell me if they see the same issue in irb. I may be going mad because the spec tests pass but in regular usage I don't get the russian strings.
I'd like Faker::Internet.password to contain digits and/or capital letters if needed.
What do you think about this idea?
Faker::Internet.user_name
uses localized Faker::Name.first_name
/ last_name
and eliminates accented alphabets by gsub(/\W/, '')
, but as Japanese is non-alphabet script, it removes almost all characters from generated names.
Result: Faker::Internet.user_name
returns only "."
, "_"
and ""
.
I think it would be nice to make Faker::Lorem methods to accept Range as argument what will generate a random number of words within a range.
Example:
Faker::Lorem.words(3..5) # generated from 3 to 5 words
[master] ~/dev/my_proj → irb
ruby-1.9.2-p290 :001 > require 'faker'
=> true
ruby-1.9.2-p290 :002 > Faker::Lorem.url
NoMethodError: undefined method []' for nil:NilClass from /Volumes/HDDisk/Users/jetienne/.rvm/gems/ruby-1.9.2-p290/gems/faker-1.0.1/lib/faker.rb:89:in
method_missing'
from (irb):2
from /Volumes/HDDisk/Users/jetienne/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `
I get the following error when calling Faker::Address.uk_county
:
NameError: undefined local variable or method `county' for Faker::Address:Class
Had a look at the source code at https://github.com/stympy/faker/blob/master/lib/faker/address.rb#L48 and it seems the uk_county method calls indeed a local variable county that is not defined. As the method is flagged as depreciated it looks like this might be a typo and should actually return a country, right?
Hi, this is my first GITHUB post and I am new to ruby so please bear with me. I have looked through the issues logged about faker and have spotted this issue reported previously and fixed. However, having checked I am on the latest version of faker (1.2.0) I am still getting these problems.
My development environment is as follows:
If I run IRB and setup the local for UK then generate a postcode you can see below that it has produced a postcode with two spaces:
rails console
Loading development environment (Rails 4.0.2)
1.9.3p448 :001 > Faker::Config.locale = 'en-gb'
=> "en-gb"
1.9.3p448 :002 > Faker::Address.postcode
=> "WM5 6JY"
Having run this several more times I get the following results:
=> "YS3 8BA" [ Invalid ]
=> "I78 6DJ" [ Invalid ]
=> "YH7 4FN" [ Valid ]
=> "S6H 9PU" [ Valid ]
=> "Y4V 9YP" [ Valid ]
=> "ZE1 1LN" [ Valid ]
=> "W1 2QB" [ Invalid ]
=> "GD7X 7GA" [ Invalid ]
=> "S35 7AL" [ Invalid ]
=> "W9N 0JR" [ Valid ]
=> "G0 5BJ" [ Valid ]
=> "TL8 5BL" [ Invalid ]
=> "YF9P 3DJ" [ Invalid ]
=> "YG9W 9LL" [ Valid ]
The results are bizarre because it does produce both valid and invalid formats that follow the same postcode standards.
For example,
"YS3 8BA" and "YH7 4FN" are both in the format AAN NAA, yet one has a single space and the other has 2 spaces.
"GD7X 7GA" and "YG9W 9LL" are both in the format AANA NAA and again one has a single space and the other has 2 spaces.
I can get around this using the squeeze method as suggested by one of the other posters but thought I should report the bug because the fix doesn't seem to have worked.
Faker::Address.postcode.squeeze(" ")
I checked that the regular expression you are using in Faker to see if it would return invalid for postcodes with 2 spaces (in the correct format). The regex you are using is as follows:
[A-PR-UWYZ][A-HK-Y]?[0-9][ABEHMNPRVWXY0-9]? [0-9][ABD-HJLN-UW-Z]{2}
I checked this using Rubular and Expresso tools using the postcode "US6P 7AD" and both indicated this does not match the regex. Removing the space does produce a valid match.
This is the regex I've been using to validate them:
/^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$/
Which seems to be the correct one, as taken from StackOverflow
Faker generated BI56 3QX
for me, which when you search in Google Maps is not recognised.
Faker should not change I18n locale (however this can be easly fixed by setting Faker::Config.locale).
Other problem after updating faker gem, when running specs in rails application is lots of failing tests:
Expected errors to include "translation missing: en.errors.messages.blank" when user_id is set to nil, got errors: user_id translation missing: en.activerecord.errors.models.billing.attributes.user_id.blank (nil)app_id translation missing: en.activerecord.errors.models.billing.attributes.app_id.blank (nil)
Rails 2.3.10, Ruby ree-1.8.7-2010.02
Using faker in a gem that I test/use on 1.8.7 and REE, I got a weird stack trace parsing the Japanese YAML file. Don't have 1.8.7 locally ATM, so forked the repo and set it up on Travis:
http://travis-ci.org/#!/davetron5000/faker/jobs/2473018
Basically, calls to translate
load all(?) the YAML files, and they are in a format incompatible with 1.8.7/REE. I will try to look into it when I'm not in the air and can install 1.8.7, but am logging this anyway, in case someone else sees an obvious solution.
Hello,
fix_umlauts is currently implemented this way:
def fix_umlauts(string)
string.gsub(/[äöüß]/i) do |match|
case match.downcase
when "ä" 'ae'
when "ö" 'oe'
when "ü" 'ue'
when "ß" 'ss'
end
end
end
This should be extended so that characters like é, â, ç etc. are also replaced with their respective non-accented variants. E.g.
def fix_umlauts(string)
string.gsub(/[äöüß]/i) do |match|
case match.downcase
when "ä" 'ae'
when "ö" 'oe'
when "ü" 'ue'
when "ß" 'ss'
end
end
string.parameterize # requires Rails ActiveSupport, however
end
Hi,
I had some strange ActionView template rendering exceptions, in a fat Rails application, that were caused by some problems with the en-au.yml locale. I verified in all known to me ways that my app is configured to use utf8 encoding, but the problem persisted. Then I took a radical action and removed directly all sections in the yml file that looked strange to me. After a couple of iterations with this ugly cutting, going through Brazilian Portuguese and French, issue was gone.
I am not sure whether this is an issue with the faker gem or not, but just wanted to let you know. I executed Linux's file info commands and they displayed 'character encoding:unknown' when run against some of the locales. Are all locales files utf8 compliant ?
The exact error message is:
ActionView::Template::Error ((.../WEB-INF/gems/gems/faker-1.0.1/lib/locales/pt-br.yml): 'reader' unacceptable character '�' (0x81) special characters are not allowed|
Kindest Regards,
Krum.
They point to v0.3.1.
I'm interested in using faker to fake other data. Specifically, I would like to use it in a situation more like a MadLib, but not for those purposes specifically.
I'd like a way to be able to create adjectives, nouns, verbs etc, and this seems like a reasonable library for including something like this. I made some changes to a copy of faker locally for my purposes, and didn't know if it would be worth pulling back into the project.
Let me know.
I tried to set up a locale as suggested:
Faker::Config.locale = :fr
I tried to do that in 2 different ways:
require 'faker'
...
RSpec.configure do |config|
...
Faker::Config.locale = :fr
...
end
require 'spec_helper'
require 'faker'
describe ClientsController do
before { Faker::Config.locale = :fr }
...
end
In both cases the country value was NOT correct:
etc.
The only solution I found was to set a country as follows in my Factory file:
factory :client do
...
country { Faker::Address.default_country }
....
end
Is it a right way ?
Any idea ?
Thank you.
Produced with faker version 1.3.0, Ruby 2.0.0, Windows XP box.
I'm not sure why, but Faker::Lorem::characters doesn't always return the correct number of characters.
Observe:
irb(main):001:0> (1..10).map { Faker::Lorem.characters(256).length == 256 }
=> [true, true, true, false, true, true, true, false, true, true]
Was using Faker with Rails 2.3.5 and everything was OK. After updating to 2.3.10 I get this error:
ree-1.8.7-2010.02 :002 > Faker::Lorem.words NoMethodError: undefined method `shuffle' for "translation missing: pt.faker.lorem.words":String from /Users/lucashungaro/.rvm/gems/ree-1.8.7-2010.02@viaranking/gems/faker-0.9.5/lib/faker/lorem.rb:5:in `words' from (irb):2
Example output:
>> require 'faker'
=> true
>> Faker::Number.number(9)
=> "1077253297"
>> Faker::Number.number(9).length
=> 10
It is using only Poznań area code - see https://en.wikipedia.org/wiki/Telephone_numbers_in_Poland#National_area_codes
Mobile numbers are never generated - see https://en.wikipedia.org/wiki/Telephone_numbers_in_Poland#Mobile_numbers
require 'faker'
def check
for i in 1..1000
puts Faker::PhoneNumber.phone_number
end
end
check
Faker::Config.locale = "pl"
sleep 1
check
First names and last names for FR locale are not working correctly on the Rubygems version since it's the 1.1.2 and it does not include commit 5fbaedc.
Would be great not to run into this not-so-evident-issue when using the Rubygems version.
Thanks in advance!
Faker::Internet.user_name("Łucja")
returns
ucja
I would expect it to return
lucja
Affected signs: ą, Ą ć Ć ę Ę ł Ł ń Ń ó Ó ś Ś ź Ź ż Ż
Commonly accepted and widespread method of dealing with inability of many systems to use proper UTF-8 is to replace this letters with closest ASCII letter.
As explained here: http://en.wikipedia.org/wiki/Table_of_administrative_country_subdivisions_by_country, each country has its own administrative subdivision. These subdivision can be grouped in 3 levels (the fourth usually matches with the city name).
When making a data structure to contain international addresses, is usefull to follow these subdivisions.
It should be easy to add administrative_level1, administrative_leve2 and administrative_leve3 generators to Faker::Address.
The current generators applies well only for US.
What do you think about?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.