
Faker
Faker is a port of Perl's Data::Faker library. It's a library for generating fake data such as names, addresses, and phone numbers.
Faker helps you generate realistic test data, and populate your database with more than a couple of records while you're doing development.
It comes in very handy for taking screenshots (taking screenshots for a personal project) and it was the original impetus for the creation of this gem.
Quick links
In the media
📰 With Great Humor Comes Great Developer Engagement - KTH Royal Institute of Technology research
🎧 Computer und Kommunikation 4.5.2024, komplette Sendung - Deutschland Funk Radio Interview
Table of Contents
Notes
While Faker generates data at random, returned values are not guaranteed to be unique by default. To explicitly specify when you require unique values, see Ensuring Unique Values. Values also can be deterministic if you use the deterministic feature, see Deterministic Random
This is the
main branch of Faker and may contain changes that are not yet released. Please refer to the README of your version for the available methods. The list of all versions is available here.Getting Started
Start by including
faker in your Gemfile:Then run
bundle install.Usage
Here are some examples of how to use Faker:
For a complete list of the generators, see Generators.
A note about the Generators versions
If you get a
uninitialized constant Faker::[some_class] error, your version of the gem is behind main.To make sure that your gem is the one documented here, change the line in your Gemfile to:
The generators have the
@faker.version tag on top of their implementation. From the tags, you can identify the version the generator was added:Ensuring unique values
To ensure Faker generates unique values, prefix your method call with
unique: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.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).
Deterministic Random
Faker supports seeding of its pseudo-random number generator (PRNG) to provide deterministic output of repeated method calls.
Customization
You may want Faker to print information depending on your location in the world. To assist you in this, Faker uses the
I18n gem to store strings and formats to represent the names and postal codes of the area of your choosing.Just set the locale you want as shown below, and Faker will take care of the rest.
To override Faker's locales, and set it on threaded server environments check out the locales README.
Minitest and Faker >= 2.22
To prevent Faker (version >= 2.22) from generating duplicate values when using Minitest, you might need to add the following to the
test_helper.rb or rails_helper.rb file:See Issue #2534 for more details.
Generators
This is the full list of generators available with this gem. If you need details about any of them, make sure to consult the documentation.
NOTE: Some of the generators below aren't released yet. If you want to use them, change the line in your gemfile to:
Default
Blockchain
Books
Fantasy
Travel
Creature
Games
Japanese Media
Movies
Music
Quotes
Sports
Tv Shows
Locations
Contributing
Note: We are not accepting proposals for new generators and locales. The Contributing guide has a few notes about this decision.
Take a look at the Contributing document for instructions on setting up the repo on your machine, opening bug reports, understanding the codebase, and creating a good pull request.
There is a Discord channel to discuss anything regarding improvements or feature requests.
Thank you, contributors!
Versioning
Faker follows Semantic Versioning 2.0 as defined at https://semver.org.
License
This code is free to use under the terms of the MIT license.
0 likes · 28 views · Mar 23, 2025
A library for generating fake data such as names, addresses, and phone numbers. - faker-ruby/faker