diff --git a/tests/pester-tests/powershell-commands/Install-ChocolateyPath.Tests.ps1 b/tests/pester-tests/powershell-commands/Install-ChocolateyPath.Tests.ps1 index d6e4d094c..9ba4e0ebf 100644 --- a/tests/pester-tests/powershell-commands/Install-ChocolateyPath.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Install-ChocolateyPath.Tests.ps1 @@ -4,6 +4,8 @@ $testLocation = Get-ChocolateyTestLocation Import-Module "$testLocation\helpers\chocolateyInstaller.psm1" + + $Preamble = [scriptblock]::Create("Import-Module '$testLocation\helpers\chocolateyInstaller.psm1'") } AfterAll { @@ -15,28 +17,24 @@ @{ Scope = 'User' } @{ Scope = 'Machine' } ) { - Context 'Path "<_>"' -ForEach @("C:\test", "C:\tools") { - BeforeAll { - $Preamble = [scriptblock]::Create("Import-Module '$testLocation\helpers\chocolateyInstaller.psm1'") - } - - It 'stores the value in the desired PATH scope' { - $Command = [scriptblock]::Create("Install-ChocolateyPath -Path '$_' -Scope $Scope -WhatIf") - - $results = @( Get-WhatIfResult -Preamble $Preamble -Command $Command ) - $results[0] | Should -BeExactly "What if: Performing the operation ""Set $Scope environment variable"" on target ""PATH""." - - if ($Scope -ne 'Process') { - $results[1] | Should -BeExactly 'What if: Performing the operation "Notify system of changes" on target "Environment variables".' - $results[2] | Should -BeExactly 'What if: Performing the operation "Refresh all environment variables" on target "Current process".' - } + It 'stores the value <_> in the desired PATH scope' -TestCases @("C:\test", "C:\tools") { + $Command = [scriptblock]::Create("Install-ChocolateyPath -Path '$_' -Scope $Scope -WhatIf") + + $results = @( Get-WhatIfResult -Preamble $Preamble -Command $Command ) + $results[0] | Should -BeExactly "What if: Performing the operation ""Set $Scope environment variable"" on target ""PATH""." + + if ($Scope -ne 'Process') { + $results[1] | Should -BeExactly 'What if: Performing the operation "Notify system of changes" on target "Environment variables".' + $results[2] | Should -BeExactly 'What if: Performing the operation "Refresh all environment variables" on target "Current process".' } + } - It 'skips adding the value if it is already present' { - $targetPathEntry = [Environment]::GetEnvironmentVariable('PATH', $Scope) -split ';' | Select-Object -First 1 - $Command = [scriptblock]::Create("Install-ChocolateyPath -Path '$targetPathEntry' -Scope $Scope -WhatIf") - Get-WhatIfResult -Preamble $Preamble -Command $Command | Should -BeNullOrEmpty -Because 'we should skip adding values that already exist' - } + It 'skips adding the value if it is already present' { + $Command = [scriptblock]::Create(@" +`$targetPathEntry = [Environment]::GetEnvironmentVariable('PATH', '$Scope') -split ';' | Select-Object -First 1 +Install-ChocolateyPath -Path '`$targetPathEntry' -Scope $Scope -WhatIf +"@) + Get-WhatIfResult -Preamble $Preamble -Command $Command | Should -BeNullOrEmpty -Because 'we should skip adding values that already exist' } } diff --git a/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 b/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 index 7a1c081a1..6e13533fb 100644 --- a/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 +++ b/tests/pester-tests/powershell-commands/Update-SessionEnvironment.Tests.ps1 @@ -12,7 +12,7 @@ $Command = [scriptblock]::Create("Update-SessionEnvironment -WhatIf") $results = Get-WhatIfResult -Preamble $Preamble -Command $Command - $results | Should -BeExactly 'What if: Performing the operation "refresh all environment variables" on target "current process".' + $results | Should -BeExactly 'What if: Performing the operation "Refresh all environment variables" on target "Current process".' } }