Skip to content

Commit

Permalink
Nested AssertionScopes do not print inner scope reportables (#2044)
Browse files Browse the repository at this point in the history
  • Loading branch information
94sedighi committed Dec 17, 2022
1 parent 3999d05 commit 9e0a2e9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
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

0 comments on commit 9e0a2e9

Please sign in to comment.