RR mock.instance_of 和 Mocha any_instance 之间的区别
我有以下 rspec 代码:
require 'spec_helper'
require 'mocha'
require 'rr'
describe ProjectsController, "creating a new project" do
integrate_views
it "should redirect to project with a notice on successful save" do
Project.any_instance.stubs(:valid?).returns(true)
#mock.instance_of(Project).valid? {true}
Project.any_instance.stubs(:create_default_packets)
#mock.instance_of(Project).create_default_packets
post 'create'
assigns[:project].should_not be_new_record
end
end
它按所写成功通过(RR 语法被注释掉),但是当我切换到 RR 语法时,它失败并显示:
“创建新项目的 ProjectsController 应重定向到项目,并显示成功保存的通知”预期 new_record 失败?返回 false,得到 true
两者有什么区别,RR会失败?
I have the following rspec code:
require 'spec_helper'
require 'mocha'
require 'rr'
describe ProjectsController, "creating a new project" do
integrate_views
it "should redirect to project with a notice on successful save" do
Project.any_instance.stubs(:valid?).returns(true)
#mock.instance_of(Project).valid? {true}
Project.any_instance.stubs(:create_default_packets)
#mock.instance_of(Project).create_default_packets
post 'create'
assigns[:project].should_not be_new_record
end
end
It passes successfully as written (RR syntax commented out) but when I switch to the RR syntax it fails with:
'ProjectsController creating a new project should redirect to project with a notice on successful save' FAILED expected new_record? to return false, got true
What is the difference between the two that RR would fail?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来区别在于你不能用 rr 调用 instance_of 两次。
编辑:情况可能不再如此,请参阅 https://github.com/rr/rr #类实例
It appears the difference is that you can't call instance_of twice with rr.
EDIT: this may no longer be the case, see https://github.com/rr/rr#class-instances