Skip to main content

Fixture

Trait Fixture 

Source
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§

Source

type Output

Output produced when the fixture is set up.

Required Methods§

Source

fn set_up(&mut self) -> Result<Self::Output>

Set the fixture up. Returns the output (e.g. a path, a handle).

Source

fn tear_down(&mut self) -> Result<()>

Tear the fixture down. MUST be idempotent.

Provided Methods§

Source

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

  • regression tags and setup_ok=0 evidence.

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.

Implementors§