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
impl Golden
Sourcepub fn new(path: impl Into<PathBuf>) -> Self
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.
Sourcepub fn compare(&self, name: impl AsRef<str>, actual: &str) -> CheckResult
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 ->
Skipwithcreatedtag (the snapshot is written to disk for the first time). - Snapshot mismatch + update mode ->
Skipwithupdatedtag (the snapshot is overwritten withactual). - Snapshot mismatch (default) ->
Fail (Error)withregressiontag, line-based diff indetail, and full actual/expected as snippet evidence.
Auto Trait Implementations§
impl Freeze for Golden
impl RefUnwindSafe for Golden
impl Send for Golden
impl Sync for Golden
impl Unpin for Golden
impl UnsafeUnpin for Golden
impl UnwindSafe for Golden
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more