#factory #testing #test #fixture

factori-impl

You shouldn’t use this crate directly. It’s internal to factori.

4 releases (2 stable)

1.1.0 Aug 14, 2020
1.0.0 Jan 15, 2020
0.1.1 Jan 8, 2020
0.1.0 May 18, 2019

#4 in #factory

Download history 557/week @ 2021-08-17 491/week @ 2021-08-24 491/week @ 2021-08-31 597/week @ 2021-09-07 497/week @ 2021-09-14 586/week @ 2021-09-21 449/week @ 2021-09-28 315/week @ 2021-10-05 307/week @ 2021-10-12 515/week @ 2021-10-19 629/week @ 2021-10-26 853/week @ 2021-11-02 867/week @ 2021-11-09 539/week @ 2021-11-16 424/week @ 2021-11-23 343/week @ 2021-11-30

2,371 downloads per month
Used in factori

MIT license

13KB
356 lines

Factori Build Status Crates.io Docs.rs

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

Factori makes it easy to instantiate your test objects/fixtures in tests while providing an ergonomic syntax for defining how they are instantiated.

Factori works on stable Rust >=1.45.

Documentation

See API documentation.

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,
    }

    mixin bike {
        number_wheels = 2,
    }
});

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

    // Its type is Vehicle, nothing fancy:
    let vehicle: Vehicle = default;

    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.

Testing

Run:

cargo test

License

MIT

Dependencies

~290–710KB
~18K SLoC

7_