Skip to content

Commit

Permalink
Support nested runs
Browse files Browse the repository at this point in the history
  • Loading branch information
fflaten committed Jul 14, 2024
1 parent 31f34bf commit 22ef754
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/functions/Mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,8 @@ function FindMatchingBehavior {

$foundDefaultBehavior = $false
$defaultBehavior = $null
# A mock exists so we do not allow original command to be called. Either:
# - A parameterized mock explicitly allows it below
# - Or a default mock exists which takes precedence either way
$fallbackAllowed = $false
# Allow fallback unless parameterized behaviors exist. Required to support nested runs where mock exists but no behaviors.
$blockOriginalCommand = @($Behaviors).IsDefault -contains $false
foreach ($b in $Behaviors) {

if ($b.IsDefault -and -not $foundDefaultBehavior) {
Expand All @@ -1012,7 +1010,7 @@ function FindMatchingBehavior {
return $b
}

if ($b.AllowFallback) { $fallbackAllowed = $true }
if ($b.AllowFallback) { $blockOriginalCommand = $false }
}
}

Expand All @@ -1027,7 +1025,7 @@ function FindMatchingBehavior {
Write-PesterDebugMessage -Scope Mock "No parametrized or default behaviors were found filter."
}

if (-not $fallbackAllowed) {
if ($blockOriginalCommand) {
throw 'Not implemented. None of the parameterized mocks match the call or accept fallback to original command.'
}

Expand Down

0 comments on commit 22ef754

Please sign in to comment.