Pester Should -BeLike

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Pester Should -BeLike



I have this test


It 'Should not find environment' {

{Add-Patchgroup -ComputerName $serversHash.serverWithNotExistingEnvironment -WarningVariable warning -WarningAction SilentlyContinue}
$warning | Should -BeLike ('*55555*')
}



$warning contains this string (exactly as you see here with the newline and whitespace on the second row)


$warning


Could not add <nameOfTheServer> to patchgroup
Exception message: Environment F was not found



But my test is passing which should not:


Context Find the environment
[+] Should not find environment 79ms
[+] Should find environment 147ms



EDIT:



seems like the test is not working at all even with -Be parameter. The test is still passing.


-Be


$warning | Should -Be 'randomrandom'




1 Answer
1



I'm not sure why your test is passing, that is very strange. But I think part of your issue may be that you are executing your command within a scriptblock, and that therefore the warning variable is only populated/accessible within the scope of that scriptblock.



Also, generally I also tend to do my execution outside of the It and then only use the it block for the assertion.


It


it



I therefore suggest you try this:


Add-Patchgroup -ComputerName $serversHash.serverWithNotExistingEnvironment -WarningVariable warning -WarningAction SilentlyContinue

It 'Should not find environment' {
$warning | Should -BeLike '*55555*'
}



Note i've also removed the brackets around the string you are asserting $warning to be like, as I think these are redundant.


$warning






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

XXhO,w,jY A jJzHm,cch lTLzN,f1KP1T9A 2,BmWAH0CKs8 V0P ff4CLmFpM
PL3qe4u96o456,VdpAst4vt1Y0zPqSb,kpgNFKtmzw8C,F k97rWdi6KObENhgXm,IxT8 6kbTTwvHee7 l2d77wiL

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results