Closed renehamburger closed 10 years ago
If you are trying to add name of assertion it can be done in Assertion.add
, with arguments as they was passed in test sources, it is harder. But i do not think that wrap every call in function it is an option (not everyone uses cs).
Yes, we could add a name or description for the assertion, but that would be a lot of additional code if we did that for every assertion.
I agree that the function wrapper is a bit cumbersome in JavaScript, so I don't expect many or any JavaScript users to make use of this feature. But for CoffeeScript users this would be a great feature. I think that nothing is as descriptive as the actual assertion code when it comes to quickly seeing why a test failed.
Another reason for providing this feature for CoffeeScript is that the line numbers in the stack trace for failed assertion refer to the compiled js files, so it's always a step more in CS to figure out which assertion failed.
So summing:
.caller
.I will not accept it. For myself better for all do 2 PR for mocha, one to support source maps for mocha and second to show lines of tests which failed.
OK, this is your decision, but let me just clarify a few points:
expected true to equal false
. But wouldn't it be much better to add the original assertion res.body.something.should.eql(false)
to this??I agree with most of your points. The syntax and implementation makes it cumbersome to use.
Regarding (4), I do think assertion libraries should present as much information as possible in absence of a message being passed to the assertion.
Wikipedia is by no means authoritative, but I think many developers expect similar results from their assertion library: "Since an assertion failure usually reports the code location, one can often pin-point the error without further debugging"
Another example is the pytest library which has even more powerful assertion introspection.
If we go instead with an implementation similar to wish assertion library, I believe we could get all of the benefits of better output without uglyness of anonymous function call wrappers.
Would you consider a PR based on this?
The way that we use should, we often run into issues with AssertionError messages not being specific enough to distinguish several should calls within the same test.
The changes suggested here add the original should call as a string to the AssertionError object
.message
and as a separate.call
property. It requires the original call to be wrapped in an anonymous self-invoking function, which is easily done in CoffeeScript:do -> a.should.eql(b)
.The original call is then printed out with the error message and, with a small change in mocha's 'reporters/base.js' on Line 356:
+ (err.call ? err.call + '\n\n' : '')
, also by mocha's inline diff.If you're interested in merging this feature in, I can add a couple of tests.