lib/service_contract/mock.rb
# generates fake data that adheres to the types defined in the service contract
generates fake data that adheres to the types defined in the service contract
generates fake data that adheres to the types defined in the service contract
def mock_value(field)
        if field.array?
          Array.new(3) do
            mock_value(field.subtype)
          end
        elsif field.complex?
          mock_fields(field)
        else
          case field.name
          when "int", :int
            Random.new.rand(10000000)
          when "string", :string
            RandomWord.nouns.next
          when "float", :float
            Random.new.rand(10000.0)
          when "boolean", :boolean
            [true, false].sample
          end
        end        
      end
def mock_value ( field ) if field . array? Array . new ( 3 ) do mock_value ( field . subtype ) end elsif field . complex? mock_fields ( field ) else case field . name when "int" , :int Random . new . rand ( 10000000 ) when "string" , :string RandomWord . nouns . next when "float" , :float Random . new . rand ( 10000.0 ) when "boolean" , :boolean [ true , false ] . sample end end end
generates fake data that adheres to the types defined in the service contract
generates fake data that adheres to the types defined in the service contract
# recursively mock values
field
<not_specific>