我正在使用 rspec3,我正在尝试处理新的双重方法验证功能。我想为这样的分页数组创建一个双精度:
my_array = object_double([])
allow(my_array).to receive(:current_page).and_return(1)
但是,这会导致此错误:
Double[...] does not implement: current_page
这是因为 rspec 在给定 object_double 时会创建一个验证双精度。我真的不想尝试创建一个响应诸如:[]
. 全局设置mocks.verify_partial_doubles = false
也无济于事(而且对于这个问题似乎也有点过分了),大概是因为 object_double 旨在进行验证。
我知道我可以在将数组翻倍之前对数组进行分页,但我觉得我不应该这样做。有什么我想念的吗?我应该要求 rspec 提供基于每个方法禁用验证的能力,还是提供创建非验证对象双精度的能力,还是应该以其他方式编写此测试?
在此期间,我可以写这样的东西:
products = Class.new(SimpleDelegator) do
def current_page
1
end
def per_page
1
end
def total_entries
1
end
end.new([])
...但它看起来不再像一个简单的 rspec 模拟了。