Project

randrizer

0.0
No release in over 3 years
Low commit activity in last 3 years
Random data generator with type composition
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 3.8.0
~> 13.0
~> 3.5.0
~> 3.0
~> 0.80.0
~> 1.38.1

Runtime

 Project Readme

Randrizer

Randrizer is a small library that allows consumers to generate random data for testing.

definition = {
  "this is" => "a constant",
  "but this should be a random positive number" => Randrizer::Types::Int[min: 1, max: 10],
  "and we support nested objects" => {
    "which can also be nested" => [
      Randrizer::Types::String[min_length: 3, max_length: 4, valid_chars: "ABC"],
      Randrizer::Types::Int[min: 0, max: 1000],
      Randrizer::Types::OneOf.build("choice 1", "choice 2", "choice 3")
    ]
  }
}

Randrizer::Generator.generate(definition)
=> {"this is"=>"a constant",
 "but this should be a random positive number"=>7,
 "and we support nested objects"=>{"which can also be nested"=>["BBB", 828, "choice 2"]}}

Use cases

  • Fuzzy testing: create massive amounts of random data for your application to consume. Are the inputs sanitised correctly? Are invalid inputs accepted?
  • Performance testing: generate random data to be fed to your application to measure throughput and performance
  • Anonymisation: replace your production data with random values

Installation

Randrizer's installation is pretty standard:

$ gem install randrizer

If you'd rather install randrizer using bundler, add a line for it in your Gemfile:

gem 'randrizer'

Drivers

Currently there's a single driver out of the box for simple JSON schema files.

$ cat json_schema.json
{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "properties": {
    "resource": {
      "description": "A type",
      "type": "string",
      "enum": ["type 1", "type 2"]
    },
    "amount": {
      "description": "Amount in cents",
      "type": "integer",
      "minimum": 0
    },
    "the_date": {
      "description": "Birthday",
      "type": "string",
      "format": "date"
    },
    "country": {
      "description": "Country code",
      "type": "string",
      "minLength": 2,
      "maxLength": 2
    }
  },
  "type": "object",
  "required": [
    "resource",
    "amount",
    "the_date",
    "country"
  ]
}
$ randrizer-json-schema json_schema.json
{
  "resource": "type 1",
  "amount": 302365828,
  "the_date": "2157-09-13",
  "country": "g-"
}