nspec/NSpec

CleanMessage sometimes removes useful information

Closed this issue · 4 comments

I'm writing code that formats console output, and I'm writing tests for that code. The tests include assertions like:

            context["midpoint"] = () =>
            {
                before = () => { min = 3; p80 = 3; max = 5; };
                it["renders correctly"] = () => bar.Should().Be("|    x    |");
            };

Unfortunately, when the console formatter runs it calls DomainExtensions.CleanMessage(), which removes duplicate whitespace from the failure message, and I get errors like:

    midpoint
      renders correctly (28ms) - FAILED - Expected string to be "| x |", but "| x |" differs near " x " (index 3).

I have no doubt that this behavior is useful and makes many systems report better errors, but in my case it makes the assertion messages much less helpful.

It would be nice if I could do something to tell NSpec to preserve whitespace here.

Not sure why double whitespaces are removed from exception message. And looking at blame results that's something dating back 7 years ago straight from original NSpec creator.

Maybe @amirrajan knows the rationale behind it.

To me, it always seems somehow complicated to pass flags to the test framework, as that depends a lot from the external testing harness (command line? which one? / Visual Studio? which one?). So I might as well propose not to remove double whitespace at all.

Not sure how such (breaking?) change would impact all tests around, so there again maybe some form of switch is better.

Let's see what Amir comes up with.


Edit: let's not forget that new formatters can be added and then specified (again, as flags) when running. So one possibility could be to have a non-deleting console formatter, and use that instead of default one.

Looks like something I would have done to help other formatters and clean up construction of Exception messages (whether the exception came from NSpec in an act, before, after, or if it were an inner exception).

I'd say remove the scrubbing.

@DeCarabas is this still meaningful/important to you?

Closing this for inactivity, please feel free to re-open if needed