Skip to content

Instantly share code, notes, and snippets.

@rtacconi
Created November 14, 2011 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtacconi/1363706 to your computer and use it in GitHub Desktop.
Save rtacconi/1363706 to your computer and use it in GitHub Desktop.
random_data gem was failing to generate unique emails (after ~ 7000 loops), so I decided to add a random number. It passed the test even with 1M loops!
require 'rubygems'
require 'random_data'
require 'spec'
describe "random data" do
it "should be unique" do
prev = RandomUtils.random_email
(1..100000).each do |n|
email = RandomUtils.random_email
puts email
puts "*** #{n} ***"
email.should_not == prev
end
end
end
class RandomUtils
def self.random_number
rand(100000000 + rand(10000 + rand(10000)))
end
def self.random_email
"#{random_number}#{Random.email}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment