Private/Invoke-PoshspecExpression.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<#
.SYNOPSIS
    Executes a Pester 'It' block using values generated by Get-PoshspecParam
.EXAMPLE
    Invoke-PoshspecExpression -InputObject ([pscustomobject]@{Name = "File 'C:\Temp' Should -Exist"; Expression = "'C:\Temp' | Should -Exist" })
#>

function Invoke-PoshspecExpression {
    [CmdletBinding()]
    param(
        # Poshspec Param Object
        [Parameter(Mandatory, Position=0)]
        [PSCustomObject]
        $InputObject
    )
    
    Write-Verbose -Message "Invoking 'it' block with expression: $($InputObject.Expression)"
    It $InputObject.Name {
        Invoke-Expression $InputObject.Expression
    }    
}