pub trait Fixture {
type Output;
// Required methods
fn set_up(&mut self) -> Result<Self::Output>;
fn tear_down(&mut self) -> Result<()>;
// Provided method
fn set_up_checked(&mut self, name: impl Into<String>) -> CheckResult { ... }
}Expand description
A trait for any fixture that can be set up and torn down.
Implementors should ensure that tear_down is idempotent and that
set_up followed by tear_down always returns the system to a clean
state.
§Example
use dev_fixtures::Fixture;
use std::io;
struct MyFixture;
impl Fixture for MyFixture {
type Output = u32;
fn set_up(&mut self) -> io::Result<u32> { Ok(42) }
fn tear_down(&mut self) -> io::Result<()> { Ok(()) }
}Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn set_up_checked(&mut self, name: impl Into<String>) -> CheckResult
fn set_up_checked(&mut self, name: impl Into<String>) -> CheckResult
Run set_up and emit a CheckResult tagged fixtures.
On Ok(_), verdict is Pass with setup_ok=1 evidence.
On Err(e), verdict is Fail (Critical) with setup_failed
regressiontags andsetup_ok=0evidence.
Default impl wraps set_up and discards the output. Override
if you need to inspect the produced value before returning.
§Example
use dev_fixtures::Fixture;
use std::io;
struct OkFixture;
impl Fixture for OkFixture {
type Output = ();
fn set_up(&mut self) -> io::Result<()> { Ok(()) }
fn tear_down(&mut self) -> io::Result<()> { Ok(()) }
}
let check = OkFixture.set_up_checked("ok");
assert!(check.has_tag("fixtures"));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.