我正在尝试使用ReactiveCocoa和Kiwi进行测试,使用CocoaPods进行依赖关系管理。
我为典型的登录屏幕设置了第一个测试,在用户输入用户名和密码之前,登录按钮才会启用。 只是一些示例代码的简单版本:
- (void)viewDidLoad { [super viewDidLoad]; RAC(self.loginButton, enabled) = [RACSignal combineLatest:@[self.userNameField.rac_textSignal, self.passwordField.rac_textSignal] reduce:^(NSString *username, NSString *password) { return @(username.length > 0 && password.length > 0); }]; }问题是,当我运行我的测试时,我收到以下错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Value from stream <RACDynamicSignal: 0xe3735a0> name: +combineLatest: ( "<RACDynamicSignal: 0xe368c50> name: <UITextField: 0xe3707a0> -rac_textSignal", "<RACDynamicSignal: 0xe372d80> name: <UITextField: 0xe36aef0> -rac_textSignal" ) is not a tuple: <RACTuple: 0xe377a40> ( "", "" )'当然,这是一个RACTuple ,所以这只是令人困惑。
我的研究在ReactiveCocoa上发现了以下问题:
https://github.com/ReactiveCocoa/ReactiveCocoa/issues/901
诊断是ReactiveCocoa以某种方式连接两次。 那个问题的人通过抛弃CocoaPods解决了这个问题。 这似乎不对。 有没有人得到这个工作?
为了完整起见,我的Podfile是:
platform :ios, '6.0' pod 'ReactiveCocoa' target :test do link_with 'PollVaultTests' pod 'Kiwi/XCTest' endI'm trying to get a new project set up using ReactiveCocoa and Kiwi for testing, using CocoaPods for dependency management.
I have a first test set up for a typical login screen, where the login button isn't enabled until the user has input something for the username and password. Just a simpler version of some of the example code:
- (void)viewDidLoad { [super viewDidLoad]; RAC(self.loginButton, enabled) = [RACSignal combineLatest:@[self.userNameField.rac_textSignal, self.passwordField.rac_textSignal] reduce:^(NSString *username, NSString *password) { return @(username.length > 0 && password.length > 0); }]; }The problem is that when I run my tests, I get the following error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Value from stream <RACDynamicSignal: 0xe3735a0> name: +combineLatest: ( "<RACDynamicSignal: 0xe368c50> name: <UITextField: 0xe3707a0> -rac_textSignal", "<RACDynamicSignal: 0xe372d80> name: <UITextField: 0xe36aef0> -rac_textSignal" ) is not a tuple: <RACTuple: 0xe377a40> ( "", "" )'Of course, it is a RACTuple, so that's just confusing.
My research turned up the following issue on ReactiveCocoa:
https://github.com/ReactiveCocoa/ReactiveCocoa/issues/901
The diagnosis there is that ReactiveCocoa is getting linked in twice somehow. The person who had the issue there solved it by ditching CocoaPods. That doesn't seem right. Has anyone gotten this working?
For completeness, my Podfile is:
platform :ios, '6.0' pod 'ReactiveCocoa' target :test do link_with 'PollVaultTests' pod 'Kiwi/XCTest' end最满意答案
好吧,我回答我自己的问题。
事实证明,当Podfile在Podfile中的“全局”级别列出时,CocoaPods将它们包含在所有目标中。
在这种情况下的结果是我的主项目链接在CocoaPods - 我的测试目标也是如此。
当我的测试目标被注入我的主项目以运行测试时 - 您将ReactiveCocoa链接两次。 因此有两个名为RACTuple类浮动 - 因此当ReactiveCocoa代码在内部检查以确保其参数是RACTuple ,它会检查类的错误副本并且实际上具有错误的否定结果。
解决方案是确保将Podfile测试目标配置为仅链接到测试窗格,如下所示:
platform :ios, '6.0' pod 'ReactiveCocoa' target :test, :exclusive => true do link_with 'PollVaultTests' pod 'Kiwi/XCTest' end那:exclusive => true part告诉Cocoapods只在我的测试目标中包含Kiwi测试框架。 问题解决了!
Well, I get to answer my own question.
It turns out that when pods are listed at the "global" level in your Podfile, CocoaPods includes them in all targets.
The result in this case is that my main project links in CocoaPods - and so does my test target.
When my test target gets injected into my main project to run the tests - you get ReactiveCocoa linked in twice. So there are two classes named RACTuple floating around - and so when the ReactiveCocoa code internally checks to make sure its argument is a RACTuple, it checks against the wrong copy of the class and effectively has a false negative result.
The solution is to make sure that my test target in the Podfile is configured to link in only the test pods like so:
platform :ios, '6.0' pod 'ReactiveCocoa' target :test, :exclusive => true do link_with 'PollVaultTests' pod 'Kiwi/XCTest' endThat :exclusive => true part is what tells Cocoapods to only include the Kiwi test framework in my test target. Problem solved!
更多推荐
发布评论