ruby-on-rails – Rspec 3中Rspec any_instance的新特性是什么?

通常在我的Rails控制器测试中,我将在{Website.any_instance.stub(:save).and_return(false)}之前进行测试,以记录记录不保存时会发生什么. Rspec 3看起来像any_instance消失了.

我尝试使用{allow(Website).to收到(:save).and_return(false)}为Rspec 3,但现在我得到这个错误

Website(id: integer,…) does not implement: save

使用Rspec 3可以替代非常有用的任务吗?

解决方法

尝试这个
allow_any_instance_of(Website).to receive(:save).and_return(false)

例如:https://github.com/rspec/rspec-mocks#settings-mocks-or-stubs-on-any-instance-of-a-class

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...