一起使用ReactiveCocoa,Kiwi和Cocoapods,获得“不是一个元组”的例外(Using ReactiveCocoa, Kiwi, and Cocoapods together, ge

编程入门 行业动态 更新时间:2024-10-28 07:32:08
一起使用ReactiveCocoa,Kiwi和Cocoapods,获得“不是一个元组”的例外(Using ReactiveCocoa, Kiwi, and Cocoapods together, getting “is not a tuple” exception)

我正在尝试使用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' end

I'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' end

That :exclusive => true part is what tells Cocoapods to only include the Kiwi test framework in my test target. Problem solved!

更多推荐

本文发布于:2023-08-03 05:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1384147.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Kiwi   ReactiveCocoa   Cocoapods   exception   tuple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!