【发布时间】:2014-10-28 15:36:58
【问题描述】:
我想使用 rspec 提供的参数匹配器来匹配散列数组。理想情况下,这是我想要的代码:
context 'logging stock levels' do
subject { double(:stock_logger, stock_updated: nil) }
let(:stock_importer) { described_class.new(logger: subject) }
before(:each) { stock_importer.import }
it { is_expected.to have_received(:stock_updated)
.with(array_including(hash_including('sku', 'count_on_hand'))) }
end
这对我来说是一个参数不匹配的错误。我能想到的唯一可行的解决方案如下:
context 'logging stock levels' do
subject { double(:stock_logger, stock_updated: nil) }
let(:stock_importer) { described_class.new(logger: subject) }
before(:each) { stock_importer.import }
it do
is_expected.to have_received(:stock_updated) do |stock_levels|
expect(stock_levels).to include(include('sku', 'count_on_hand'))
end
end
end
我是不是做错了什么?
【问题讨论】: