Skip to main content

Golden

Struct Golden 

Source
pub struct Golden { /* private fields */ }
Expand description

A stored snapshot of an expected text output.

§Example

use dev_fixtures::golden::Golden;
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("snap.txt");
std::fs::write(&path, "hello\n").unwrap();

let g = Golden::new(&path);
let check = g.compare("greet", "hello\n");
assert!(matches!(check.verdict, dev_report::Verdict::Pass));

Implementations§

Source§

impl Golden

Source

pub fn new(path: impl Into<PathBuf>) -> Self

Build a golden bound to a path on disk. The path may not exist yet; on first run the snapshot is created and verdict is Skip with a created tag.

Source

pub fn compare(&self, name: impl AsRef<str>, actual: &str) -> CheckResult

Compare actual against the stored snapshot and emit a CheckResult tagged fixtures and golden.

Verdicts:

  • Snapshot matches -> Pass.
  • Snapshot missing -> Skip with created tag (the snapshot is written to disk for the first time).
  • Snapshot mismatch + update mode -> Skip with updated tag (the snapshot is overwritten with actual).
  • Snapshot mismatch (default) -> Fail (Error) with regression tag, line-based diff in detail, and full actual/expected as snippet evidence.
Source

pub fn path(&self) -> &Path

The path this golden is bound to.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.