Contributing to FakeDataDSL
Thank you for your interest in contributing to FakeDataDSL! This document provides guidelines and information for contributors.
Table of Contents
- Code of Conduct
- Getting Started
- Development Setup
- How to Contribute
- Pull Request Process
- Code Style
- Testing Guidelines
- Documentation
Code of Conduct
This project adheres to a Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to the maintainers.
Getting Started
- Fork the repository on GitHub
- Clone your fork locally:
bash git clone https://github.com/YOUR_USERNAME/fake_data_dsl.git cd fake_data_dsl - Add the upstream remote:
bash git remote add upstream https://github.com/talaatmagdyx/fake_data_dsl.git
Development Setup
Prerequisites
- Ruby 3.1.0 or higher
- Bundler 2.0+
Installation
# Install dependencies
bundle install
# Run tests to verify setup
bundle exec rspec
# Run linter
bundle exec rubocop
Running the CLI locally
# From the project root
bundle exec exe/fake_data_dsl --help
How to Contribute
Reporting Bugs
Before creating a bug report:
- Check the existing issues
- Ensure you're using the latest version
- Collect information about the bug:
- Stack trace
- Ruby version (
ruby --version) - Gem version (
bundle show fake_data_dsl) - Your operating system
- Steps to reproduce
Suggesting Enhancements
Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion, include:
- A clear and descriptive title
- A detailed description of the proposed functionality
- Examples of how the feature would be used
- Why this enhancement would be useful
Adding New Types
To add a new data type:
- Create a new file in
lib/fake_data_dsl/types/in the appropriate domain folder - Inherit from
FakeDataDSL::Types::Base - Implement
generate_random,generate_edge, andgenerate_invalidmethods - Register the type in
lib/fake_data_dsl.rbinregister_builtin_types! - Add tests in
spec/types/ - Document in
tech_docs/dsl/core_types.md
Example:
# lib/fake_data_dsl/types/personal_names/nickname.rb
module FakeDataDSL
module Types
module PersonalNames
class Nickname < Base
def generate_random(rng, context, args)
rng.element(["Ace", "Buddy", "Chief", "Duke", "Flash"])
end
def generate_edge(rng, context, args)
rng.element(["", "X", "A" * 100])
end
def generate_invalid(rng, context, args)
rng.element([nil, 123, [], {}])
end
end
end
end
end
Adding New Behaviors
To add a new behavior:
- Create a new file in
lib/fake_data_dsl/behaviors/ - Inherit from
FakeDataDSL::Behaviors::Base - Implement the
applymethod - Register in
lib/fake_data_dsl/behaviors/registry.rb - Add tests and documentation
Adding New Export Formats
To add a new export format:
- Create a new file in
lib/fake_data_dsl/export/ - Inherit from
FakeDataDSL::Export::Base - Implement
exportand optionallyexport_allmethods - Register in
lib/fake_data_dsl/export.rb - Add CLI support in
lib/fake_data_dsl/cli.rbif needed - Add tests and documentation
Pull Request Process
Create a new branch from
main:git checkout -b feature/my-new-featureMake your changes and commit:
git add . git commit -m "feat: add new feature X"Follow the Conventional Commits specification:
feat:- New featuresfix:- Bug fixesdocs:- Documentation changesstyle:- Code style changes (formatting, etc.)refactor:- Code refactoringtest:- Adding or updating testschore:- Maintenance tasks
Ensure all tests pass:
bundle exec rspecEnsure code style compliance:
bundle exec rubocopUpdate documentation if needed
Push your branch and create a Pull Request
PR Requirements
- [ ] Tests pass
- [ ] RuboCop passes
- [ ] New code has test coverage
- [ ] Documentation updated (if applicable)
- [ ] CHANGELOG.md updated (for user-facing changes)
Code Style
We follow the Ruby Style Guide with some customizations. RuboCop is configured to enforce these rules.
Key Guidelines
- Use 2 spaces for indentation
- Use
frozen_string_literalpragma - Maximum line length: 120 characters
- Document public methods with YARD
- Prefer explicit over implicit
- Keep methods small and focused
Example
# frozen_string_literal: true
module FakeDataDSL
module Example
# Generate a random example value
#
# @param count [Integer] number of values to generate
# @return [Array<String>] generated values
#
# @example
# generate_examples(3)
# # => ["example1", "example2", "example3"]
#
def generate_examples(count)
count.times.map { |i| "example#{i + 1}" }
end
end
end
Testing Guidelines
Running Tests
# Run all tests
bundle exec rspec
# Run specific file
bundle exec rspec spec/types/core_types_spec.rb
# Run with coverage
bundle exec rspec --coverage
Writing Tests
- Place tests in
spec/mirroring thelib/structure - Use descriptive
describeanditblocks - Test edge cases and error conditions
- Use factories or fixtures for complex data
Example Test
# frozen_string_literal: true
RSpec.describe FakeDataDSL::Types::PersonalNames::Nickname do
subject(:generator) { described_class.new }
describe "#generate_random" do
it "returns a string" do
result = generator.generate_random(rng, context, {})
expect(result).to be_a(String)
end
it "returns consistent results with same seed" do
rng1 = FakeDataDSL::Generator::RNG.new(42)
rng2 = FakeDataDSL::Generator::RNG.new(42)
result1 = generator.generate_random(rng1, context, {})
result2 = generator.generate_random(rng2, context, {})
expect(result1).to eq(result2)
end
end
describe "#generate_edge" do
it "returns edge case values" do
result = generator.generate_edge(rng, context, {})
expect(result).to satisfy { |v| v.empty? || v.length == 1 || v.length >= 100 }
end
end
end
Documentation
Code Documentation
- Use YARD for API documentation
- Document all public methods
- Include usage examples
- Document parameters and return values
User Documentation
- Update
tech_docs/for user-facing features - Include examples that users can copy/paste
- Keep tutorials up to date
Generating Docs
# Generate YARD documentation
bundle exec yard doc
Questions?
If you have questions about contributing:
- Check existing documentation
- Search existing issues
- Open a new issue with the "question" label
Thank you for contributing to FakeDataDSL! 🎉