rspec match_array递归?

问题描述 投票:0回答:1

我有一个看起来像这样的rspec:

expect(res).to match_array(expected)

它输出失败了:

the missing elements were:   [[:all_reports, [{:match=>"Tech", :title=>"Middle Tech Middle", :url=>"/report_sections/4267"}, {:match=>"Tech", :title=>"High Tech High", :url=>"/report_sections/4265"}]]]
the extra elements were:        [[:all_reports, [{:match=>"Tech", :title=>"High Tech High", :url=>"/report_sections/4265"}, {:match=>"Tech", :title=>"Middle Tech Middle", :url=>"/report_sections/4267"}]]]

我的猜测是,问题是需要重新排序的东西是2层深,而这不是match_array的作用......

我只是在match_arrayres[0][1]上做expected[0][1]吗?

ruby-on-rails rspec
1个回答
0
投票

这似乎有效,但我不确定它是否是惯用语:

由于dict实际上有2个字段,我用过:

  expect(res[:all_reports]).to match_array(expected[:all_reports])
  expect(res[:this_report]).to match_array(expected[:this_report])
© www.soinside.com 2019 - 2024. All rights reserved.