diff --git a/src/functions/Set-ItResult.ps1 b/src/functions/Set-ItResult.ps1 index 6dfc8da33..d7f2cf672 100644 --- a/src/functions/Set-ItResult.ps1 +++ b/src/functions/Set-ItResult.ps1 @@ -81,7 +81,8 @@ } if ($Because) { - [String]$message += ", because $(Format-Because $Because)" + [String]$formatted = Format-Because $Because + [String]$message += ",$($formatted.SubString(0, $formatted.Length - 1))" } throw [Pester.Factory]::CreateErrorRecord( diff --git a/tst/functions/Set-ItResult.Tests.ps1 b/tst/functions/Set-ItResult.Tests.ps1 index ed7f642a9..91622e4be 100644 --- a/tst/functions/Set-ItResult.Tests.ps1 +++ b/tst/functions/Set-ItResult.Tests.ps1 @@ -19,6 +19,15 @@ Describe "Testing Set-ItResult" { } } + It "Set-ItResult appends the -Because reason to the message" { + try { + Set-ItResult -Skipped -Because "we are forcing it to skip" + } + catch { + $_.Exception.Message | Should -Be "is skipped, because we are forcing it to skip" + } + } + It "Set-ItResult can be called without -Because" { try { Set-ItResult -Skipped