From da83d6cc2ea3bbc757ef8b6515156b688726c894 Mon Sep 17 00:00:00 2001 From: TehPers Date: Tue, 18 Jun 2024 00:08:58 -0700 Subject: [PATCH] Require expectation in AssertError --- src/error.rs | 6 ++++-- src/expect.rs | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index 50fccb0..f20976c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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>) -> Self { + Self { + fields: vec![("expected", expectation.into())], + } } /// Attaches a custom field to the error. This will appear in the error when diff --git a/src/expect.rs b/src/expect.rs index ce8a29c..bbb9002 100644 --- a/src/expect.rs +++ b/src/expect.rs @@ -126,8 +126,7 @@ impl Assertable for TryExpectationRoot { 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)