我真的是Rspec的新手,并试图找到我的答案,但它一直指导我使用stub_chain,但它似乎在Rspec3上被弃用了。我有以下几个我正在尝试的存根:
active_automation = Client.automation_active_status.new_client其中Client是我的模型,automation_active_status是我的客户端模型中的以下内容
scope :automation_active_status, -> { where(automation_status: true) }new_client是我想要调用以进一步过滤结果的属性
我试图实现stub_chain,但没有成功。我的目标是让以下内容发挥作用:
Client.any_instance( black_box_I_can_not_figure_out ).returns[something]谢谢。
发布于 2014-12-17 23:08:06
我相信你可能在找allow和receive_message_chain。
allow(Client).to receive_message_chain(:automation_active_status, :new_client) { [thing_to_return] }这将对允许它的方法进行存根,并返回您传递给它的块产生的任何结果。希望能有所帮助。
发布于 2014-12-12 17:10:46
Client.stub_chain(:automation_active_status, :new_client).and_return([thing-to-return])应该会带你去你想去的地方。
此外,应该在类的实例上使用any_instance。例如,Client.first是一个实例,而Client是类(您可以直接在它上面存根)。
https://stackoverflow.com/questions/27438280
复制相似问题