2

我有两个用 Kiwi 编写的规范,它们都调用这两种方法beforeAll

[MagicalRecord setDefaultModelFromClass:[self class]];
[MagicalRecord setupCoreDataStackWithInMemoryStore];

[MagicalRecord cleanUp];afterAll.

这些规格之一没有说Default Context is nil! Did you forget to initialize the Core Data Stack?,但另一个没有。当我注释掉第一个规范时,第二个规范仍然失败。当我注释掉第二个规范时,第一个规范仍然通过,因此顺序似乎并不重要,或者它们正在并行运行并导致问题。

谁能阐明为什么会发生这种情况?这是失败的完整规范:

#import "Kiwi.h"
#import "AuthenticationHelper.h"
#import "Admin.h"

SPEC_BEGIN(AuthenticationManagerSpec)

describe(@"The authentication helper", ^{

    beforeAll(^{
        [MagicalRecord setDefaultModelFromClass:[self class]];
        [MagicalRecord setupCoreDataStackWithInMemoryStore];
    });

    afterAll(^{
        [MagicalRecord cleanUp];
    });

    context(@"when given correct credentials", ^{
        context(@"should pass", ^{
            NSString *email = @"foo@bar.com";
            NSString *password = @"test_password_1234";

            Admin *admin = [Admin createEntity];
            admin.email = email;
            admin.password = password;

            __block BOOL loggedInSuccessfully = NO;
            [AuthenticationHelper authenticateUserWithEmail:email
                                                      password:password
                                                    completion:^(BOOL success,
                                                                 id response) {
             loggedInSuccessfully = success;
             }];

            [admin deleteEntity];

            [[expectFutureValue(theValue(loggedInSuccessfully)) shouldEventually] beTrue];

        });
    });

});

SPEC_END

+ (NSManagedObjectContext *) MR_defaultContextNSAssert 说它失败了Default Context is nil! Did you forget to initialize the Core Data Stack?

4

1 回答 1

0

愚蠢的错误!这一行:

context(@"should pass", ^{

应该是这样的:

it(@"should pass", ^{

这导致beforeAll块不运行,因此核心数据堆栈没有正确配置。

于 2013-11-18T16:53:02.107 回答