Getting Started with FakeDataDSL
FakeDataDSL is a Ruby gem for generating realistic fake data using a simple, human-friendly DSL (Domain-Specific Language).
Installation
Add FakeDataDSL to your Gemfile:
gem 'fake_data_dsl'
Then run:
bundle install
Or install it directly:
gem install fake_data_dsl
Basic Usage
1. Define a Schema
Create a schema file (e.g., user.dsl):
User:
id: uuid
name: name
email: email
age: number(18..65)
active: boolean
2. Load and Generate
require 'fake_data_dsl'
# Load schema
registry = FakeDataDSL::Registry.new
registry.load_file('user.dsl')
# Generate a single record
schema = registry.schema('User')
record = schema.generate
# => { "id" => "550e8400-e29b-41d4-a716-446655440000",
# "name" => "John Smith",
# "email" => "john.smith@example.com",
# "age" => 42,
# "active" => true }
# Generate multiple records
records = schema.generate_many(10)
# => Array of 10 user records
Key Concepts
Schemas
A schema defines the structure of your data. Each schema has a name (like User) and contains fields with types.
Types
Types define what kind of data to generate. Examples:
uuid- Universally unique identifiersname- Person namesemail- Email addressesnumber- Numeric valuesboolean- True/false values
See Type Reference for the complete list.
Fields
Fields are the properties of your schema. Each field has:
- A name (e.g.,
id,name) - A type (e.g.,
uuid,name) - Optional arguments (e.g.,
number(18..65))
Next Steps
- Read the DSL Reference to learn the full syntax
- Explore Examples for real-world use cases
- Check out Advanced Features for complex scenarios