Open jondot opened 11 months ago
In my project, I extract the configure_insta!
into tests/mod.rs
and use params to configure the snapshot suffix. Here is usage example:
/// in tests/mod.rs
macro_rules! configure_insta {
($suffix:expr) => {
let mut settings = insta::Settings::clone_current();
settings.set_prepend_module_to_snapshot(false);
settings.set_snapshot_suffix($suffix);
let _guard = settings.bind_to_scope();
};
}
pub(crate) use configure_insta;
/// in tests/models/users.rs
macro_rules! configure_insta {
() => {
crate::configure_insta!("users")
};
}
#[tokio::test]
#[serial]
async fn test_can_validate_model() {
configure_insta!();
// ...test code
}
You can see the actual commit in: https://github.com/Bogay/normal-oj/pull/3/commits/e3ed1a5e5915a5889929d7ac8965bf8d6814c893
Do you think this is the right approach to extract configure_insta!
?
Can be closed - loco-macros was just removed.
currently start of each test in
tests/
contains this pragma:we need to somehow share this macro, or create a new macro that wraps configuring insta as well as booting an app (possibly).
also, making:
into our own attribute
loco::test
which wraps these might make sense as well.