Skip to content

Commit

Permalink
Fix the failure message for occurrence regex (#1913)
Browse files Browse the repository at this point in the history
  • Loading branch information
ITaluone committed Apr 27, 2022
1 parent 29ab732 commit c33006c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 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}} {{0}} to match regex {{1}} {{expectedOccurrence}}{{reason}}, " +
$"but found it {actual.Times()}.",
Subject, regexStr);
}

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*Lorem*to match regex*\"Lorem.*\" exactly 2 times, but found it 1 time*");
}

[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*a*to match regex*\"a\" exactly 0 times, but found it 1 time*");
}

[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
5 changes: 3 additions & 2 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 All @@ -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
Expand Down

0 comments on commit c33006c

Please sign in to comment.