0
votes

I'm trying to mock the CLBeacon object inorder to test the app behavior for a particular type of beacon. But I'm facing trouble to stub the method proximity to return a required proximity value from it.

Below is the code which has the issue:

id clBeacon = [OCMockObject niceMockForClass:[CLBeacon class]];

[[[clBeacon stub] andReturn:@"2"] major];
[[[clBeacon stub] andReturn:@"0"] minor];

[[[clBeacon stub] andReturnValue: OCMOCK_VALUE(CLProximityNear)] proximity]; // Didn't work

[[[clBeacon stub] andReturn: @""] proximity]; // Didn't work

The above code raising the below issue when I'm trying to stub the proximity response.

Multiple methods named 'proximity' found with mismatched result, parameter or attributes

Can someone point me the exact issue with the above code??

Regards.

3

3 Answers

0
votes

the proximity property is not a string but rather a CLProximity typedef.

typedef NS_ENUM(NSInteger, CLProximity) {
    CLProximityUnknown,
    CLProximityImmediate,
    CLProximityNear,
    CLProximityFar
} NS_ENUM_AVAILABLE_IOS(7_0);

Try something like this:

[[[clBeacon stub] andReturn: @(CLProximityImmediate)] proximity]; // Didn't work

You should also pass in NSNumber objects for the major and minor values instead of strings as well


Edit:

Have you also tried doing something like this:

id clBeacon = [OCMockObject partialMockForObject:[CLBeacon new]];
0
votes

I've figured where the actual issue is.

So, I've two other classes which has proximity property but with different type (One is CLProximity and the other is NSString), so it is having conflict in choosing the right one.

0
votes

You could declare using CLBeacon instead of id.

CLBeacon *clBeacon = [OCMockObject niceMockForClass:[CLBeacon class]];