Skip to content

Inaccurate MatchedBy error message #556

@jsvensson

Description

@jsvensson

This might sorta-maybe be related to #432.

I'm trying to use MatchedBy to verify that I get the proper object. When I have MatchedBy just return true tests work:

s.foo.On("UpdateFoo", mock.MatchedBy(func(foo *model.Foo) bool {
    return true
})).Return(nil)

However, as soon as I'm actually trying to compare values on foo like this:

s.foo.On("UpdateFoo", mock.MatchedBy(func(foo *model.Foo) bool {
    // LastSeen is a time.Time
    return foo.LastSeen.Equal(timer.Timestamp())
})).Return(nil)

Then I get this panic:

UpdateFoo(*model.Foo)
		0: &model.Foo{ /* stuff */}

The closest call I have is: 

UpdateFoo(mock.argumentMatcher)
		0: mock.argumentMatcher{fn:reflect.Value{typ:(*reflect.rtype)(0x769b00), ptr:(unsafe.Pointer)(0x8036c0), flag:0x13}}

Update: After plenty of staring at my test cases and spotting that my test values didn't line up with what I wanted to match it against, I isolated this to Testify returning that error as soon as MatchedBy can't match the object we're testing. Simply having MatchedBy return false will give the same error.

That error message should be changed to give some information about what caused it, in this case MatchedBy() failing to match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions