Make spies use the annotated protocol's access level
dafurman opened this issue · 3 comments
Is your feature request related to a problem? Please describe.
I have a public protocol that I'd like to create a spy for, and I'd like to use that spy in different module. Currently, the spy seems to always be created as implicitly internal, which prevents this.
Ex:
public protocol MyCoolThing { ... }
should produce
public class MyCoolThingSpy { ... }
Likewise:
protocol MyCoolThing { ... }
should produce
class MyCoolThingSpy { ... }
Describe alternatives you've considered
If we don't want to just match the access type of the protocol, this could be a parameter, like @Spyable(accessLevel: .public)
that defaults to internal. I'm not sure I like this approach, but it is an option.
Additional context
I'm happy to create a PR for this, but I'm just wanting to note it as an issue first.
Hey there,
First off, thanks for raising this issue! 🫶
Regarding the feature request you've proposed: it's an interesting point you're bringing up about the access levels for generated spy classes. However, have you considered using the @testable
attribute when importing the module that contains the spy? This way, you'd have access to the implicitly internal classes and members for testing purposes without having to change their access level. Would that work for your use-case?
Looking forward to your thoughts!
However, have you considered using the @testable attribute when importing the module that contains the spy?
Ah that's such a better idea! I didn't think of that. Yep, that totally works to solve my issue, thanks! I think that pretty much makes my suggestion unneeded so I'll close this issue.
Awesome, I'm glad to hear that it solves your issue! No worries about the suggestion; it was a valid point to bring up, and discussions like this can often lead to enhancements or uncover best practices.
Feel free to close the issue, and if you have any more ideas or run into any more challenges, don't hesitate to share. Thanks again for your proactive involvement in improving swift-spyable!