Hey there,
For the powershell
track, I’d have love to have any potential error that can be dealt with in Validating Parameter
and have their business done there. It is idiomatic and clean just like you said.
However this lead back to the problem of having to match the default error message somewhat, instead of just following the one from the specs.
So there are two ways to solve this:
- Change the expected message to match some of the text from default error message, so you can match it however way you throw error.
- Either let pester just catch the error without any message / with any message text.
I don’t like particular like the second one in general, because inside a function there could be multiple points when an error happen and it would be great to know exactly what’s going on.
This is important because we have told new learner repeatedly that the test suite is the authoritative of information for them to use and solve the exercise. There are only a handful of instance where I chose this option because the wording for an error message can be customize in many fashions, and they are mostly belong to harder / later exercises when learners are already adept at throwing error and reading the test suite.
As for the first option, there are some upsides :
. Many new learners will have no idea about the Validating Parameter
property, but all of them can see how the throw
keyword being used in every stub and use that. So changing the text will validate the default and the custom error msg as long as they match that part.
. Keeping the test suite coherent and clear for new learners (this exercise is quite early on)
Potential downsides:
. Could lead to some awkward error messages.
This is the default msg when using the ValidateRange('Positive')
and -1
as input.
Cannot validate argument on parameter 'Number'. The argument -1" cannot be validated because its value is not greater than zero.
vs
Only positive numbers are allowed
If i have to change it to something to match, it probably gotta be something like Error: Input value is not greater than zero.
Shouldn’t be a problem for native speakers but a lot of people learning using English as secondary language, so keeping the msg easy to understand is key.
. Another downsize which matter a lot to the website is re-running test and breaking existing solutions, which is often discouraged unless really needed. Sure the code might not be idiomatic but they didn’t do anything wrong, breaking their solutions it would annoy people.
I can see a potential solution for this is to modify the test so there will be different accepted error msg. This way if either of the error msg hit then the test pass, allowing more options to check for error. But I haven’t done this before so I will need to check pester documentation to see how plausible it is to implement this.