Created
November 14, 2011 10:42
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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