This tests is written to show a pattern of how iteration will work in Pester 5.1 (as of Oct 23, 2020 is still in beta).
The function included in this test,
Get-FileEncoding, was sourced from Frank Richard's post.
ForEach can be used with the
Context blocks in your tests. The
Describe block you would execute code prior in order to provide the object (as I did for
Context is a bit different because a major change in Pester 5 was code that is to be run prior to a
It block has to be done within a
When you iterate over the objects and you want to reference the object in the description of the
It block you can use
<_>. Within code such as
BeforeAll you would use the same
$_ that we use in PowerShell piping. I use the later for setting variables in the
BeforeAll block such as
Pester Should Syntax
A major thing ot remember when you are converting your scripts, or writing new ones for Pester 5, is the syntax for Should statement is no being enforced. Previously we could just do
$true | Should Be $true but that will now error with the following:
RuntimeException: Legacy Should syntax (without dashes) is not supported in Pester 5. Please refer to migration guide at: http://pester.dev/docs/migrations/v3-to-v4
Instead you must use proper parameter syntax as
$true | Should -Be $true (notice the dash).