stuartleeks / PesterMatchArray

Array assertions for Pester
MIT License
10 stars 0 forks source link

Why does it differ? #5

Open DarkLite1 opened 7 years ago

DarkLite1 commented 7 years ago

Thank you for the great add-on to Pester. I would like to use your module but for some reason or another it's saying that the following arrays are not equal:

Import-Module PesterMatchArray

$Result = @(
    [PSCustomObject]@{
        'First Name' = 'Chuck'
        'Address'    = 'California'
    }
    [PSCustomObject]@{
        'First Name' = 'Jean-Claude'
        'Address'    = 'Brussels'
    }
)

$ExpectedResult = @(
    [PSCustomObject]@{
        'First Name' = 'Chuck'
        'Address'    = 'California'
    }
    [PSCustomObject]@{
        'First Name' = 'Jean-Claude'
        'Address'    = 'Brussels'
    }
)

$Result | Should MatchArrayOrdered $ExpectedResult

It throws the following error:

Differs at index 0. Expected: { }. Actual: {}.
At C:\Program Files\WindowsPowerShell\Modules\Pester\4.0.6\Functions\Assertions\Should.ps1:190 char:9
+         throw ( New-ShouldErrorRecord -Message $testResult.FailureMes ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (System.Collections.Hashtable:Hashtable) [], Exception
    + FullyQualifiedErrorId : PesterAssertionFailed

Thank you for your help.

DarkLite1 commented 7 years ago

The problem appears to be here:

function FindMismatchedValueOrdered($value, $expectedMatch) {
    $value = @($value)
    for ($i = 0; $i -lt $expectedMatch.Length -and $i -lt $value.Length; $i++) {
        if (-not($value[$i] -eq $expectedMatch[$i])) {
            return "Differs at index $i. Expected: {$expectedMatch}. Actual: {$value}."
        }

It's not designed to inspect the property values and names of objects. Could this be added?