我有一个如下所示的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]
吗?
答案 0 :(得分:0)
这似乎可行,但我不确定是否惯用:
由于字典实际上有2个字段,因此我使用了:
expect(res[:all_reports]).to match_array(expected[:all_reports])
expect(res[:this_report]).to match_array(expected[:this_report])