Skip to content

Commit 25ffa7c

Browse files
Fix formatting for Set-ItResult with because, removing trailing comma and redundant because (#2591)
Co-authored-by: Tyler Richardson <[email protected]>
1 parent ae8de8d commit 25ffa7c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/functions/Set-ItResult.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
}
9595

9696
if ($Because) {
97-
[String]$message += ", because $(Format-Because $Because)"
97+
[String]$formatted = Format-Because $Because
98+
[String]$message += ",$($formatted.SubString(0, $formatted.Length - 1))"
9899
}
99100

100101
throw [Pester.Factory]::CreateErrorRecord(

tst/functions/Set-ItResult.Tests.ps1

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ Describe "Testing Set-ItResult" {
2828
}
2929
}
3030

31+
It "Set-ItResult appends the -Because reason to the message" {
32+
try {
33+
Set-ItResult -Skipped -Because "we are forcing it to skip"
34+
}
35+
catch {
36+
$_.Exception.Message | Should -Be "is skipped, because we are forcing it to skip"
37+
}
38+
}
39+
3140
It "Set-ItResult can be called without -Because" {
3241
try {
3342
Set-ItResult -Skipped

0 commit comments

Comments
 (0)