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

Fixed a continuation issue in the fluent assertion API #1791

Merged
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
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Execution/GivenSelector.cs
Expand Up @@ -101,7 +101,7 @@ public ContinuationOfGiven<T> FailWith(string message, params object[] args)
public ContinuationOfGiven<T> ClearExpectation()
{
predecessor.ClearExpectation();
return new ContinuationOfGiven<T>(this, predecessor.Succeeded);
return new ContinuationOfGiven<T>(this, continueAsserting);
}
}
}
39 changes: 39 additions & 0 deletions Tests/FluentAssertions.Specs/Execution/GivenSelectorSpecs.cs
Expand Up @@ -201,5 +201,44 @@ public void The_failure_message_should_not_be_preceded_by_the_expectation_after_
act.Should().Throw<XunitException>()
.WithMessage("Failure");
}

[Fact]
public void Clearing_the_expectation_does_not_affect_a_successful_assertion()
{
// Act
bool result = Execute.Assertion
.WithExpectation("Expectation ")
.Given(() => "Don't care")
.ForCondition(_ => true)
.FailWith("Should not fail")
.Then
.ClearExpectation();

// Assert
result.Should().BeTrue();
}

[Fact]
public void Clearing_the_expectation_does_not_affect_a_failed_assertion()
{
// Act
using var scope = new AssertionScope();

bool result = Execute.Assertion
.WithExpectation("Expectation ")
.Given(() => "Don't care")
.ForCondition(_ => false)
.FailWith("Should fail")
.Then
.ClearExpectation();

scope.Discard();

// Assert
if (result)
{
throw new XunitException("the assertion failed and should return false");
}
}
}
}
3 changes: 2 additions & 1 deletion docs/_pages/releases.md
Expand Up @@ -13,7 +13,8 @@ sidebar:

* Added `WithMapping` option to `BeEquivalentTo` to map members with different names between the subject and expectation - [#1742](https://github.com/fluentassertions/fluentassertions/pull/1742)

### Fixes
### Fixes (Extensibility)
* Fixed a continuation issue when using `ClearExpectation` - [#1791](https://github.com/fluentassertions/fluentassertions/pull/1791)

## 6.4.0

Expand Down