Kiwi + MagicalRecord method does not exist

I am using Kiwi framework to test the interaction between my code and Core Data through Magical Record library. Magical record defines a category on NSManagedObject, which adds few nice methods, such as MR_createInContext:(NSManagedObjectContext *)context. I am trying to test wether or not, that method is called, and how many times.

it(@"should create new object for me object with new id", ^{
    [[[NSManagedObjectContext MR_contextForCurrentThread] should] receive:@selector(MR_createInContext:)];
    Me *me = [Me meWithID:@"12345" inContext:[NSManagedObjectContext MR_contextForCurrentThread]];
    [me shouldNotBeNil];
    [[me.idNumber should] equal:@"12345"];
});

The issue is that Kiwi does not seem to see that category despite

#import <CoreData+MagicalRecord.h>

in the test .m file.

ME_ShouldCreateNewObjectForMeObjectWithNewId (EHMeSpecs) failed: 'ME, should create new object for me object with new id' [FAILED], cannot stub -MR_createInContext´╝Ü because no such method exist

How can I make Kiwi aware of the category?

Answers


Looking at the name of your test, I am guessing your intent to to verify that Core Data works, creates a new Managed Object for you and has a proper ObjectID. I don't see the need to know that Kiwi should now how to intercept the category and such. I would simply write your test like so:

it(@"should create a new object", ^{

    NSManagedObjectContext *testContext = [NSManagedObjectContext MR_context];
    id myObject = [MyEntity createWithStuff:@{...} inContext:testContext];

    assertThat(myObject, isNot(nil));
    assertThat([myObject someAttrbiute], is(equalTo(@"some value")));
});

Don't worry about testing if the category works because with this test, it's implicitly testing that anyway. If this test breaks, you'll know pretty quickly that the category isn't working.

One of my rules of testing is "Don't test the language or framework". When you're testing to see if a category works, you're violating this rule and testing something that someone else most likely has tested.


Obviously this method is defined on an NSManagedObject not NSManagedObjectContext, it should say [[Me class] should] receive... My bad.


Need Your Help

What was the design decision to merge IplImage and cv::Mat?

c++ opencv

In OpenCV 2.0, they switched from having separate image and matrix classes to a unified class called cv::Mat. What was the design decision there? To me, who works with both images and matrices on a...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.