Using Pester to test a PowerShell module, my mocked function doesnt return a value
How about casting to System.IO.DirectoryInfo
Get-HighestBuildNumber -buildRoot "C:\my\test\directory" | Should Be @([System.IO.DirectoryInfo]"12348")
or using the "Name" property
return $fakeListingOfDirectories.Name
?
I'm not at a machine where I can test this, but the Mock {}
scriptblock is likely not in the same scope as the Describe {}
scriptblock. I would rewrite your Describe{}
block like this:
Describe "Get-HighestBuildNumber" { Context "Get-ChildItem mocked to returns 12345, 12346, 12348, Foobar12349" { Mock -ModuleName EnvironmentSetup Get-ChildItem { @( "12345","12346","12348","Foobar12349" | % { New-Object System.IO.DirectoryInfo($_) } ) } it "should return 12348" { Get-HighestBuildNumber -buildRoot "C:\my\test\directory" | Should Be "12348" } }}