RR mock.instance_of 和 Mocha any_instance 之间的区别

发布于 2024-08-16 17:07:33 字数 720 浏览 6 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烧了回忆取暖 2024-08-23 17:07:33

看来区别在于你不能用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文