You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the Assertion in the PoshSpec is placed inside a scriptblock, how does one reference variables in it e.g below works fine when the assertion is hardcoded -:
Describe test {
Service Bits Status {Should be 'Running'}
}
But when a variable is placed in the assertion, it can't see them e.g.
Describe test {
$DesiredStatus = 'Running'
Service Bits Status {Should be $DesiredStatus}
}
Above gives me the error -:
Describing test
[-] Service property 'Status' for 'Bits' Should be $DesiredStatus 123ms
Expected: {}
But was: {Running}
1: Get-Service -Name 'Bits' | Select-Object -ExpandProperty 'Status' | Should be $Desir
edStatus
at <ScriptBlock>, <No file>: line 1
at <ScriptBlock>, C:\Users\Deepak_Dhami\Documents\GitHub\poshspec\Private\Invoke-Poshsp
ecExpression.ps1: line 12
The idea is to use a CSV file as a template for all the service and their compliant status.
How do I do something like this with PoshSpec ?
Describe 'IT Compliance for Services' {
$ObjectFromCSV = @([PSCustomObject]@{
Name='Bits';
Status='Stopped'
})
$ObjectFromCSV.Foreach({
Service $PSItem.Name Status {Should be $PSItem.Status}
})
}
The text was updated successfully, but these errors were encountered:
I would say that is an architectural limitation of PoshSpec that will not be addressed in the short-term. I think there are two work arounds: you can create a loop for each State you want to test and hard code the test value; or, you can declare a variable with Global scope.
Since the Assertion in the PoshSpec is placed inside a scriptblock, how does one reference variables in it e.g below works fine when the assertion is hardcoded -:
But when a variable is placed in the assertion, it can't see them e.g.
Above gives me the error -:
The idea is to use a CSV file as a template for all the service and their compliant status.
How do I do something like this with PoshSpec ?
The text was updated successfully, but these errors were encountered: