Skip to content

Commit

Permalink
Partial mock doNothing works!
Browse files Browse the repository at this point in the history
  • Loading branch information
jonreid committed Feb 22, 2013
1 parent c2a657a commit 65e9670
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
15 changes: 9 additions & 6 deletions Source/OCMockito/MKTInvocationContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@implementation MKTInvocationContainer
{
MKTStubbedInvocationMatcher *_invocationMatcherForStubbing;
MKTStubbedInvocationMatcher *_invocationForStubbing;
NSMutableArray *_stubbed;
NSMutableArray *_answersForStubbing;
}
Expand All @@ -39,20 +39,20 @@ - (void)setInvocationForPotentialStubbing:(NSInvocation *)invocation

MKTStubbedInvocationMatcher *s = [[MKTStubbedInvocationMatcher alloc] init];
[s setExpectedInvocation:invocation];
_invocationMatcherForStubbing = s;
_invocationForStubbing = s;
}

- (void)setMatcher:(id <HCMatcher>)matcher atIndex:(NSUInteger)argumentIndex
{
[_invocationMatcherForStubbing setMatcher:matcher atIndex:argumentIndex];
[_invocationForStubbing setMatcher:matcher atIndex:argumentIndex];
}

- (void)addAnswer:(id)answer
{
[_registeredInvocations removeLastObject];

[_invocationMatcherForStubbing setAnswer:answer];
[_stubbed insertObject:_invocationMatcherForStubbing atIndex:0];
[_invocationForStubbing setAnswer:answer];
[_stubbed insertObject:_invocationForStubbing atIndex:0];
}

- (MKTStubbedInvocationMatcher *)findAnswerFor:(NSInvocation *)invocation
Expand All @@ -75,7 +75,10 @@ - (BOOL)hasAnswersForStubbing

- (void)setMethodForStubbing:(MKTInvocationMatcher *)invocationMatcher
{
// _invocationMatcherForStubbing = invocationMatcher;
_invocationForStubbing = [[MKTStubbedInvocationMatcher alloc] initCopyingInvocationMatcher:invocationMatcher];
for (id answer in _answersForStubbing)
[self addAnswer:answer];
[_answersForStubbing removeAllObjects];
}

@end
6 changes: 6 additions & 0 deletions Source/OCMockito/MKTInvocationMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@


@interface MKTInvocationMatcher : NSObject
{
NSInvocation *_expected;
NSUInteger _numberOfArguments;
NSMutableArray *_argumentMatchers;
}

- (id)init;
- (void)setMatcher:(id <HCMatcher>)matcher atIndex:(NSUInteger)argumentIndex;
- (NSUInteger)argumentMatchersCount;

Expand Down
6 changes: 1 addition & 5 deletions Source/OCMockito/MKTInvocationMatcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import "MKTTypeEncoding.h"


#define HC_SHORTHAND
#if TARGET_OS_MAC
#import <OCHamcrest/OCHamcrest.h>
Expand All @@ -25,11 +26,6 @@ @interface MKTInvocationMatcher ()


@implementation MKTInvocationMatcher
{
NSInvocation *_expected;
NSUInteger _numberOfArguments;
NSMutableArray *_argumentMatchers;
}

- (id)init
{
Expand Down
2 changes: 2 additions & 0 deletions Source/OCMockito/MKTStubbedInvocationMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@

@property (nonatomic, strong) id answer;

- (id)initCopyingInvocationMatcher:(MKTInvocationMatcher *)other;

@end
14 changes: 14 additions & 0 deletions Source/OCMockito/MKTStubbedInvocationMatcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@
// Source: https://github.com/jonreid/OCMockito
//

#import "MKTInvocationMatcher.h"
#import "MKTStubbedInvocationMatcher.h"


@implementation MKTStubbedInvocationMatcher

- (id)initCopyingInvocationMatcher:(MKTInvocationMatcher *)other
{
self = [super init];
if (self)
{
_expected = other->_expected;
_numberOfArguments = other->_numberOfArguments;
_argumentMatchers = [other->_argumentMatchers mutableCopy];
}
return self;
}

@end

0 comments on commit 65e9670

Please sign in to comment.