Skip to content

Commit

Permalink
Require expectation in AssertError
Browse files Browse the repository at this point in the history
  • Loading branch information
TehPers committed Jun 18, 2024
1 parent f8afe6f commit da83d6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ pub struct AssertError {
impl AssertError {
/// Creates a new assertion error. Attach fields using the
/// [`Self::with_field`] method.
pub const fn new() -> Self {
Self { fields: Vec::new() }
pub fn new(expectation: impl Into<Cow<'static, str>>) -> Self {
Self {
fields: vec![("expected", expectation.into())],
}
}

/// Attaches a custom field to the error. This will appear in the error when
Expand Down
3 changes: 1 addition & 2 deletions src/expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ impl<T> Assertable for TryExpectationRoot<T> {
if satisfied {
Ok(())
} else {
let error = AssertError::new()
.with_field("expected", expectation.to_string())
let error = AssertError::new(expectation.to_string())
.with_field("at", self.source_info.to_string())
.with_field("original target", self.target_source);
Err(error)
Expand Down

0 comments on commit da83d6c

Please sign in to comment.