rspec包括matcher以相同的数组失败

时间:2015-07-01 13:20:33

标签: ruby-on-rails arrays rspec matcher

我正在测试active的{​​{1}}范围,我有以下测试:

SystemCommission

它失败了:

  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] ,因为它与对象不匹配。

任何线索?

2 个答案:

答案 0 :(得分:1)

数组[1, 2, 3]不包含[1, 2, 3]

要进行该传递,它将类似于:[1, 2, 3, [1, 2, 3]]

splat你的阵列:

expect(SystemCommission.active.map(&:id)).to include *expected.map(&:id)

答案 1 :(得分:0)

我认为include参数不是数组,而是项目列表

将测试更改为:

  expect(SystemCommission.active.map(&:id)).to include *expected.map(&:id)

做了这个伎俩

相关问题