As highlighted by this issue, there are some changes in the way Should Be works. At the current point the $Actual side of the assertion determines the type to be used to do the equality check, and in v3 the $Expected side determines the type to be used.
This leads to subtle bugs where the expected value is upgraded to a reference type and compared by reference instead of by value.
Here the expected string value is upgraded to script block:
describe "a" {
it "b" {
{hello} | should be "hello"
}
}
# [-] b 29ms
# Expected: {hello}
# But was: {hello}
# at line: 3 in
# 3: {hello} | should be "hello"
Here the expected value is upgraded to Boolean (sting False becomes $true boolean):
describe "a" {
it "b" {
$false | should be False
}
}
# [-] b 27ms
# Expected: {False}
# But was: {False}
# at line: 3 in
# 3: $false | should be False
In v4 this is equivalent to doing $Actual -eq $Expected, where the left side determines the type. The actual code to be modified is here https://github.com/pester/Pester/blob/DevelopmentV4/Functions/Assertions/Be.ps1#L214 (as well as on 210 and possibly other lines).
TODO:
I need to write tests to highlight the issue.
See how it behaves for object types.
Possibly make the exception messages better by mentioning the types.
Go through all assertions and make sure the $expected side is on the left and $actual on the right (in assertions where it makes sense).
Check if the behavior makes sense if there is reference type on the Expected side and value type on the actual side.
As highlighted by this issue, there are some changes in the way
Should Beworks. At the current point the$Actualside of the assertion determines the type to be used to do the equality check, and in v3 the$Expectedside determines the type to be used.This leads to subtle bugs where the expected value is upgraded to a reference type and compared by reference instead of by value.
Here the expected string value is upgraded to script block:
Here the expected value is upgraded to Boolean (sting False becomes $true boolean):
In v4 this is equivalent to doing
$Actual -eq $Expected, where the left side determines the type. The actual code to be modified is here https://github.com/pester/Pester/blob/DevelopmentV4/Functions/Assertions/Be.ps1#L214 (as well as on 210 and possibly other lines).TODO:
I need to write tests to highlight the issue.
See how it behaves for object types.
Possibly make the exception messages better by mentioning the types.
Go through all assertions and make sure the
$expectedside is on the left and$actualon the right (in assertions where it makes sense).Check if the behavior makes sense if there is reference type on the Expected side and value type on the actual side.