ruby-on-rails - 不支持 not_to change.by()

标签 ruby-on-rails rspec rspec3

我将 rspec 版本从 2 升级到 3。这是我面临的问题之一:

Failures:

  1) Slide after .destroy(force: false) visible if .with_deleted
     Failure/Error: expect{@slide.destroy(force: false)}.to_not change(Slide.with_deleted, :count).by(1)
     NotImplementedError:
       `expect { }.not_to change { }.by()` is not supported
     # ./spec/models/slide_spec.rb:36:in `block (3 levels) in <top (required)>'

并在 rspec's changelog我可以读到它从未被支持 (oink ?!@#)。同时还有some examples how to use change syntax但没有 not关键词。

所以问题是如何期望没有变化?

最佳答案

幸运的是,我不希望有任何变化(任何),所以我可以省略 by()部分。它工作得很好!

  expect{@slide.destroy(force: false)}.to_not change(Slide.with_deleted, :count)

关于ruby-on-rails - 不支持 not_to change.by(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25267875/

相关文章:

ruby-on-rails - RSpec 未定义方法 "errors_on"

javascript - 使用 Carrierwave 附加 Canvas 图像以形成并上传

ruby-on-rails - RSpec请求测试合并了POST JSON参数中数组中的哈希

ruby-on-rails - 如何 stub i18n_scope 以在 Rails 4 rspec 3.3.0 上模拟 ActiveRecord::RecordInvalid?

ruby-on-rails - 访问我的 API 规范中的 session

ruby-on-rails - 禁用 guard 规范运行的代码覆盖率

ruby-on-rails - RSpec 3.5 将参数传递给 shared_context

ruby-on-rails - 如何使用 ruby​​ aws s3 一次删除多个对象

ruby-on-rails - 在 Rails 中重构 View 逻辑

ruby-on-rails - 使用回形针下载文件