Created
May 11, 2016 16:10
-
-
Save sixdub/10edb2506d8cd268a4c447774ed8d541 to your computer and use it in GitHub Desktop.
Can you Mock an internal locally scoped function in Pester?
This file contains hidden or 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
######## SCRIPT EXAMPLE ######## | |
function Do-SomethingStupid | |
{ | |
function local:Get-NumberFive | |
{ | |
return 5 | |
} | |
$value = Get-NumberFive | |
if (value -ne 5) | |
{ | |
throw "ERROR" | |
} | |
Write-Output "Value $value" | |
} | |
######### PESTER TEST ####### | |
$here = Split-Path -Parent $MyInvocation.MyCommand.Path | |
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' | |
. "$here\$sut" | |
Describe "Do-SomethingStupid" { | |
Context 'Wrong value returned' { | |
#### THIS MOCK WILL NOT WORK. I GET AN ERROR ON VALIDATE-FUNCTION #### | |
Mock Get-NumberFive {2} | |
It 'Should not fail due to wrong value' { | |
{Do-SomethingStupid} | Should Throw | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment