Skip to content

Commit

Permalink
Fix the failure message for occurrence regex
Browse files Browse the repository at this point in the history
  • Loading branch information
ITaluone committed Apr 26, 2022
1 parent d1e4318 commit f639b70
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Src/FluentAssertions/Primitives/StringAssertions.cs
Expand Up @@ -507,8 +507,9 @@ public AndConstraint<TAssertions> 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}} to match regex {{0}} {{expectedOccurrence}}{{reason}}, " +
$"but found it {actual.Times()} in {{1}}.",
regexStr, Subject);
}

return new AndConstraint<TAssertions>((TAssertions)this);
Expand Down
Expand Up @@ -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<XunitException>()
.WithMessage($"Expected subject to match regex*\"Lorem.*\" exactly 2 times, but found it 1 time.");
.WithMessage($"Expected subject to match regex*\"Lorem.*\" exactly 2 times, but found it 1 time in *Lorem*");
}

[Fact]
Expand All @@ -252,7 +252,7 @@ public void When_a_string_is_matched_and_the_expected_count_is_zero_and_string_m

// Assert
act.Should().Throw<XunitException>()
.WithMessage($"Expected subject to match regex*\"a\" exactly 0 times, but found it 1 time.");
.WithMessage($"Expected subject to match regex*\"a\" exactly 0 times, but found it 1 time in *{subject}*");
}

[Fact]
Expand Down Expand Up @@ -305,7 +305,7 @@ public void When_the_subject_is_empty_and_expected_count_is_more_than_zero_it_fa

// Assert
act.Should().Throw<XunitException>()
.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]
Expand Down
3 changes: 3 additions & 0 deletions docs/_pages/releases.md
Expand Up @@ -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
Expand Down

0 comments on commit f639b70

Please sign in to comment.