rspec 包含相等数组的匹配器失败
rspec include matcher fails with equal arrays
我正在测试 SystemCommission
的 active
范围,我有以下测试:
expected = [active, no_starting, no_ending]
expect(SystemCommission.active.map(&:id)).to include expected.map(&:id)
它失败了:
Failure/Error: expect(SystemCommission.active.map(&:id)).to include expected.map(&:id)
expected [1, 2, 3] to include [1, 2, 3]
我不得不使用 id
s 因为它与对象不匹配。
有线索吗?
我认为include
参数不是一个数组,而是一个项目列表,
所以将测试更改为:
expect(SystemCommission.active.map(&:id)).to include *expected.map(&:id)
成功了
数组[1, 2, 3]
不包含[1, 2, 3]
要通过它看起来像:[1, 2, 3, [1, 2, 3]]
展开你的数组:
expect(SystemCommission.active.map(&:id)).to include *expected.map(&:id)
我正在测试 SystemCommission
的 active
范围,我有以下测试:
expected = [active, no_starting, no_ending]
expect(SystemCommission.active.map(&:id)).to include expected.map(&:id)
它失败了:
Failure/Error: expect(SystemCommission.active.map(&:id)).to include expected.map(&:id)
expected [1, 2, 3] to include [1, 2, 3]
我不得不使用 id
s 因为它与对象不匹配。
有线索吗?
我认为include
参数不是一个数组,而是一个项目列表,
所以将测试更改为:
expect(SystemCommission.active.map(&:id)).to include *expected.map(&:id)
成功了
数组[1, 2, 3]
不包含[1, 2, 3]
要通过它看起来像:[1, 2, 3, [1, 2, 3]]
展开你的数组:
expect(SystemCommission.active.map(&:id)).to include *expected.map(&:id)