fixture_rs

Crates.iofixture_rs
lib.rsfixture_rs
version0.0.1
created_at2025-05-04 19:34:04.291092+00
updated_at2025-05-04 19:34:04.291092+00
descriptionFixture derive macro for Type Driven Development
homepagehttps://github.com/ProbablyClem/fixture_rs
repositoryhttps://github.com/ProbablyClem/fixture_rs
max_upload_size
id1659883
size5,156
Clément Guiton (ProbablyClem)

documentation

README

fixture_rs

Create default fixtures for your types

This crates exposes a simple fixture Trait

pub trait Fixture {
    fn fixture() -> Self;
}

wich can be automaticaly derived

#[derive(Fixture)]
pub struct User {
    pub name: String,
    pub age: u32,
    pub bio: Option<String>,
}

#[derive(Fixture)]
pub struct Group {
    pub users: Vec<User>,
}

You can then call fixture() to use it in your tests

    #[test]
    fn test_user_fixture() {
        let user = User::fixture();
        assert_eq!(user.name, "string".to_string());
        assert_eq!(user.age, 1);
        assert_eq!(user.bio, Some("string".to_string()));
    }

    #[test]
    fn test_group_fixture() {
        let group = Group::fixture();
        assert_eq!(group.users.len(), 1);
        let user = &group.users[0];
        assert_eq!(user.name, "string".to_string());
    }

Implementation

You need to implement it manually for your value object such as

impl Fixture for Text {
    fn fixture() -> Self {
        "string".into()
    }
}

Limitations

Unfortunatly due to Rust orphan rules, you can't implement the Fixture trait on primitive types nor any forein types Rust Orphan

This means that you need to wrap the primitive types, or any foreign struct. Which means that this crate is particulary usefull when enforcing type driven development

Commit count: 14

cargo fmt