Eventually, I've managed to create something like that. If you haven't seen it yet, you can find it here: Introducing Spyable: A Swift Macro for Automatic Spies Generation - #8 by Matejkob. In the current version, I've covered all cases that AutoMockable from Sorcery covers, but as you mentioned, there are a lot of edge cases. I would be very glad if you could contribute to this project. It would be awesome if you could add issues to the repo outlining the cases that you encounter during your own testing of this approach. Additionally, if you have any cool functionality in mind that you think could enhance the project, feel free to make a PR! ![]()
Have you been able to build a library or tool out of this? If yes, is there a chance that I could check it out on GitHub? I'm curious to see how your solution compares to a tool I've been working on, called Spyable. There's always something new to learn from the way others approach similar problems, and perhaps we could even extract the best solutions from each to create a more robust tool.
The ideal situation here, would be that a protocol extension, or a class conforming to a protocol could have access to the methods defined in such protocol, right?
For example
protocol ProductsRepository {
func search(query: String)
}
// in tests we could do either:
@Mock
extension ProductsRepository {}
// or
func test() {
@Mock let repo: ProductsRepository
}
// or
@Mock
class MockProduictsRepository: ProductsRepository {}
// or
@Mock(ProductsRepository.self)
class MockProductsRepository {}
Or something along these lines..
Problem is, MemberDeclListItem is always nil or just not there when you try to do it in these ways.
Perhaps I'm just writing it wrong, or it's just not how macros work?
Hi! I've been looking at your source code and that looks great! congrats! Currently my approach was only a POC that what could be done using macros, so your solutions is far more advanced than mine. Anyway if you feel curious DM me and I'll send you the code.
I understand where you're coming from, but I'm afraid the proposed solution is not going to work as expected. Rather than repeating the full explanation here, I'd like to refer you to another thread where we've discussed this in detail: Introducing Spyable: A Swift Macro for Automatic Spies Generation - #10 by Matejkob. Feel free to join that conversation or reach out if you have further questions or ideas! ![]()