Geeks With Blogs
Enginerding Alex Moore

One of the first ruby gems I used was the Faker Gem, a nice little ruby gem that ...wait for it... Fakes Data!

Usage is simple; first grab the gem using your gem program:

$sudo gem install faker

Now you can use it in your favorite ruby program or script. For now let's fire up irb and see what we can fake. 

require 'rubygems'
require 'faker'
#Let's see if we can make a fake person...
person_name =
person_email =
person_company =
person_company_slogan =
person_phone = Faker::PhoneNumber.phone_number
person_address = Faker::Address.street_address
person_city =
person_state = Faker::Address.us_state
person_zip = Faker::Address.zip_code
# Wowee-wow-wow. Now let's print him off some business cards
puts "#{person_name}
#{person_city}, #{person_state} #{person_zip}
Call me at : #{person_phone}
Email me at: #{person_email}
It's a pleasure doing business."
# Awesome, now we can go into business and
# get back our money from that Nigerian prince fellow...


As you can see Faker is pretty easy to use; you can build some powerful test bases using it inside a loop:

require 'rubygems'
require 'faker'
require 'activerecord'
1000.times do
  # make a person
  # save person


For more information see the Faker Docs:

In my next post I will show you how you can use all this fake data you're generating to test anything you need data for.


Posted on Monday, January 18, 2010 7:57 PM Ruby | Back to top

Comments on this post: Faker Gem - A Quick and Dirty Introduction

# re: Faker Gem - A Quick and Dirty Introduction
Requesting Gravatar...
Waseem Saddique - Online Marketing, PPC and SEO
Left by Waseem Saddique Brazil on Mar 07, 2011 12:47 PM

Your comment:
 (will show your gravatar)

Copyright © Alex Moore | Powered by: | Join free