我想圍繞一些擴展帶屬性的對象的PowerShell代碼包裝文本夾具。我得到一個似乎是由於pester引起的錯誤。我在下面有一個人爲的例子,顯示了我正在嘗試做的事情。使用具有屬性的'Pester'(Powershell單元測試框架)
有沒有人成功地在使用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.SelectObjectC
ommand
我的功能:
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)
}
}
從上糾纏的github上scottmuc: 。「呸,好像對象擴展導致更多的問題,我們正在考慮去掉$ object.should擴展,並使用管道基於斷言的2.0版本應該解決這個問題」 https://github.com/pester/Pester/issues/33 – msgisme