Top Level Namespace
Instance Method Summary collapse
- #random_domain ⇒ Object
- #random_email ⇒ Object
- #random_exception ⇒ Object
- #random_hash(options = {}) ⇒ Object
- #random_number(options = {}) ⇒ Object
- #random_query ⇒ Object
- #random_text(options = {}) ⇒ Object
- #random_time ⇒ Object
- #random_url(options = {}) ⇒ Object
Instance Method Details
#random_domain ⇒ Object
1 2 3 4 5 6 |
# File 'lib/specstar/support/random.rb', line 1 def random_domain tld = ["com", "org", "net", "biz", "info", "co", "co.in"].sample domain = (0..rand(3)).map { random_text(:max_length => 12).downcase }.join(".") "#{domain}.#{tld}" end |
#random_email ⇒ Object
8 9 10 |
# File 'lib/specstar/support/random.rb', line 8 def random_email "#{random_text}@#{random_text}.com".downcase end |
#random_exception ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/specstar/support/random.rb', line 12 def random_exception begin raise random_text rescue => e e end end |
#random_hash(options = {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/specstar/support/random.rb', line 20 def random_hash(={}) hash = {} elements = [:length] || 1 + rand([:max_length] || 10) elements.times { hash[random_text.to_sym] = random_text } hash end |
#random_number(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/specstar/support/random.rb', line 27 def random_number(={}) output = nil while output.nil? || output == [:except] output = rand([:max] || 1e9) end output end |
#random_query ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/specstar/support/random.rb', line 36 def random_query params = {} (0..rand(10)).each { params[random_text :max_length => 8] = random_text } params.to_param end |
#random_text(options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/specstar/support/random.rb', line 44 def random_text(={}) length = if [:length] [:length] elsif [:max_length] 1 + rand([:max_length]) else 1 + rand(32) end chars = ("A".."Z").to_a + ("a".."z").to_a + ("0".."9").to_a (1..length).map { chars.sample }.join("") end |
#random_time ⇒ Object
58 59 60 |
# File 'lib/specstar/support/random.rb', line 58 def random_time Time.at rand Time.now.to_i end |
#random_url(options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/specstar/support/random.rb', line 62 def random_url(={}) domain = .include?(:domain) ? [:domain] : random_domain scheme = .include?(:scheme) ? [:scheme] : ['http', 'https'].sample fragment = .include?(:fragment) ? [:fragment] : random_text uri = URI("#{scheme}://#{domain}") uri.path = "/#{random_text.downcase}" uri.query = random_query uri.fragment = fragment uri.to_s end |