Skip to content

Commit

Permalink
Message fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd committed Oct 7, 2024
1 parent 30ce6e9 commit 6fb23b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/functions/assert/Collection/Should-BeCollection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

if ($PSCmdlet.ParameterSetName -eq 'Count') {
if ($Count -ne $Actual.Count) {
$Message = Get-AssertionMessage -Expected $Count -Actual $Actual.Count -Because $Because -DefaultMessage "Expected <expected> items in <actualType> <actual>, but it has <actualCount> items."
$Message = Get-AssertionMessage -Expected $Count -Actual $Actual -Because $Because -Data @{ actualCount = $Actual.Count } -DefaultMessage "Expected <expected> items in <actualType> <actual>,<because> but it has <actualCount> items."
throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true)
}
return
Expand All @@ -73,7 +73,7 @@
}

if (-not (Is-CollectionSize -Expected $Expected -Actual $Actual)) {
$Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected <expectedType> <expected> to be present in <actualType> <actual>, but they don't have the same number of items."
$Message = Get-AssertionMessage -Expected $Expected -Actual $Actual -Because $Because -DefaultMessage "Expected <expectedType> <expected> to be present in <actualType> <actual>,<because> but they don't have the same number of items."
throw [Pester.Factory]::CreateShouldErrorRecord($Message, $MyInvocation.ScriptName, $MyInvocation.ScriptLineNumber, $MyInvocation.Line.TrimEnd([System.Environment]::NewLine), $true)
}

Expand Down
5 changes: 5 additions & 0 deletions tst/functions/assert/Collection/Should-BeCollection.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ Describe "Should-BeCollection" {
) {
$_ | Should-BeCollection -Count 1
}

It "Fails when collection does not have the expected number of items" {
$err = { @(1, 2) | Should-BeCollection -Count 3 } | Verify-AssertionFailed
$err.Exception.Message | Verify-Equal "Expected 3 items in [Object[]] @(1, 2), but it has 2 items."
}
}
}

0 comments on commit 6fb23b0

Please sign in to comment.