Closed Jaykul closed 5 years ago
@ghostsquad had a good suggestion for this in #279 . By using dynamic parameter sets, we can support both the new and old syntax in calls to Should
, and we can also add aliases (where -Be
could also be -Eq
, if that's your preference.)
Yeah, I had one called Assert-That
from PSAINT which I was migrating over:
https://github.com/Jaykul/Pester/blob/Assertive/Functions/Assertions/Must.ps1
It basically just proxies Where-Object
with support for -Not
and adding -BeNullOrEmpty
as well as -All
and -Any
for working with arrays, so you can do:
1 | Must -Not -Equal 2
1,2,2 | Must -Not -All -Equal 2
But because it's proxying Where-Object, you can also test properties, and I added some aliases:
$result = @(1,2),@(1,3,5),@(2,4,6)
$result | Must -All Length -GE 2
$result | Must -All Length -NotBeLessThan 2
However, I haven't finished the tests, and as you can see here, currently it just returns true or false, instead of throwing a descriptive error:
https://github.com/Jaykul/Pester/blob/Assertive/Functions/Assertions/Must.Tests.ps1
At least we have a new form of Assertions for Pester 6 :D
So maybe should we change the label from 'Feature to ' 'Futurology'?
The operator syntax is already there provided by the aliases. Better assertions with better collection support are planned.
I think it would be awesome if we could provide a new syntax word which would map roughly to the syntax of Where-Object such that all of the PowerShell operators would work for assertions.
The logical thing would probably be to keep "Should" for the sake of pluggable assertions (but perhaps mark as obsolete the assertions which map to operators and would thus overlap), but perhaps we could find a way to make the new command work for both, and just mark "Should" as entirely obsolete (that is, obviously, leaving it in for now, but warning people to migrate to a new more PowerShell-specific syntax).
As a suggestion, we could use the keyword "must" with an alias "mustbe" ... so we could write things like: