Lorenz H Menke
Lorenz H Menke

Reputation: 113

OCMock version 3 will not recognized class methods

I am trying to use OCMock version 3 on class methods. These methods are not recognized. Does anyone know why and how do I solve this. When I am typing the code for the stub the maskWithObjectType method does not appear. I enter it anyway and try the test. Some code is

#import <Foundation/Foundation.h>
@interface ObjectMask : NSObject
@property (strong, nonatomic, readonly) Class objectType;
@property (strong, nonatomic, readonly) NSMutableArray* requestedFields;
@property (strong, nonatomic, readonly) NSDictionary* children;
@property (weak, nonatomic, readonly) ObjectMask* parent;
#pragma mark - Factory
+(instancetype)maskWithObjectType:(Class)objectType;

The mocking is

id mockMask = OCMClassMock([ObjectMask class]);
OCMStub([mockMask maskWithObjectType:[someotherclass class]]);
[mockMask maskWithObjectType:[someotherclass class]];
OCMVerify(mockMask);

When I run the test I get the error

failed: caught "NSInvalidArgumentException", "-[OCMockObject(PGWS3ObjectMask) maskWithObjectType:]: unrecognized selector sent to instance 0x7fe420e0ca60"

Upvotes: 1

Views: 473

Answers (1)

Kjuly
Kjuly

Reputation: 35131

What you got by OCMClassMock(cls) is an instance object, not a class, i.e.,

id mockMask = OCMClassMock([ObjectMask class]);

just returns an instance.


If you want to invoke ObjectMask's class method +maskWithObjectType:, try

id mockMaskForSomeOtherClass = [ObjectMask maskWithObjectType:[someotherclass class]];

Upvotes: 4

Related Questions