Open littledot opened 7 years ago
👍
sounds great, as well as I need a feature to On() receive a function pointer as a parameter
I'm really interested in this. The issue is old. Do you know if anyone implemented it somewhere may be a fork ?
I can try to implement it in few weeks
The current implementation is a bit frustrating for me when I refactor code with my IDE, the string used everywhere are not updated, and I have to manually edit tons of files.
based on a quick code check, I think the code needed to implement it is close to what is currently in (m *Mock) Called
for further reading: https://stackoverflow.com/questions/7052693/how-to-get-the-name-of-a-function-in-go
but I don't plan to work on it, until someone confirms it's not already implemented somewhere
@ccoVeille @littledot you might try https://github.com/go-andiamo/mmock
@ccoVeille @littledot you might try https://github.com/go-andiamo/mmock
Thanks. I love it. I will try.
How far is your code from testify? Do you think it could it be integrated in testify via a PR?
I didn't read your code yet. I'm in holidays with only a phone for now.
testify provides the On() function to set up mock expectations, which uses a string to identify the mocked function. However, Go provides an API runtime.FuncForPC() which allows users to obtain a function pointer's name.
https://play.golang.org/p/RAB0zOkB0L
What are your thoughts on providing a new API similar to On() which accepts function pointers in the form of interface{} instead of string? The implementation would then parse the function pointer's name to identify the method that needs mocking. I think this could really reduce pains in refactoring code - such as method renaming - because tools can now pick up these tokens.