-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Description
Mock.IsMethodCallable
implements its own incomplete expected argument checking. So it doesn't always work. It should be using the same methods as Mock.Called
to check if it is callable.
It also has no reason to accept a TestingT, it doesn't use it at all, there is no point calling Helper, which also isn't part of TestingT.
I also see no sensible use case for IsMethodCallable.
Description
If the expected Args of a Call in Mock.ExpectedCalls are dynamic (mock.Anything, mock.MatchedBy, etc...) then Mock.IsMethodCallable will return the wrong answer.
Step To Reproduce
package kata_test
import (
"testing"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
type MyMock struct {
mock.Mock
}
func TestEventuallyFast(t *testing.T) {
m := &MyMock{}
m.On("MyMethod", 1).Return()
m.On("MyMethod", mock.Anything).Return()
require.True(t, m.IsMethodCallable(t, "MyMethod", 1))
require.True(t, m.IsMethodCallable(t, "MyMethod", 2))
}
Expected behavior
Testcase passes
Actual behavior
m.IsMethodCallable(t, "MyMethod", 2)
incorrectly returns false.