From c33006c2e8857f7a02f1acffbc1e8a45ebd8853b Mon Sep 17 00:00:00 2001 From: ITaluone <44049228+ITaluone@users.noreply.github.com> Date: Wed, 27 Apr 2022 20:03:13 +0200 Subject: [PATCH] Fix the failure message for occurrence regex (#1913) --- Src/FluentAssertions/Primitives/StringAssertions.cs | 5 +++-- .../Primitives/StringAssertionSpecs.MatchRegex.cs | 6 +++--- docs/_pages/releases.md | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Src/FluentAssertions/Primitives/StringAssertions.cs b/Src/FluentAssertions/Primitives/StringAssertions.cs index a55ad0236d..60ca4084e5 100644 --- a/Src/FluentAssertions/Primitives/StringAssertions.cs +++ b/Src/FluentAssertions/Primitives/StringAssertions.cs @@ -507,8 +507,9 @@ public AndConstraint NotMatch(string wildcardPattern, string becaus .ForConstraint(occurrenceConstraint, actual) .UsingLineBreaks .BecauseOf(because, becauseArgs) - .FailWith($"Expected {{context:string}} to match regex {{0}} {{expectedOccurrence}}{{reason}}, but found it {actual.Times()}.", - regexStr); + .FailWith($"Expected {{context:string}} {{0}} to match regex {{1}} {{expectedOccurrence}}{{reason}}, " + + $"but found it {actual.Times()}.", + Subject, regexStr); } return new AndConstraint((TAssertions)this); diff --git a/Tests/FluentAssertions.Specs/Primitives/StringAssertionSpecs.MatchRegex.cs b/Tests/FluentAssertions.Specs/Primitives/StringAssertionSpecs.MatchRegex.cs index e84f9342aa..2259176f45 100644 --- a/Tests/FluentAssertions.Specs/Primitives/StringAssertionSpecs.MatchRegex.cs +++ b/Tests/FluentAssertions.Specs/Primitives/StringAssertionSpecs.MatchRegex.cs @@ -225,7 +225,7 @@ public void When_a_string_is_matched_and_the_count_of_matches_do_not_fit_the_exp // Assert act.Should().Throw() - .WithMessage($"Expected subject to match regex*\"Lorem.*\" exactly 2 times, but found it 1 time."); + .WithMessage($"Expected subject*Lorem*to match regex*\"Lorem.*\" exactly 2 times, but found it 1 time*"); } [Fact] @@ -252,7 +252,7 @@ public void When_a_string_is_matched_and_the_expected_count_is_zero_and_string_m // Assert act.Should().Throw() - .WithMessage($"Expected subject to match regex*\"a\" exactly 0 times, but found it 1 time."); + .WithMessage($"Expected subject*a*to match regex*\"a\" exactly 0 times, but found it 1 time*"); } [Fact] @@ -305,7 +305,7 @@ public void When_the_subject_is_empty_and_expected_count_is_more_than_zero_it_fa // Assert act.Should().Throw() - .WithMessage($"Expected subject to match regex* at least 1 time, but found it 0 times.*"); + .WithMessage($"Expected subject*to match regex* at least 1 time, but found it 0 times*"); } [Fact] diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md index 3011877865..ada326d6ad 100644 --- a/docs/_pages/releases.md +++ b/docs/_pages/releases.md @@ -16,6 +16,9 @@ sidebar: * Add `For`/`Exclude` to allow exclusion of members inside a collection - [#1782](https://github.com/fluentassertions/fluentassertions/pull/1782) * Added overload for `HaveElement` for `XDocument` and `XElement` to assert on number of XML nodes - [#1880](https://github.com/fluentassertions/fluentassertions/pull/1880) +### Fixes +* Fix the failure message for regex matches (occurrence overload) to include the missing subject - [#1913](https://github.com/fluentassertions/fluentassertions/pull/1913) + ## 6.6.0 ### What's New @@ -32,8 +35,6 @@ sidebar: * Better handling of NaN in various numeric assertions - [#1822](https://github.com/fluentassertions/fluentassertions/pull/1822) & [#1867](https://github.com/fluentassertions/fluentassertions/pull/1867) * `WithMapping` in `BeEquivalentTo` now also works when the root is a collection - [#1858](https://github.com/fluentassertions/fluentassertions/pull/1858) -### Fixes (Extensibility) - ## 6.5.1 ### Fixes