我想知道测试ActionCable频道.
假设我有以下聊天频道:
class ChatChannel < ApplicationCable::Channel
def subscribed
current_user.increment!(:num_of_chats)
stream_from "chat_#{params[:chat_id]}"
stream_from "chat_stats_#{params[:chat_id]}"
end
end
Run Code Online (Sandbox Code Playgroud)
该subscribed方法更新数据库并定义了两个要在整个频道上广播的流,但细节不是很重要,因为我的问题更为通用:
RSpec在测试类似的交互操作(如控制器操作)时提供了许多辅助方法和各种实用程序,但我可以找到有关RSpec和ActionCable的任何内容.
用于指定包含关系的文档Array#include?是使用==运算符检查的。我正在使用自定义定义将对象与其自身进行比较的情况下进行检查==:
class Foo
def ==(other)
false
end
end
f = Foo.new
f == f # => false
Run Code Online (Sandbox Code Playgroud)
在这种情况下,文档的描述就不是这种情况了,而另一种机制则优先考虑:
[f].include?(f) # => true
Run Code Online (Sandbox Code Playgroud)
该机制是什么?在哪里定义?
我是 Scala 单元测试的新手,我找不到一种方法来存根在单例对象中定义的函数。
例如:
class Profile {
def getLatest
...
Feed.getLatestEntries
...
}
object Feed {
def getLatestEntries: Future[List[FeedEntry]] { /* Access some API*/ }
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试对getLatestProfile 类中定义的函数进行单元测试。由于我不想在我的单元测试中通过 Web 实际访问外部 API,因此我试图存根Feed对象及其getLatestEntries函数以返回一些预定义的值。
我研究了 ScalaMock、EasyMock 和 Mockito 框架,但找不到一种方法来存根单例对象的方法。ScalaMock 状态
为什么所有的模拟框架都不提供这个功能?我怎样才能做到这一点?存根Feed.getLatestEntries?
谢谢