Skip to content

Commit 5ab36e8

Browse files
authored
Merge pull request #456 from epage/docs
docs(snap): Improve gettting started experience
2 parents ede8921 + dda19ac commit 5ab36e8

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

crates/snapbox/src/assert/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ pub use error::Result;
2626
/// # use snapbox::Assert;
2727
/// # use snapbox::file;
2828
/// let actual = "something";
29-
/// Assert::new().eq(actual, file!["output.txt"]);
29+
/// Assert::new()
30+
/// .action_env("SNAPSHOTS")
31+
/// .eq(actual, file!["output.txt"]);
3032
/// ```
3133
#[derive(Clone, Debug)]
3234
pub struct Assert {
@@ -62,15 +64,19 @@ impl Assert {
6264
/// # use snapbox::Assert;
6365
/// let actual = "something";
6466
/// let expected = "so[..]g";
65-
/// Assert::new().eq(actual, expected);
67+
/// Assert::new()
68+
/// .action_env("SNAPSHOTS")
69+
/// .eq(actual, expected);
6670
/// ```
6771
///
6872
/// Can combine this with [`file!`][crate::file]
6973
/// ```rust,no_run
7074
/// # use snapbox::Assert;
7175
/// # use snapbox::file;
7276
/// let actual = "something";
73-
/// Assert::new().eq(actual, file!["output.txt"]);
77+
/// Assert::new()
78+
/// .action_env("SNAPSHOTS")
79+
/// .eq(actual, file!["output.txt"]);
7480
/// ```
7581
#[track_caller]
7682
pub fn eq(&self, actual: impl IntoData, expected: impl IntoData) {

crates/snapbox/src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
//!
2929
//! Testing Functions:
3030
//! - [`assert_data_eq!`] for quick and dirty snapshotting
31+
//! - [`IntoJson`]: adapt serde types to be asserted against
32+
//! - [`std::string::ToString`]: adapt displayable types to be asserted against
33+
//! - [`ToDebug`]: adapt `#[derive(Debug)]` types to be asserted against
3134
//!
3235
//! Testing Commands:
3336
//! - [`cmd::Command`]: Process spawning for testing of non-interactive commands
@@ -38,25 +41,28 @@
3841
//! - [`dir::DirRoot`]: Working directory for tests
3942
//! - [`Assert`]: Diff a directory against files present in a pattern directory
4043
//!
44+
//! Snapshots:
45+
//! - [`str!`]: In-source snapshots
46+
//! - [`file!`]: External snapshots
47+
//!
4148
//! You can also build your own version of these with the lower-level building blocks these are
4249
//! made of.
4350
//!
44-
#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
45-
//!
4651
//! # Examples
4752
//!
4853
//! [`assert_data_eq!`]
4954
//! ```rust
50-
//! snapbox::assert_data_eq!("Hello many people!", "Hello [..] people!");
55+
//! # use snapbox::str;
56+
//! let actual = // ...
57+
//! # "Hello many people!";
58+
//! snapbox::assert_data_eq!(actual, str![["Hello [..] people!"]]);
5159
//! ```
5260
//!
53-
//! [`Assert`]
54-
//! ```rust,no_run
55-
//! let actual = "...";
56-
//! snapbox::Assert::new()
57-
//! .action_env("SNAPSHOTS")
58-
//! .eq(actual, snapbox::file!["help_output_is_clean.txt"]);
59-
//! ```
61+
//! To update the snapshot, run the tests with `SNAPSHOTS=overwrite` set.
62+
//!
63+
//! # Feature flags
64+
//!
65+
#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
6066
//!
6167
//! [trycmd]: https://docs.rs/trycmd
6268

0 commit comments

Comments
 (0)