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

Nested AssertionScopes do not print inner scope reportables #2044

Merged
merged 10 commits into from Dec 17, 2022
1 change: 1 addition & 0 deletions Src/FluentAssertions/Execution/AssertionScope.cs
Expand Up @@ -395,6 +395,7 @@ public void Dispose()
parent.assertionStrategy.HandleFailure(failureMessage);
}

parent.contextData.Add(contextData);
parent.AppendTracing(tracing.ToString());

parent = null;
Expand Down
Expand Up @@ -300,17 +300,18 @@ public void When_asserting_collections_not_to_be_equivalent_with_options_but_sub
{
// Arrange
int[] actual = null;
int[] expectation = new[] { 1, 2, 3 };

// Act
Action act = () =>
{
using var _ = new AssertionScope();
actual.Should().NotBeEquivalentTo(new[] { 1, 2, 3 }, opt => opt, "we want to test the failure {0}", "message");
actual.Should().NotBeEquivalentTo(expectation, opt => opt, "we want to test the failure {0}", "message");
};

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected actual not to be equivalent *failure message*, but found <null>.");
.WithMessage("Expected actual not to be equivalent *failure message*, but found <null>.*");
}

[Fact]
Expand Down
18 changes: 18 additions & 0 deletions Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs
Expand Up @@ -235,6 +235,24 @@ public void When_using_a_custom_strategy_it_should_include_failure_messages_of_a
.WithMessage("*but found false*but found true*");
}

[Fact]
public void When_nested_scope_is_disposed_it_passes_reports_to_parent_scope()
{
// Arrange/Act
using (var outerScope = new AssertionScope())
{
outerScope.AddReportable("outerReportable", "foo");

using (var innerScope = new AssertionScope())
{
innerScope.AddReportable("innerReportable", "bar");
}

// Assert
outerScope.Get<string>("innerReportable").Should().Be("bar");
}
}

public class CustomAssertionStrategy : IAssertionStrategy
{
private readonly List<string> failureMessages = new();
Expand Down
1 change: 1 addition & 0 deletions docs/_pages/releases.md
Expand Up @@ -17,6 +17,7 @@ sidebar:

### Fixes
* Quering properties on classes, e.g. `typeof(MyClass).Properties()`, now also includes static properties - [#2054](https://github.com/fluentassertions/fluentassertions/pull/2054)
* Nested AssertionScopes now print the inner scope reportables - [#2044](https://github.com/fluentassertions/fluentassertions/pull/2044)

## 6.8.0

Expand Down