仍在整体学习 Rspec,所以感谢您的耐心等待。
返回值是这样的:
{ supermodel: {
'id': 1,
'name': 'J',
'model_attributes': [
{attr1: 'T', attrA: 1},
{attr2: 'F', attrB: 2},
{attr3: 'T', attrC: 3}
],
}
}
尝试获得一个期望,即名为“model_attributes”的哈希键包含一个数组的值,该数组包含以下键值对 - {attr2:F, attrB: 2}
和 {attr3: T, attrC: 3}
.
欢迎任何见解。
最佳答案
describe 'Stuff' do
let(:model_attributes) do
[
{attr1: 'T', attrA: 1},
{attr2: 'F', attrB: 2},
{attr3: 'T', attrC: 3}
]
end
let(:result) do
{ supermodel:
{
'id': 1,
'name': 'J',
'model_attributes': model_attributes
}
}
end
it 'has the correct model_attributes value' do
expect(result.dig(:supermodel, :model_attributes)).to eq(model_attributes)
end
end
关于ruby-on-rails - RSpec 期望哈希包含键值对数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42657275/