Top Level Namespace
Instance Method Summary collapse
- #random_date ⇒ Object
- #random_domain ⇒ Object
- #random_email ⇒ Object
- #random_exception ⇒ Object
- #random_hash(options = {}) ⇒ Object
- #random_hexadecimal(options = {}) ⇒ Object
- #random_number(options = {}) ⇒ Object
- #random_query ⇒ Object
- #random_text(options = {}) ⇒ Object
- #random_time ⇒ Object
- #random_url(options = {}) ⇒ Object
Instance Method Details
#random_date ⇒ Object
79 80 81 |
# File 'lib/specstar/support/random.rb', line 79 def random_date random_time.to_date end |
#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_hexadecimal(options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/specstar/support/random.rb', line 28 def random_hexadecimal(={}) length = if [:length] [:length] elsif [:max_length] 1 + rand([:max_length]) elsif [:min_length] [:min_length] + rand(64) else 1 + rand(64) end (1..length).map { '0123456789abcdef'.chars.sample }.join end |
#random_number(options = {}) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/specstar/support/random.rb', line 43 def random_number(={}) output = nil while output.nil? || output == [:except] output = rand([:max] || 1e9) end output end |
#random_query ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/specstar/support/random.rb', line 52 def random_query params = {} (0..rand(10)).each { params[random_text :max_length => 8] = random_text } params.to_param end |
#random_text(options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/specstar/support/random.rb', line 60 def random_text(={}) length = if [:length] [:length] elsif [:max_length] 1 + rand([:max_length]) else 1 + rand(32) end alpha_chars = ("A".."Z").to_a + ("a".."z").to_a chars = alpha_chars + ("0".."9").to_a ([alpha_chars.sample] + (2..length).map { chars.sample }).shuffle.join("") end |
#random_time ⇒ Object
75 76 77 |
# File 'lib/specstar/support/random.rb', line 75 def random_time Time.at rand Time.now.to_i end |
#random_url(options = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/specstar/support/random.rb', line 83 def random_url(={}) domain = .include?(:domain) ? [:domain] : random_domain scheme = .include?(:scheme) ? [:scheme] : ['http', 'https'].sample fragment = .include?(:fragment) ? [:fragment] : random_text query = .include?(:query)? [:query] : random_query uri = URI("#{scheme}://#{domain}") uri.path = "/#{random_text.downcase}" uri.query = query uri.fragment = fragment uri.to_s end |