Skip to content

Commit

Permalink
Fixed a continuation issue in the fluent assertion API (#1791)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisdoomen committed Jan 29, 2022
1 parent 91aca63 commit 8d59e4d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
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)

* Improved the documentation on `BeLowerCased` and `BeUpperCased` for strings with non-alphabetic characters - [#1792](https://github.com/fluentassertions/fluentassertions/pull/1792)

Expand Down

0 comments on commit 8d59e4d

Please sign in to comment.