Comments (2)
I think this is a good idea!
from ocmockito.
There's one wrinkle: propagating the type through means you now need to cast to id<MKTNonObjectArgumentMatching>
or a type that conforms to that (like MKTObjectMock *
) to use the -withMatcher:
and -withMatcher:forArgument:
.
Example of errors
Without the cast, and with propagating the type, clang issues errors like:
OCMockito/Source/Tests/VerifyObjectTests.m:139:25: error: no visible @interface for 'NSMutableArray' declares the selector 'withMatcher:forArgument:'
[[verify(mockArray) withMatcher:greaterThan(@1) forArgument:0]
~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OCMockito/Source/Tests/VerifyObjectTests.m:147:25: error: no visible @interface for 'NSMutableArray' declares the selector 'withMatcher:'
[[verify(mockArray) withMatcher:greaterThan(@1)]
~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~
Example of fixing the errors
The errors are fixed by casting to the type of objects conforming to the protocol:
@@ -120,7 +136,7 @@ static inline double *createArrayOf10Doubles(void)
{
[mockArray removeObjectAtIndex:2];
- [[verify(mockArray) withMatcher:greaterThan(@1) forArgument:0]
+ [[(id<MKTNonObjectArgumentMatching>)verify(mockArray) withMatcher:greaterThan(@1) forArgument:0]
removeObjectAtIndex:0];
}
@@ -128,7 +144,7 @@ static inline double *createArrayOf10Doubles(void)
{
[mockArray removeObjectAtIndex:2];
- [[verify(mockArray) withMatcher:greaterThan(@1)]
+ [[(id<MKTNonObjectArgumentMatching>)verify(mockArray) withMatcher:greaterThan(@1)]
removeObjectAtIndex:0];
}
Proposed enhancement
This could be made more ergonomic by adding macros like verifyWithMatcher(mock, matcher)
and verifyWithMatcherForArgument(mock, matcher, index)
.
As a bonus, that would also make the "use a matcher for a primitive" behavior more discoverable through autocomplete of veriβ¦
. I've tripped over that primitive-related behavior a couple times already. It's easy to think you did it right when you didn't: anything()
successfully matched YES
in a test for me last week, but then I found this week it wasn't actually matching just anything when the method got invoked with a primitive NO
in a test this week.
from ocmockito.
Related Issues (20)
- Swift Static Declaration of 'times' follows non-static declaration HOT 1
- Expected nil, but was nil HOT 3
- Crash when calling mocks from `dealloc` that are not called from elsewhere HOT 16
- MKTArgumentCaptor to HCArgumentCaptor migration HOT 2
- Unable to @import OCMockitoIOS HOT 4
- Is there a way to assert method throws? HOT 1
- Stubbing the protocol return as Nil HOT 3
- Cannot use OCMockito because of OCHamcrest. HOT 2
- Feature request: possibility to call through HOT 1
- Argument captor capturing outer function HOT 1
- Import OCHamcrest as a module breaks backward compatibility and feels unnecessary HOT 1
- Mock internal calls of a another class methods HOT 4
- Feature Request: Apple Silicon binary release HOT 9
- Catalyst Support for OCMockito.xcframework HOT 8
- verify doesn't fail when parameter is mocked HOT 11
- Stubs return nil when verifying HOT 3
- Could not build OCMockito using Carthage HOT 3
- Building with Carthage fails HOT 1
- Use OCHamcrest 9.0.1 via all dependency managers
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 ocmockito.