How to compare structure parameters with OCMock?

So, I have a method that has the following signature in the class PopoverProvider

- (void)showPopoverForAction:(MESAction *)action fromRect:(CGRect)rect inView:(UIView *)view onDoneBlock:(MESActionPopoverDoneBlock)block;

And I want to check that it is called like this:

// popoverProvider is a PopoverProvider
                            [[[popoverProvider expect] andReturn:mockRecipeIngredientViewController]
                                    showPopoverForAction:[OCMArg any]
                                                fromRect:[OCMArg any] // !!!!
                                                  inView:[OCMArg any]
                                             onDoneBlock:[OCMArg any]
                            ];

A marked line causes a problem: [OCMArg any]does not match CGRects, which is a type of structure.

+4
source share
1 answer

In this case, since you do not care about the value of rect, I would use:

[[[[popoverProvider expect] andReturn:mockRecipeIngredientViewController] ignoringNonObjectArgs]
                 showPopoverForAction:[OCMArg any]
                             fromRect:CGRectMake(0.0f,0.0f,0.0f,0.0f)
                               inView:[OCMArg any]
                          onDoneBlock:[OCMArg any]
];

If you had a case when you wanted to ignore one structure, but check another, you can do this:

[[[[[popoverProvider expect] andReturn:mockRecipeIngredientViewController] ignoringNonObjectArgs]  andDo:^(NSInvocation *invocation) {
        CGRect theSize;
        [invocation getArgument:&theSize atIndex:6];
        STAssertEquals(theSize, CGSizeMake(20.0f,20.0f), @"No match!");
    }]
                 showPopoverForAction:[OCMArg any]
                             fromRect:CGRectMake(0.0f,0.0f,0.0f,0.0f)
                               inView:[OCMArg any]
                          onDoneBlock:[OCMArg any]
                             someSize:CGSizeMake(0.0f,0.0f)
];
+4
source

Source: https://habr.com/ru/post/1535519/


All Articles