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 fixtures: Fixtures, with less to write.
ⓘ
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 is a static of type Fixture, named after its module and itself.
Its setup is the expression after the =: a future, such as an async
block or a call of an async fn. A fixture declared static NAME: PARENT
extends PARENT.
§A module’s fixture
for mod makes it the fixture of the module it is declared in: every
#[encore::test] there and in the modules inside it
loads it before the test runs. The innermost module’s fixture wins, and a
test can ask otherwise: #[encore::test(fixture = OTHER)],
#[encore::test(fixture = none)].
ⓘ
mod billing {
encore::fixture! {
pub static SEEDED for mod = seed();
}
#[encore::test]
async fn lists_users() {
// starts from SEEDED
}
}A test that is not an #[encore::test] loads no fixture by itself, and in
such a module is told to — to call Fixture::load or
without_fixture — rather than left to run on the wrong data.