Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol Mock in library has internal initializer #340

Open
AnthonyMillerSF opened this issue Apr 16, 2020 · 4 comments
Open

Protocol Mock in library has internal initializer #340

AnthonyMillerSF opened this issue Apr 16, 2020 · 4 comments
Labels
awaiting reply A Cuckoo maintainer is awaiting reply from the issue/PR creator. enhancement good first issue If you're looking to contribute, this issue is the way to go!

Comments

@AnthonyMillerSF
Copy link

I have a library that I generate all of my mocks into that is imported in my unit tests. When mocking a protocol, the generated mock object doesn't have an initializer declared. This means is uses the default initializer, which would be fine, except the default init() method is internal. I can get around this by importing my mock library @testable, but I'd suggest that protocol mocks for public protocols have a public init() {} method generated.

@MatyasKriz
Copy link
Collaborator

Hey, @AnthonyMillerSF, I understand where you're coming from. However, method accessibility is a tricky subject because we might fix this use case and break N others. I'm not against implementing this if it's tested thoroughly enough to rule out issues that might arise from it.
If you're up for it, by all means, file a PR along with some tests and we'll take a look and merge it as long as it's not a breaking change for others.

@MatyasKriz MatyasKriz added awaiting reply A Cuckoo maintainer is awaiting reply from the issue/PR creator. good first issue If you're looking to contribute, this issue is the way to go! help wanted This issue is asking for a way to solve a problem. labels Apr 18, 2020
@MatyasKriz MatyasKriz removed the help wanted This issue is asking for a way to solve a problem. label May 21, 2020
@mwoollard
Copy link

I've just taken a look at Cuckoo and hit same issue. Our codebase is highly modular (private Cocoapods spec repo) and wanted to have each pod have a 'Mock' sub-spec that contains mocked versions of the protocols in the module. Maybe way to deal with compatibility is to have a command line option to turn generating of protocol initialisers on? Might take a look at implementing this if this is thought a sensible approach.

@MatyasKriz
Copy link
Collaborator

Hey, @mwoollard. Unless @AnthonyMillerSF's proposal doesn't work for all use-cases, I'd rather avoid polluting the generator arguments.
I reckon that generating an init with no parameters (and the same accessibility as the generated class) shouldn't break anything; provided there is no init with any number of parameters declared in the protocol itself.
We'll probably see where we fall with a concrete implementation and a bit more extensive tests on protocol inits. I hope we won't need to add another argument to the generator, further increasing the complexity.

@mwoollard
Copy link

If @AnthonyMillerSF's proposal works for all use-cases would see that as preferable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reply A Cuckoo maintainer is awaiting reply from the issue/PR creator. enhancement good first issue If you're looking to contribute, this issue is the way to go!
Projects
None yet
Development

No branches or pull requests

3 participants