Sha256: 9b29836a04eb002bd5d96fe2dd73cf93e0250f9144f61949124ed559c5bfe2ae

Contents?: true

Size: 746 Bytes

Versions: 70

Compression:

Stored size: 746 Bytes

Contents

# require "eitil_core/mocks/array"

class Array

  def self.mock(n=10, type=Integer, &block)
    
    return Array.new(n,&block) if block_given?
    
    case type.to_s
    
    when 'Integer'
      Array.new(n) {|i| i+1}
    
    when 'Float'
      Array.new(n) {|i| i+1.0}
   
    when 'String'
      words = String.mock(n).split
      Array.new(n) {|i| words[i]}
   
    when 'Time'
      time_now = Time.now
      Array.new(n) {|i| time_now + (i * (60 * 60 * 24)) }
   
    when 'Date'
      date_now = Date.today
      Array.new(n) {|i| date_now + (i * 1) }
   
    else
      Array.new(n) do 
        type.send(:new) rescue
          raise NoNewMethodError, 'Please provide Object that responds to `new` call'
      end
    end

  end

end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
eitil-1.1.8 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.1.7 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.1.6 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.1.5 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.1.4 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.1.3 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.1.2 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.1.1 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.1.0 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.0.4 eitil_core/lib/eitil_core/mocks/array.rb