-
Notifications
You must be signed in to change notification settings - Fork 46
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
Optional in stubbed properties #23
Comments
Hi @fmirault Thanks for raising this issue. I can see why you would want the type to match the return type in the method but this was my reasoning for the decision: If the type of the stub property exactly matches the return type of the method then it won't always compile. Example when method returns guaranteed value:
The two ways to fix that would be to either:
or:
The first approach works for all return types and the second option makes the mock a little more complex. So I opted to keep things simpler, but also more flexible. For example, if you were to change the signature of:
to:
then the mock wouldn't have to be regenerated. |
Hi @seanhenry Thank you for your answer, now I better understand your choice :) |
No problem. I'm glad you like it :) Do you mean you need your mock method to return nil? If so, you don't need to change the generated mock because it will return nil by default because the IUO will be converted to an optional. Example:
|
Oh you're right! I thought that I will have a crash (I don't really know why...) but it's working, so I don't have to change anything in the generated code, thank you ! 👍 |
👍 |
Hi!
I just used the mock generator for the first time, and I noticed that the stubbed properties don't match the signature method.
For example, if a method has this signature
func object(forKey defaultName: String) -> Any?
, the associated stubbed property isvar stubbedObjectResult: Any!
.I'd like to have instead of this
var stubbedObjectResult: Any?
, but maybe there is a reason that I don't get to not be able to have correct stubbed object ?The text was updated successfully, but these errors were encountered: