Created
May 15, 2013 07:49
-
-
Save adambird/5582273 to your computer and use it in GitHub Desktop.
Methods for generating randomised variables for testing purposes
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
def random_string | |
(0...24).map{ ('a'..'z').to_a[rand(26)] }.join | |
end | |
def random_symbol | |
random_string.to_sym | |
end | |
def random_integer | |
rand(9999) | |
end | |
def random_float | |
random_integer + rand | |
end | |
def random_time | |
(Time.now + random_integer.minutes).utc | |
end | |
def random_date | |
Time.new(random_time.year, random_time.month, random_time.day) | |
end | |
def random_email | |
"#{random_string}@#{random_domain}" | |
end | |
def random_domain | |
"#{random_string}.com" | |
end | |
def random_url | |
"http://#{random_string}.#{random_domain}/#{random_string}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment