fixture_rs 0.0.1

Fixture derive macro for Type Driven Development
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 4.65 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ProbablyClem/fixture_rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ProbablyClem

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