stympy/faker

When creating applications, one of the toughest things to do is test and debug. It's only so long before repeating the name "John Doe" a hundred times over for a User gets tiring. Faker is a great way to pre-fill in your records and database with realistic-looking information.

To install, just like Devise, add this line to your Gemfile in the general application folder:

gem 'faker'

For our purposes, Faker will only exist in your seeds.rb file in order. Go ahead and open this file up and stick the following at the top:

seeds.rb

require 'faker'

Within the Faker package, there are several categories that allow us to pull fake data depending on the format/style that we need. The categories range from "Internet" (for usernames, emails, etc.) to Harry Potter (access characters, quotes, etc.).

To access fake data from the "Internet" category, if we have forms that collect information like emails and usernames, we can use this category to pull specific kind of information in the format: Faker::Internet

Then, we can request specific kinds of information. A few examples for Internet are listed below.

Faker::Internet.email #=> "[email protected]"
Faker::Internet.username #=> "alexie"

We can also pass "arguments" into the faker fields to be more specific about the kind of data we want:

Faker::Internet.email('Nancy') #=> "[email protected]"
Faker::Internet.username(5..8) #=> a username of length min=5 and max=8

This is immensely useful for being able to fill out forms. We can also pull some other information from Internet and thousands of others from other categories. Below are some more fun examples:

Faker::MichaelScott.quote #=> "I am Beyoncé, always."
Faker::HarryPotter.house #=> "Gryffindor"
Faker::Color.hex_color #=> "#31a785"