macro_rules! fixture {
() => { ... };
($(#[$meta:meta])* $vis:vis static $name:ident for mod : $parent:path = $setup:expr; $($rest:tt)*) => { ... };
($(#[$meta:meta])* $vis:vis static $name:ident for mod = $setup:expr; $($rest:tt)*) => { ... };
($(#[$meta:meta])* $vis:vis static $name:ident : $parent:path = $setup:expr; $($rest:tt)*) => { ... };
($(#[$meta:meta])* $vis:vis static $name:ident = $setup:expr; $($rest:tt)*) => { ... };
}Expand description
Declares one or more Fixture statics with concise syntax.
encore::fixture! {
/// Two users.
pub static SEEDED = async {
DB.execute("INSERT INTO users (name) VALUES ('ada'), ('grace')", &[]).await?;
Ok(())
};
/// `SEEDED`, plus an invoice for each user.
pub static INVOICED: SEEDED = create_invoices();
}Each item defines a static of type Fixture named after its module
path and identifier. The expression after = produces the setup future (an
async block or async fn call). Write static NAME: PARENT = ... to
extend another fixture.
§Module-level fixtures
Add for mod to make a fixture the default for the enclosing module and its
submodules: every #[encore::test] in scope loads it
automatically. The innermost module’s fixture takes precedence, and
individual tests can override it with #[encore::test(fixture = OTHER)] or
#[encore::test(fixture = none)].
mod billing {
encore::fixture! {
pub static SEEDED for mod = seed();
}
#[encore::test]
async fn lists_users() {
// starts from SEEDED
}
}Tests that do not use #[encore::test] do not load module fixtures
automatically; in a module with a default fixture, they must explicitly call
Fixture::load or without_fixture before accessing resources.