public
Created

Pester - Script variables should reset for every describe

  • Download Gist
1.WhatIHaveToDo.ps1
PowerShell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Describe "When installing packages from a packages.config manifest" {
$script:chocolatey_nuget_was_called = $false
$script:chocolatey_rubygem_was_called = $false
$script:chocolatey_webpi_was_called = $false
$script:packageName = ''
$script:version = ''
 
# content here
}
 
Describe "When installing packages from a packages.config manifest that doesn't exist" {
$script:chocolatey_nuget_was_called = $false
$script:chocolatey_rubygem_was_called = $false
$script:chocolatey_webpi_was_called = $false
$script:packageName = ''
$script:version = ''
 
# content here
 
}
2.WhatIWantToDo.ps1
PowerShell
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#all script variables automatically reset
#$script:chocolatey_nuget_was_called = $false
#$script:chocolatey_rubygem_was_called = $false
#$script:chocolatey_webpi_was_called = $false
#$script:packageName = ''
#$script:version = ''
 
Describe "When installing packages from a packages.config manifest" {
# content here
}
 
Describe "When installing packages from a packages.config manifest that doesn't exist" {
# content here
}
3.Workaround.ps1
PowerShell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
function Initialize-Variables {
$script:chocolatey_nuget_was_called = $false
$script:chocolatey_rubygem_was_called = $false
$script:chocolatey_webpi_was_called = $false
$script:packageName = ''
$script:version = ''
}
 
Describe "When installing packages from a packages.config manifest" {
Initialize-Variables
# content here
}
 
Describe "When installing packages from a packages.config manifest that doesn't exist" {
Initialize-Variables
# content here
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.