#factory #testing #test #fixture

factori

A factory library for Rust, inspired by FactoryBot. 🤖

4 releases

✓ Uses Rust 2018 edition

0.1.0 May 18, 2019
0.0.3 Jun 27, 2018
0.0.2 Jun 27, 2018
0.0.1 Jun 14, 2018

#84 in Testing

Download history 27/week @ 2019-04-18 9/week @ 2019-04-25 32/week @ 2019-05-02 9/week @ 2019-05-09 38/week @ 2019-05-16 11/week @ 2019-05-23 12/week @ 2019-05-30 24/week @ 2019-06-06 24/week @ 2019-06-20 20/week @ 2019-06-27 35/week @ 2019-07-04 11/week @ 2019-07-11 9/week @ 2019-07-18 4/week @ 2019-07-25

78 downloads per month

MIT license

5KB

Factori Build Status Crates.io Docs.rs

A testing factory library for Rust, inspired by FactoryBot. 🤖 🦀

Factori works on stable Rust >=1.30. It aims to provide a clean, ergonomic syntax for instantiating test objects, without sacrificing type-safety.

Example

Factori provides two macros: factori!, which defines a factory for a type, and create! which instantiates it:

#[macro_use]
extern crate factori;

pub struct Vehicle {
    number_wheels: u8,
    electric: bool,
}

factori!(Vehicle, {
    default {
        number_wheels = 4,
        electric = false,
    }

    feature bike {
        number_wheels = 2,
    }
});

fn main() {
    let default = create!(Vehicle);
    assert_eq!(default.number_wheels, 4);
    assert_eq!(default.electric, false);

    let three_wheels = create!(Vehicle, number_wheels: 3);
    assert_eq!(three_wheels.number_wheels, 3);

    let electric_bike = create!(Vehicle, :bike, electric: true);
    assert_eq!(electric_bike.number_wheels, 2);
    assert_eq!(electric_bike.electric, true);
}

More examples are available in the tests/ directory.

Stability

Factori is still brand new, and the syntax may change significantly between point-releases.

Testing

Run:

cargo test

License

MIT

Dependencies

~1MB
~27K SLoC