1

プロパティを使用してオブジェクトを拡張する PowerShell コードにテキスト フィクスチャをラップしようとしています。Pester が原因と思われるエラーが表示されます。私がやろうとしていることを示す不自然な例を以下に示します。

Pester でプロパティを使用する関数のテストを書くことに成功した人はいますか?

私が得るエラー:

Describing Get-PropertyOfItem
Select-Object : Property cannot be processed because property "should" already exists.
At C:\Repos\ClinicientOps\clinicientops\General\Functions\Get-PropertyOfItem.ps1:4 char:11
+     $files | Select-Object *, @{Name = "TestProperty"; Expression = { $dir.Length}} ...
+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Windows:PSObject) [Select-Object], PSArgumentException
    + FullyQualifiedErrorId : AlreadyExistingUserSpecifiedPropertyNoExpand,Microsoft.PowerShell.Commands.SelectObjectCommand

私の機能:

function Get-PropertyOfItem {
    $dir = "C:\"
    $files = Get-ChildItem $dir
    $files | Select-Object *, @{Name = "TestProperty"; Expression = { $dir.Length}} -Last 1
}

私のテストコード:

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"

Describe "Get-PropertyOfItem" {

    It "does something useful" {

        $prop = Get-PropertyOfItem
        $prop.TestProperty.should.be(3)
    }
}
4

2 に答える 2

1

Pester バージョン 2.0.1が静かにリリースされました。期待を書き直す必要があります

$prop.TestProperty | Should Be 3

また、他のすべてのテストをこのパイプライン形式の Expectation 構文に移行する必要があることも意味します。

于 2013-02-03T15:24:39.340 に答える
1

バージョン 2 で調査中の制限のようです。

于 2012-11-30T20:04:54.697 に答える