diff --git a/Src/FluentAssertions/Execution/AssertionScope.cs b/Src/FluentAssertions/Execution/AssertionScope.cs index 69c5c85a1b..5c84beb23e 100644 --- a/Src/FluentAssertions/Execution/AssertionScope.cs +++ b/Src/FluentAssertions/Execution/AssertionScope.cs @@ -395,6 +395,7 @@ public void Dispose() parent.assertionStrategy.HandleFailure(failureMessage); } + parent.contextData.Add(contextData); parent.AppendTracing(tracing.ToString()); parent = null; diff --git a/Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeEquivalentTo.cs b/Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeEquivalentTo.cs index 166c2ef16c..2f4cb231a8 100644 --- a/Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeEquivalentTo.cs +++ b/Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeEquivalentTo.cs @@ -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() - .WithMessage("Expected actual not to be equivalent *failure message*, but found ."); + .WithMessage("Expected actual not to be equivalent *failure message*, but found .*"); } [Fact] diff --git a/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs b/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs index 47a5aec385..8576323280 100644 --- a/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs +++ b/Tests/FluentAssertions.Specs/Execution/AssertionScopeSpecs.cs @@ -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("innerReportable").Should().Be("bar"); + } + } + public class CustomAssertionStrategy : IAssertionStrategy { private readonly List failureMessages = new(); diff --git a/docs/_pages/releases.md b/docs/_pages/releases.md index cf8572970f..ea723ba039 100644 --- a/docs/_pages/releases.md +++ b/docs/_pages/releases.md @@ -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