| Crates.io | fixture_rs |
| lib.rs | fixture_rs |
| version | 0.0.1 |
| created_at | 2025-05-04 19:34:04.291092+00 |
| updated_at | 2025-05-04 19:34:04.291092+00 |
| description | Fixture derive macro for Type Driven Development |
| homepage | https://github.com/ProbablyClem/fixture_rs |
| repository | https://github.com/ProbablyClem/fixture_rs |
| max_upload_size | |
| id | 1659883 |
| size | 5,156 |
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());
}
You need to implement it manually for your value object such as
impl Fixture for Text {
fn fixture() -> Self {
"string".into()
}
}
Unfortunatly due to Rust orphan rules,
you can't implement the Fixture trait on primitive types nor any forein types

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