This gem is a port of Perl's Data::Faker library that generates fake data.
It comes in very handy for taking screenshots (taking screenshots for my project, Catch the Best was the original impetus for the creation of this gem), having real-looking test data, and having your database populated with more than one or two records while you're doing development.
- While Faker generates data at random, returned values are not guaranteed to be unique by default. You must explicity specify when you require unique values, see details. Values also can be deterministic if you use the deterministic feature, see details
- This is the
master
branch of Faker and may contain changes that are not yet released. Please refer the README of your version for the available methods. List of all versions is available here.
gem install faker
Note: if you are getting a uninitialized constant Faker::[some_class]
error, your version of the gem is behind the one documented here. To make sure that your gem is the one documented here, change the line in your Gemfile to:
gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master'
require 'faker'
Faker::Name.name #=> "Christophe Bartell"
Faker::Internet.email #=> "[email protected]"
Instructions are available in the faker-bot README.
Prefix your method call with unique
. For example:
Faker::Name.unique.name # This will return a unique name every time it is called
If too many unique values are requested from a generator that has a limited
number of potential values, a Faker::UniqueGenerator::RetryLimitExceeded
exception may be raised. It is possible to clear the record of unique values
that have been returned, for example between tests.
Faker::Name.unique.clear # Clears used values for Faker::Name
Faker::UniqueGenerator.clear # Clears used values for all generators
You also can give some already used values to the unique generator if you have collisions with the generated data (i.e: using FactoryBot with random and manually set values).
# Usage:
# Faker::<generator>.unique.exclude(method, arguments, list)
# Add 'azerty' and 'wxcvbn' to the string generator with 6 char length
Faker::Lorem.unique.exclude :string, [6], %w[azerty wxcvbn]
Faker supports seeding of its pseudo-random number generator (PRNG) to provide deterministic output of repeated method calls.
Faker::Config.random = Random.new(42)
Faker::Company.bs #=> "seize collaborative mindshare"
Faker::Company.bs #=> "engage strategic platforms"
Faker::Config.random = Random.new(42)
Faker::Company.bs #=> "seize collaborative mindshare"
Faker::Company.bs #=> "engage strategic platforms"
Faker::Config.random = nil # seeds the PRNG using default entropy sources
Faker::Config.random.seed #=> 185180369676275068918401850258677722187
Faker::Company.bs #=> "cultivate viral synergies"
NOTE: Some of the generators below aren't released yet. If you want to use them, change the line in your gemfile to:
gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master'
- Faker::Address
- Faker::Alphanumeric
- Faker::Ancient
- Faker::App
- Faker::Appliance
- Faker::Artist
- Faker::Avatar
- Faker::Bank
- Faker::Beer
- Faker::Boolean
- Faker::BossaNova
- Faker::Business
- Faker::Cannabis
- Faker::ChileRut
- Faker::ChuckNorris
- Faker::Code
- Faker::Coffee
- Faker::Coin
- Faker::Color
- Faker::Commerce
- Faker::Company
- Faker::Compass
- Faker::Construction
- Faker::Cosmere
- Faker::Crypto
- Faker::CryptoCoin
- Faker::Currency
- Faker::Date
- Faker::DcComics
- Faker::Demographic
- Faker::Dessert
- Faker::Device
- Faker::DrivingLicence
- Faker::Educator
- Faker::ElectricalComponents
- Faker::Esport
- Faker::File
- Faker::Fillmurray
- Faker::Finance
- Faker::Food
- Faker::FunnyName
- Faker::Gender
- Faker::GreekPhilosophers
- Faker::Hacker
- Faker::Hipster
- Faker::House
- Faker::IDNumber
- Faker::IndustrySegments
- Faker::Internet
- Faker::Invoice
- Faker::Job
- Faker::Json
- Faker::Kpop
- Faker::Lorem
- Faker::LoremFlickr
- Faker::LoremPixel
- Faker::Markdown
- Faker::Marketing
- Faker::Measurement
- Faker::Military
- Faker::Name
- Faker::Nation
- Faker::NatoPhoneticAlphabet
- Faker::NationalHealthService
- Faker::Number
- Faker::Omniauth
- Faker::PhoneNumber
- Faker::Placeholdit
- Faker::ProgrammingLanguage
- Faker::Relationship
- Faker::Restaurant
- Faker::Science
- Faker::SlackEmoji
- Faker::Source
- Faker::SouthAfrica
- Faker::Space
- Faker::String
- Faker::Stripe
- Faker::Subscription
- Faker::Superhero
- Faker::Team
- Faker::Time
- Faker::Twitter
- Faker::Types
- Faker::University
- Faker::Vehicle
- Faker::Verbs
- Faker::WorldCup
- Faker::Blockchain::Aeternity
- Faker::Blockchain::Bitcoin
- Faker::Blockchain::Ethereum
- Faker::Blockchain::Tezos
- Faker::Game
- Faker::Games::Dota
- Faker::Games::ElderScrolls
- Faker::Games::Fallout
- Faker::Games::HalfLife
- Faker::Games::Heroes
- Faker::Games::HeroesOfTheStorm
- Faker::Games::LeagueOfLegends
- Faker::Games::Myst
- Faker::Games::Overwatch
- Faker::Games::Pokemon
- Faker::Games::SonicTheHedgehog
- Faker::Games::SuperSmashBros
- Faker::Games::Witcher
- Faker::Games::WorldOfWarcraft
- Faker::Games::Zelda
- Faker::JapaneseMedia::DragonBall
- Faker::JapaneseMedia::OnePiece
- Faker::JapaneseMedia::SwordArtOnline
- Faker::Movie
- Faker::Movies::BackToTheFuture
- Faker::Movies::Ghostbusters
- Faker::Movies::HarryPotter
- Faker::Movies::HitchhikersGuideToTheGalaxy
- Faker::Movies::Hobbit
- Faker::Movies::Lebowski
- Faker::Movies::LordOfTheRings
- Faker::Movies::PrincessBride
- Faker::Movies::StarWars
- Faker::Movies::VForVendetta
- Faker::Music
- Faker::Music::GratefulDead
- Faker::Music::Opera
- Faker::Music::Phish
- Faker::Music::RockBand
- Faker::Music::UmphreysMcgee
- Faker::TvShows::AquaTeenHungerForce
- Faker::TvShows::BojackHorseman
- Faker::TvShows::BreakingBad
- Faker::TvShows::Buffy
- Faker::TvShows::Community
- Faker::TvShows::DrWho
- Faker::TvShows::DumbAndDumber
- Faker::TvShows::FamilyGuy
- Faker::TvShows::Friends
- Faker::TvShows::GameOfThrones
- Faker::TvShows::HeyArnold
- Faker::TvShows::HowIMetYourMother
- Faker::TvShows::MichaelScott
- Faker::TvShows::NewGirl
- Faker::TvShows::ParksAndRec
- Faker::TvShows::RickAndMorty
- Faker::TvShows::RuPaul
- Faker::TvShows::Seinfeld
- Faker::TvShows::SiliconValley
- Faker::TvShows::Simpsons
- Faker::TvShows::SouthPark
- Faker::TvShows::StarTrek
- Faker::TvShows::Stargate
- Faker::TvShows::StrangerThings
- Faker::TvShows::TheExpanse
- Faker::TvShows::TheFreshPrinceOfBelAir
- Faker::TvShows::TheITCrowd
- Faker::TvShows::TheThickOfIt
- Faker::TvShows::TwinPeaks
- Faker::TvShows::VentureBros
Since you may want to make addresses and other types of data look different depending on where in the world you are (US postal codes vs. UK postal codes, for example), Faker uses the I18n gem to store strings (like state names) and formats (US postal codes are NNNNN while UK postal codes are AAN NAA), allowing you to get different formats by switching locales. Just set Faker::Config.locale to the locale you want, and Faker will take care of the rest.
If your locale doesn't already exist, create it in the lib/locales
directory
and you can then override or add elements to suit your needs. See more about how to
use locales here
en-au-ocker:
faker:
name:
# Existing faker field, new data
first_name:
- Charlotte
- Ava
- Chloe
- Emily
# New faker fields
ocker_first_name:
- Bazza
- Bluey
- Davo
- Johno
- Shano
- Shazza
region:
- South East Queensland
- Wide Bay Burnett
- Margaret River
- Port Pirie
- Gippsland
- Elizabeth
- Barossa
See CONTRIBUTING.md.
Comments and feedback are welcome. Send an email to Benjamin Curtis via the google group.
You can also join our discord channel to discuss anything regarding improvements or feature requests.
This code is free to use under the terms of the MIT license.