我有一个看起来像这样的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_array
和res[0][1]
上做expected[0][1]
吗?
这似乎有效,但我不确定它是否是惯用语:
由于dict实际上有2个字段,我用过:
expect(res[:all_reports]).to match_array(expected[:all_reports])
expect(res[:this_report]).to match_array(expected[:this_report])