Repository navigation
Fixing NoException! message in tests where an exception was expected,… - #2973
Mike Richmond (mirichmo) wants to merge 1 commit into
Conversation
… but one was not thrown.
|
😕 I have many cons:
try {
& $sb
throw "Expected FullyQualifiedErrorId: $expectedFqeid"
}
catch {
$_.FullyQualifiedErrorId | Should Be $expectedFqeid
}It seems the latter is most accurate but somewhat redundant and complex. |
|
Jason Shirk (@lzybkr) Any comments? |
| { | ||
| get-item "ThisFileCannotPossiblyExist" -ErrorAction Stop | ||
| throw "No Exception!" | ||
| throw "Expected an exception throw, but no Exception was thrown." |
There was a problem hiding this comment.
To be grammatically correct, shouldn't it be an exception throw*n*?
Personally, I find We shouldn't get here, the previous command should have thrown an exception. to be the clearest.
|
Ilya (@iSazonov) - Jason Shirk (@lzybkr) and I want a message that is more descriptive and self-documenting for the example. I don't expect the exact message to be reproduced in every test (although it would be nice). As long as the message clearly describes the scenario in the test failure log, then that should be sufficient. As you point out, there are different ways of applying the pattern and scrict adherence to that specific message may not always make sense (as shown in your example 5). |
|
Mike Richmond (@mirichmo) I'm trying to look at things from the other side. Sometimes this is useful. :-) |
|
I am closing this PR after discussing it with James Truher (@JamesWTruher). The point of "No Message!" is that it is a terse statement that is self-descriptive and reads well when observed in the Pester results. A more descriptive error message will not add value to the Pester output. Ilya (@iSazonov) You are welcome to go back and update the rest of the tests to conform to the "No Message!" string if you want to. However, your time and effort could be better spent addressing other issues or adding new features in the code base. |
|
Mike Richmond (@mirichmo) It seems I am somewhat perfectionist. :-) The thought about "No message!" inconsistance is already sitting in my head. If I'll have free time, I'll try to fix these tests. (I think this will save a lot of reviewer's time in future, because people won't copy-past bad files.) |
|
I'd prefer a helper function with a nice name like Other ways we could improve this - fix Pester, or introduce a "better" helper, maybe it would look something like: { Do-Something -ea Stop } | Should Throw { $_.FullyQualifiedErrorId | Should Be Blah }And if we don't change Pester, it can still look similar { Do-Something -ea Stop } | PSShouldThrow { $_.FullyQualifiedErrorId | Should Be Blah }The point here is - it still looks like |
|
Jason Shirk (@lzybkr) I open Issue pester/Pester#673 And nohwnd suggested that what you are talking about. Also nohwnd said that Paster 4 contains 'Should throw' improvements and will be released soon. |
|
If the new version is portable to .Net Core and Linux, then it would be good to pick it up. |
… but one was not thrown.
Fixes #2971