-
-
Notifications
You must be signed in to change notification settings - Fork 479
Description
1. General summary of the issue
In writing tests to ensure the accurate fixing of the issue resolved by this PR, I discovered that Should can and will differentiate between a complete array passed over the pipeline and an enumerated array, and it seems to expect the latter.
Simple repro:
$a = 1, 2, 3
,$a |Should -Be $a2. Describe Your Environment
Operating System, Pester version, and PowerShell version:
Pester version : 4.3.1 C:\Program Files\PowerShell\Modules\Pester\4.3.1\Pester.psd1
PowerShell version : 6.1.0
OS version : Microsoft Windows NT 10.0.17763.0
3. Expected Behavior
Should should more clearly indicate what is happening, with either symbolic representation of the different element that more closely reflects what's happened on the command line, or by explicitly calling out the fact that the two arrays are different in some other way.
Bonus: perhaps an optional switch or operator might be a good idea that doesn't check for this, however this is getting picked up.
4.Current Behavior
Clearly, it is able to distinguish between what is a multidimensional array that has been enumerated, and a flat array. However, its error message is the polar opposite of clear. π
Simple example:
PS> $a = 1, 2, 3
PS> ,$a |Should -Be $a
Expected @(1, 2, 3), but got @(1, 2, 3).
At C:\Program Files\PowerShell\Modules\Pester\4.3.1\Functions\Assertions\Should.ps1:206 char:9
+ throw ( New-ShouldErrorRecord -Message $testResult.FailureMes ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collections.Hashtable:Hashtable) [], Exception
+ FullyQualifiedErrorId : PesterAssertionFailed6. Context
It was noted that Get-Variable passes collections whole over the pipeline, thus similar to the original example, this too throws a strangely confusing error. This particular case is fixed in the linked PR, however, making the command properly enumerate collections when outputting.
$v = 1, 2, 3
Get-Variable -Name v -ValueOnly | Should -Be $v