pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.08k stars 470 forks source link

-BeIn exception only shows the first 10 elements of the expected set #1305

Closed f0rt closed 3 years ago

f0rt commented 5 years ago

101 | Should -BeIn (1..100)

prints the following error message:

Expected collection @(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) to contain 101, but it was not found.

This is misleading since the expected set doesn't contain only 10 elements.

nohwnd commented 5 years ago

There was elipsis originally, I am not sure why I commented it out. Is it better like this?

101 | Should -BeIn (1..10)
Expected collection @(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...90 more) to contain 101, but it was not found.
At C:\projects\pester_main\Functions\Assertions\Should.ps1:186 char:9
+         throw ( New-ShouldErrorRecord -Message $testResult.FailureMes ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (System.Collections.Hashtable:Hashtable) [], Exception
    + FullyQualifiedErrorId : PesterAssertionFailed
f0rt commented 5 years ago

Looks good. Actually you can reverse the message because "101" is the object under test (not the collection):

Expected 101 to be one of the values in the collection @() ...

nohwnd commented 5 years ago

I won't change the order, the messages should have the same order in all assertions, and there is also -Because that gets inserted into the message when user specifies it. :)

nohwnd commented 3 years ago

Now in 5.2.1 it prints Expected collection @(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...) to contain 101, but it was not found.