Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow getting the Assert from an AssertError #144

Merged
merged 1 commit into from Oct 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/assert.rs
Expand Up @@ -1035,6 +1035,33 @@ impl AssertError {
fn panic<T>(self) -> T {
panic!("{}", self)
}

/// Returns the [`Assert`] wrapped into the [`Result`] produced by
/// the `try_` variants of the [`Assert`] methods.
///
/// # Examples
///
/// ```rust,no_run
/// use assert_cmd::prelude::*;
///
/// use std::process::Command;
/// use predicates::prelude::*;
///
/// let result = Command::new("echo")
/// .assert();
///
/// match result.try_success() {
/// Ok(assert) => {
/// assert.stdout(predicate::eq(b"Success\n" as &[u8]));
/// }
/// Err(err) => {
/// err.assert().stdout(predicate::eq(b"Err but some specific output you might want to check\n" as &[u8]));
/// }
/// }
/// ```
pub fn assert(self) -> Assert {
self.assert
}
}

impl Error for AssertError {}
Expand Down