nspec / NSpec

A battle hardened testing framework for C# that's heavily inspired by Mocha and RSpec.
http://nspec.org/
MIT License
260 stars 57 forks source link

CleanMessage sometimes removes useful information #202

Closed DeCarabas closed 6 years ago

DeCarabas commented 6 years ago

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.

GiuseppePiscopo commented 6 years ago

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.

amirrajan commented 6 years ago

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.

BrainCrumbz commented 6 years ago

@DeCarabas is this still meaningful/important to you?

BrainCrumbz commented 6 years ago

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