#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

#72 in Testing

Download history 25/week @ 2019-02-02 34/week @ 2019-02-09 35/week @ 2019-02-16 37/week @ 2019-02-23 17/week @ 2019-03-02 8/week @ 2019-03-09 24/week @ 2019-03-16 39/week @ 2019-03-23 3/week @ 2019-03-30 10/week @ 2019-04-06 20/week @ 2019-04-13 26/week @ 2019-04-20 23/week @ 2019-04-27 18/week @ 2019-05-04 12/week @ 2019-05-11

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
~22K SLoC