Last active
September 24, 2019 09:16
-
-
Save nohwnd/cdc24a9edbd1c963dc776c083777dc3d to your computer and use it in GitHub Desktop.
Check variable in parent scope, an interesting approach to testing a parent if condition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-Module m | Remove-Module | |
New-Module -Name m -ScriptBlock { | |
function Do-Expensive { } | |
} | Import-Module | |
function f () { | |
$variable = 2 | |
# if ($variable -eq 1) { | |
Do-Expensive | |
# } | |
} | |
Describe "a" { | |
It "b" { | |
Mock -CommandName "Do-Expensive" -MockWith { | |
if ($variable -ne 1) { | |
throw "Variable `$variable is not 1, it is $($variable)." | |
} | |
else { | |
Write-Host "Variable `$variable is 1." | |
} | |
} | |
f | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment