{"action":"closed","issue":{"url":"https://api.github.com/repos/jonreid/OCMockito/issues/114","labels_url":"https://api.github.com/repos/jonreid/OCMockito/issues/114/labels{/name}","comments_url":"https://api.github.com/repos/jonreid/OCMockito/issues/114/comments","events_url":"https://api.github.com/repos/jonreid/OCMockito/issues/114/events","html_url":"https://github.com/jonreid/OCMockito/issues/114","id":121596997,"number":114,"title":"Should decrement number of invocations after matching","user":{"login":"gchaurais","id":13836675,"avatar_url":"https://avatars.githubusercontent.com/u/13836675?v=3","gravatar_id":"","url":"https://api.github.com/users/gchaurais","html_url":"https://github.com/gchaurais","followers_url":"https://api.github.com/users/gchaurais/followers","following_url":"https://api.github.com/users/gchaurais/following{/other_user}","gists_url":"https://api.github.com/users/gchaurais/gists{/gist_id}","starred_url":"https://api.github.com/users/gchaurais/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gchaurais/subscriptions","organizations_url":"https://api.github.com/users/gchaurais/orgs","repos_url":"https://api.github.com/users/gchaurais/repos","events_url":"https://api.github.com/users/gchaurais/events{/privacy}","received_events_url":"https://api.github.com/users/gchaurais/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-10T22:57:33Z","updated_at":"2015-12-17T04:44:31Z","closed_at":"2015-12-17T04:44:31Z","body":"Suppose I have:\r\n\r\n[myMock myMethod];\r\n[verify(myMock) myMethod];\r\n[myMock myMethod];\r\n[verify(myMock) myMethod];\r\n\r\nThis is the most logical way to write this test. Every time the method myMethod gets called, I want to verify it's been called.\r\n\r\nUnfortunately, that code fails. The reason is because verify(mock) is the same as calling verifyCount(mock, times(1)) and after a verification is done, the invocations that have already been successfully verified aren't removed from the list of recordedInvocations. In other words, in order to make my test pass, I'd need to change the second call to either:\r\n\r\n[verifyCount(myMock, times(2)) myMethod];\r\n\r\nor:\r\n\r\n[verifyCount(myMock, atLeast(1)) myMethod];\r\n\r\nThe first option works, but it's not intuitive for people reading my test. All I want is to verify every time myMethod is called. Option two might not work because I might want to check using =, instead of >=.\r\n\r\nOne possibility to solve this problem is to change the numberOfMatchingInvocations method of the MKTVerificationData class to:\r\n\r\n- (NSUInteger)numberOfMatchingInvocations\r\n{\r\n        NSUInteger count = 0;\r\n        NSMutableArray *registeredInvocations = data.invocations.registeredInvocations;\r\n        for (int i = registeredInvocations.count - 1; i >= 0; i--) {\r\n            if ([data.wanted matches:registeredInvocations[i]]) {\r\n                ++count;\r\n                [registeredInvocations removeObjectAtIndex:i];\r\n            }\r\n        }\r\n        return count;\r\n}\r\n\r\nI'm swizzling it in my code so I can have proper behavior, but I'd love to have the correct behavior by default."}}