-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fixing NoException! message in tests where an exception was expected,… #2973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
|
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
@iSazonov - @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). |
|
@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 @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. @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. |
|
@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 |
|
@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