【发布时间】:2016-09-26 12:33:02
【问题描述】:
我刚刚升级到 Rails 5。在我的规格中,我有以下内容
expect(model).to receive(:update).with(foo: 'bar')
但是,由于 params 不再扩展 Hash 而现在是 ActionController::Parameters,因此规范失败了,因为 with() 期待一个哈希值,但它实际上是 ActionController::Parameters
有没有更好的方法在 Rspec 中做同样的事情,比如不同的方法with_hash?
我可以使用
解决这个问题expect(model).to receive(:update).with(hash_including(foo: 'bar'))
但这只是检查参数是否包含该哈希,而不是检查完全匹配。
【问题讨论】:
标签: ruby-on-rails ruby rspec ruby-on-rails-5