Geeks With Blogs

@alexmoore
  • alexmoore Looks like I'm digging a trench this weekend. One of mah favorite things to do. about 310 days ago
  • alexmoore @jpease It kinda looks like a dyson. All it needs is some wheels and a handle. about 311 days ago
  • alexmoore "6 Firewire 2 ports"… Oh god no. about 311 days ago
  • alexmoore Should have been OSX Ocelot. I would have set my hostname to "Babu". about 311 days ago
  • alexmoore Anybody else think it should have been OS X Sea Lion ? about 311 days ago
  • alexmoore Wanted to watch 1984 on Netflix, had to settle for The Hunger Games :'( about 313 days ago
  • alexmoore Playing with LinkedIn Maps over lunch. Not sure what to label these two groups: https://t.co/WSer62T5LH Green-Ruby-ish vs Blue-.Net-ish? about 314 days ago
  • alexmoore @bladesjester It's that shoulder/neck/back muscle, don't know if I have an ace big enough to wrap all those angles. about 315 days ago
  • alexmoore I wonder if I can ducktape the heating pad to my shoulder so it doesn't fall off... about 315 days ago

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 = Faker::Name.name
person_email = Faker::Internet.email
person_company = Faker::Company.name
person_company_slogan = Faker::Company.bs
person_phone = Faker::PhoneNumber.phone_number
person_address = Faker::Address.street_address
person_city = Faker::Address.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_company}
'#{person_company_slogan.capitalize}'
#{person_address}
#{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
end

 


For more information see the Faker Docs: http://faker.rubyforge.org/rdoc/

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.

--Alex

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: GeeksWithBlogs.net | Join free