Comments (5)
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:
...
var stubbedObjectResult: Any // won't compile
func object(forKey defaultName: String) -> Any {
...
return stubbedObjectResult
}
The two ways to fix that would be to either:
var stubbedObjectResult: Any!
or:
return stubbedObjectResult!
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:
func object(forKey defaultName: String) -> Any?
to:
func object(forKey defaultName: String) -> Any
then the mock wouldn't have to be regenerated.
from swiftmockgeneratorforxcode.
Hi @seanhenry
Thank you for your answer, now I better understand your choice :)
It's not a huge problem, because my use case is that I want to test some methods with nil values, so I just have to change some generated code after using the generator, not the best practice because every time I use the generator I loose my changes, but in every case I save time thanks to your tool. Thank you very much !
from swiftmockgeneratorforxcode.
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:
class MyMock: MyType {
...
var stubbedObjectResult: Any!
func object(forKey defaultName: String) -> Any? {
...
return stubbedObjectResult
}
}
let mock = MyMock()
mock.object(forKey: "anyKey") == nil // true
from swiftmockgeneratorforxcode.
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 ! 👍
from swiftmockgeneratorforxcode.
👍
from swiftmockgeneratorforxcode.
Related Issues (20)
- Installation? HOT 1
- Using this with Objective C HOT 1
- Typo in permission error message
- Generated code does not follow the enclosing class access control HOT 1
- Extension doesn't work on Big Sur HOT 16
- ObjectToTest ???? HOT 2
- Can't find Mock Generator on Big Sur HOT 1
- import AST errors HOT 2
- Stubs are not generated when the member variable end in a '$'
- Optional properties have a force-unwrapped stub
- Installation via Homebrew
- Stopped working under Big Sur and Xcode 12.4 HOT 1
- Extensions not supported HOT 1
- Indentation follows Xcode ctrl-i
- Naming Conventions
- Generate async mocks HOT 6
- Cannot compile because of missing private framework `SwiftToolkit`
- Optional function parameter break generator
- Handle generic completion handlers in mocked function
- Can I enter it in the function?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftmockgeneratorforxcode.