Skip to content

Should.be() fails when comparing object and true #1183

@GeeWee

Description

@GeeWee

Description

If I have an object and I use Should().Be() to compare it to a boolean, it will always pass, if passed in true, but fail correctly when passed in false.

See the example below:

// For unrelated reasons I have an object as a number
object myNumber = 10;

// This should not work, they're not identical, but it passes
myNumber.Should().Be(true);

// The opposite arrangement fails properly
((object)true).Should().Be(myNumber);

// Comparing the number to false, fails properly as well
myNumber.Should().Be(false);

Versions

FluentAssertions 5.9.0 targeting .NET Core 3.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions