Allow passing an array of values to stub#551
Allow passing an array of values to stub#551jdanthinne wants to merge 2 commits intoBrightify:masterfrom
Conversation
| func testReturningArray() { | ||
| let mock = MockTestedClass() | ||
| stub(mock) { mock in | ||
| when(mock.readOnlyProperty.get).thenReturn(["a", "b", "c"]) |
There was a problem hiding this comment.
Won't this be ambiguous when the property is an array?
There was a problem hiding this comment.
Ambiguous for the compiler?
If readOnlyProperty is an array, the to generic method will translate to func thenReturn(_ output: [T], _ outputs: [T]...) -> Self and func thenReturn(_ output: [[T]]) -> Self.
So, if you give it a "simple" array (one dimension), it will known that it is the first method. I you give it an array of arrays (two dimensions), it will know that it is the second one.
Would you prefer to add a name to the argument for the new method, to be clearer for users?
There was a problem hiding this comment.
Yeah, I'd add something like inOrder: to the new method to disambiguate passing array of individually returned values from passing array as a singular one. I can imagine a scenario where some complex tests only tell the developer the classic "The compiler is unable to type-check this expression in reasonable time." because they might not know about the second method which returns the values one by one.
There was a problem hiding this comment.
I've added the inOrder: parameter name.
|
Oh, I forgot to merge this. Merging. 🙂 |
As spreading an array doesn't work in Swift, I've added an extension to be able to pass an array of returned values to a stub.