As you've discovered, when you set a receive
expectation, Kiwi stubs that method on the object, regardless of whether it's a regular object, a Class
object, or an actual Kiwi mock / test double (https://github.com/allending/Kiwi/wiki/Expectations#expectations-interactions-and-messages).
If what you're trying to test is that your +groupWithID:inContext:
helper behaves correctly, you don't actually want the real implementation of MR_createInContext:
. A "should receive" expectation is designed to test that you're sending the right message, but to avoid executing the real code.
Maybe something like this:
it(@"creates a new group if one does not exist with the specified id", ^{
// stub MR_findByAttribute to return no results
[Group stub:@selector(MR_findByAttribute:withValue:inContext:) andReturn:@[]];
// stub MR_createInContext to use our test group so that we can set
// expectations on it
id context = [NSManagedObject MR_defaultContext];
id group = [Group MR_createInContext:context];
[[Group should] receive:@selector(MR_createInContext:) andReturn:group withArguments:context];
// call the method we want to test
[Group groupWithID:@"1234" inContext:context];
// test that the id was set correctly
[[group.idNumber should] equal:@"1234"];
});