This gem provides a Random singleton class with a series of methods for generating random test data including names, mailing addresses, dates, phone numbers, e-mail addresses, and text. Instead of:
foo.name = "John Doe"
You get:
foo.name = "#{Random.firstname} #{Random.initial} #{Random.lastname}"
sudo gem install random_data
or get the gem manually from rubyforge.org/frs/?group_id=4458
Random.phone, Random.international_phone, Random.email
Random.date, Random.date_between
Random.address_line_1, Random.address_line_2, Random.zipcode, Random.uk_post_code, Random.state_code, Random.state_full, Random.country, Random.city
Random.firstname, Random.firstname_male, Random.firstname_female, Random.initial, Random.lastname
Random.alphanumeric, Random.paragraphs
Random.grammatical_construct
Random.number, Random.bit, Random.bits
Random.boolean
Random.MarkovGenerator.new Random.MarkovGenerator.insert Random.MarkovGenerator.generate
Array.rand Array.roulette
Random implements a method_missing helper that will choose a line at random from a file in your load path. See Random::method_missing for details.
Note that some methods take parameters to bound or limit the amount of data returned. See RDocs for details.
>>Random.alphanumeric => “cfbutm3vYfhZXil0”
>> Random.alphanumeric(5) => “XYVyn”
>> Random.paragraphs => “Ulysses, fighting evil and tyranny with all his power and with all of his might. Ulysses, fighting evil and tyranny with all his power and with all of his might. nnHe’s got style, a groovy style, and a car that just won’t stop. nn”
>> Random.paragraphs(3) => “Excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum. Down the road that’s where I’ll always be. He’s got style, a groovy style, and a car that just won’t stop. I’ve gotten burned over Cheryl Tiegs and blown up for Raquel Welch, but when I end up in the hay it’s only hay hey hey. Hey there where ya goin, not exactly knowin’. nnLorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. I might jump an open drawbridge or Tarzan from a vine, beause I’m the unknown stuntman that makes Eastwood look so fine. He just keeps on movin’ and ladies keep improvin’. Rolling down to Dallas - who is providin my palace?. Every stop I make I make a new friend; Can’t stay for long just turn around and I’m gone again. nnAlways fighting all the evil forces bringing peace and justice to all. nn”
>> Random.firstname => “Thomas”
>> Random.initial => “E”
>> Random.lastname => “Robinson”
>> Random.date => Sun, 09 Sep 2007
(Returns an actual date object, shown here in its to_s form) >> Random.date(1000) => Sun, 26 Nov 2006
>> Random.email => “[email protected]”
>> Random.phone => “564-103-8353”
>> Random.international_phone => “011-24-37-9704”
>> Random.address_line_1 => “38367 Adams Rd”
>> Random.address_line_2 => “Lot 247”
>> Random.zipcode => 22904
(Note that the zipcodes are totally random and may not be real zipcodes)
>> Random.state_code => “MD”
>> Random.state_full => “New Mexico”
>> Random.country => “Philippines”
Let me know if you have patches, comments, or suggestions: [email protected]
Major thanks to Hugh Sasse and Paul Barry for their contributions.
Copyright © 2008 Mike Subelsky, Baltimore, Maryland, released under the MIT license.