diff --git a/README.md b/README.md index 59874da..847f585 100644 --- a/README.md +++ b/README.md @@ -364,10 +364,10 @@ for types that implement `std::error::Error`. for types that implement `core::fmt::Debug`: -| assertion | description | -|-----------------------------|----------------------------------------------------------------------------| -| has_debug_message | verify that a type formatted for debug is equal to the expected string | -| does_not_have_debug_message | verify that a type formatted for debug is not equal to the expected string | +| assertion | description | +|----------------------------|----------------------------------------------------------------------------| +| has_debug_string | verify that a type formatted for debug is equal to the expected string | +| does_not_have_debug_string | verify that a type formatted for debug is not equal to the expected string | for types that implement `core::fmt::Display`: diff --git a/src/assertions.rs b/src/assertions.rs index 333d5b6..ff8e6ba 100644 --- a/src/assertions.rs +++ b/src/assertions.rs @@ -2287,10 +2287,10 @@ pub trait AssertErrorHasSource<'a, R> { /// /// let subject = Foo { hello: "World".into() }; /// -/// assert_that!(&subject).has_debug_message("Foo { hello: \"World\" }"); -/// assert_that!(&subject).does_not_have_debug_message("Bar { hello: \"World\" }"); +/// assert_that!(&subject).has_debug_string("Foo { hello: \"World\" }"); +/// assert_that!(&subject).does_not_have_debug_string("Bar { hello: \"World\" }"); /// ``` -pub trait AssertHasDebugMessage { +pub trait AssertHasDebugString { /// Verifies that a subject formatted for debugging results in the expected /// string. /// @@ -2306,10 +2306,10 @@ pub trait AssertHasDebugMessage { /// /// let subject = Foo { hello: "World".into() }; /// - /// assert_that!(subject).has_debug_message("Foo { hello: \"World\" }"); + /// assert_that!(subject).has_debug_string("Foo { hello: \"World\" }"); /// ``` #[track_caller] - fn has_debug_message(self, expected: E) -> Self; + fn has_debug_string(self, expected: E) -> Self; /// Verifies that a subject formatted for debugging does not result in the /// expected string. @@ -2326,10 +2326,10 @@ pub trait AssertHasDebugMessage { /// /// let subject = Foo { hello: "World".into() }; /// - /// assert_that!(subject).does_not_have_debug_message("Hello World"); + /// assert_that!(subject).does_not_have_debug_string("Hello World"); /// ``` #[track_caller] - fn does_not_have_debug_message(self, expected: E) -> Self; + fn does_not_have_debug_string(self, expected: E) -> Self; } /// Assert a type formatted into a display string. diff --git a/src/equality.rs b/src/equality.rs index c89678b..cf0b4fd 100644 --- a/src/equality.rs +++ b/src/equality.rs @@ -1,11 +1,11 @@ //! Implementation of the equality assertions. use crate::assertions::{ - AssertEquality, AssertHasDebugMessage, AssertHasDisplayMessage, AssertSameAs, + AssertEquality, AssertHasDebugString, AssertHasDisplayMessage, AssertSameAs, }; use crate::colored::{mark_diff, mark_diff_str}; use crate::expectations::{ - has_debug_message, has_display_message, is_equal_to, is_same_as, not, HasDebugMessage, + has_debug_string, has_display_message, is_equal_to, is_same_as, not, HasDebugString, HasDisplayMessage, IsEqualTo, IsSameAs, }; use crate::spec::{DiffFormat, Expectation, Expression, FailingStrategy, Invertible, Spec}; @@ -95,22 +95,22 @@ where impl Invertible for IsSameAs {} -impl AssertHasDebugMessage for Spec<'_, S, R> +impl AssertHasDebugString for Spec<'_, S, R> where S: Debug, E: AsRef, R: FailingStrategy, { - fn has_debug_message(self, expected: E) -> Self { - self.expecting(has_debug_message(expected)) + fn has_debug_string(self, expected: E) -> Self { + self.expecting(has_debug_string(expected)) } - fn does_not_have_debug_message(self, expected: E) -> Self { - self.expecting(not(has_debug_message(expected))) + fn does_not_have_debug_string(self, expected: E) -> Self { + self.expecting(not(has_debug_string(expected))) } } -impl Expectation for HasDebugMessage +impl Expectation for HasDebugString where S: Debug, E: AsRef, @@ -131,12 +131,12 @@ where let (marked_actual, marked_expected) = mark_diff_str(&format!("{actual:?}"), expected, format); format!( - "expected {expression} to {not}have debug message {expected:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}", + "expected {expression} to {not}have a debug string equal to {expected:?}\n but was: {marked_actual}\n expected: {not}{marked_expected}", ) } } -impl Invertible for HasDebugMessage {} +impl Invertible for HasDebugString {} impl AssertHasDisplayMessage for Spec<'_, S, R> where diff --git a/src/error/tests.rs b/src/error/tests.rs index 0155b2f..1d11bd7 100644 --- a/src/error/tests.rs +++ b/src/error/tests.rs @@ -38,28 +38,28 @@ impl Display for SourceError { impl Error for SourceError {} #[test] -fn error_has_debug_message() { +fn error_has_debug_string() { let error = SuperError { source: SourceError::Bar, }; - assert_that(error).has_debug_message("SuperError { source: Bar }"); + assert_that(error).has_debug_string("SuperError { source: Bar }"); } #[test] -fn verify_error_has_debug_message_fails() { +fn verify_error_has_debug_string_fails() { let error = SuperError { source: SourceError::Foo, }; let failures = verify_that(error) - .has_debug_message("SuperError { source: Bar }") + .has_debug_string("SuperError { source: Bar }") .display_failures(); assert_eq!( failures, &[ - r#"expected subject to have debug message "SuperError { source: Bar }" + r#"expected subject to have a debug string equal to "SuperError { source: Bar }" but was: SuperError { source: Foo } expected: SuperError { source: Bar } "# @@ -68,28 +68,28 @@ fn verify_error_has_debug_message_fails() { } #[test] -fn error_does_not_have_debug_message() { +fn error_does_not_have_debug_string() { let error = SuperError { source: SourceError::Bar, }; - assert_that(error).does_not_have_debug_message("SuperError { source: Foo }"); + assert_that(error).does_not_have_debug_string("SuperError { source: Foo }"); } #[test] -fn verify_error_does_not_have_debug_message_fails() { +fn verify_error_does_not_have_debug_string_fails() { let error = SuperError { source: SourceError::Bar, }; let failures = verify_that(error) - .does_not_have_debug_message("SuperError { source: Bar }") + .does_not_have_debug_string("SuperError { source: Bar }") .display_failures(); assert_eq!( failures, &[ - r#"expected subject to not have debug message "SuperError { source: Bar }" + r#"expected subject to not have a debug string equal to "SuperError { source: Bar }" but was: SuperError { source: Bar } expected: not SuperError { source: Bar } "# diff --git a/src/expectations.rs b/src/expectations.rs index ccc4c6d..13e1b71 100644 --- a/src/expectations.rs +++ b/src/expectations.rs @@ -637,12 +637,12 @@ pub struct ErrorHasSourceMessage { pub expected_source_message: String, } -/// Creates a [`HasDebugMessage`] expectation. -pub fn has_debug_message(expected: E) -> HasDebugMessage { - HasDebugMessage { expected } +/// Creates a [`HasDebugString`] expectation. +pub fn has_debug_string(expected: E) -> HasDebugString { + HasDebugString { expected } } -pub struct HasDebugMessage { +pub struct HasDebugString { pub expected: E, }