Giter Site home page Giter Site logo

Comments (2)

jonreid avatar jonreid commented on June 15, 2024

I think this is a good idea!

from ocmockito.

jeremy-w avatar jeremy-w commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.