我有两个用 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_defaultContext
NSAssert 说它失败了Default Context is nil! Did you forget to initialize the Core Data Stack?
。