Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the failure message for occurrence regex #1913

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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