Skip to content
프로젝트

소개

이름, 주소, 전화번호 등의 가짜 데이터를 생성하는 라이브러리입니다.

개발 도구

이 수치를 측정하는 방법

What you can do

  • Internet: Email addresses, Passwords, Domains, etc.
  • Date and Time: Travel back in time or to the future.
  • Person: Names, Genders, Bios, Job titles, and more.
  • Number and String: Random numbers and strings.

측정된 스타 증가

in 24h
+2
in 7 days
+2
in 15 days
+4
in 1 month
-2

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Faker Gem Version Build Status Total Downloads Downloads

Generate (almost) realistic fake data for testing, demos, and populating your database during development.

Quick links

Features

  • Internet: Email addresses, Passwords, Domains, etc.
  • Date and Time: Travel back in time or to the future.
  • Person: Names, Genders, Bios, Job titles, and more.
  • Number and String: Random numbers and strings.
  • Location: Addresses, Zip Codes, Street Names, States, and Countries.
  • Finance: Account Details, Transactions, and Crypto Addresses.
  • Localization - Customize faker with over 40 locales to generate realistic-looking Names, Addresses, and Phone Numbers.

Note: The generated names, addresses, emails, phone numbers, and/or other data might return valid information. Please be careful when using faker in your tests.

For a complete list of the generators, see Generators.

Getting Started

Start by including faker in your Gemfile:

gem 'faker'

Then run bundle install.

Usage

require 'faker'

Faker::Name.name                      #=> "Christophe Bartell"
Faker::Internet.password              #=> "Vg5mSvY1UeRg7"
Faker::Internet.email                 #=> "[email protected]"
Faker::Address.full_address           #=> "5479 William Way, East Sonnyhaven, LA 63637"
Faker::Markdown.emphasis              #=> "Quo qui aperiam. Amet corrupti distinctio. Sit quia *dolor.*"
Faker::Lorem.paragraph                #=> "Recusandae minima consequatur. Expedita sequi blanditiis. Ut fuga et."
Faker::Alphanumeric.alpha(number: 10) #=> "zlvubkrwga"
Faker::ProgrammingLanguage.name       #=> "Ruby"

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. The list of all versions is available here.

Ensuring unique values

To ensure Faker generates unique values, prefix your method call with unique:

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 can also 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).

# Faker::<generator>.unique.exclude(method, arguments, list)

# Add 'azerty' and 'wxcvbn' to the string generator with 6 char length
Faker::Lorem.unique.exclude :string, [number: 6], %w[azerty wxcvbn]

Deterministic Random

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::Lorem.word              #=> "velit"
Faker::Lorem.word              #=> "quisquam"

Faker::Config.random = Random.new(42)
Faker::Lorem.word              #=> "velit"
Faker::Lorem.word              #=> "quisquam"

Faker::Config.random = nil     # seeds the PRNG using default entropy sources
Faker::Config.random.seed      #=> 185180369676275068918401850258677722187
Faker::Lorem.word              #=> "ipsam"

Localization

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.

Faker::Config.locale = 'es'
# or
Faker::Config.locale = :es

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:

Faker::Config.random = Random.new

Generators

To see the full list, check out the GENERATORS document.

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. This is not actively monitored by the current maintainers.

Thank you, contributors!

Versioning

Faker follows Semantic Versioning 2.0 as defined at https://semver.org.

Inspiration

Faker was inspired by Perl's Data::Faker library.

In the media

License

This code is free to use under the terms of the MIT license.

관련 프로젝트 살펴보기

불러오는 중…