问题是:我有一个方法
def comparison_reporter(list_of_scenarios_results1, list_of_scenarios_results2)
actual_failed_tests = list_of_scenarios_results2.select {|k,v| v == 'Failed'}
actual_passed_tests = list_of_scenarios_results2.select {|k,v| v == 'Passed'}
failed_tests = Array.new(actual_failed_tests.length) { Hash.new }
failed_tests.each do |hash|
actual_failed_tests.keys.map {|name| hash["test_name"] = name}
actual_failed_tests.values.map {|new_status| hash["actual_status"] = new_status}
list_of_scenarios_results1.values_at(*actual_failed_tests.keys).map {|old_status| hash["previous_status"] = old_status}
end
final_result = {
"passed_tests_count" => list_of_scenarios_results2.select {|k,v| v == 'Passed'}.length,
"failed_tests_count" => list_of_scenarios_results2.select {|k,v| v == 'Failed'}.length,
"failed_tests" => failed_tests
}
return final_result
end
此方法将 2 个哈希值作为参数,并返回它们的比较结果和其他一些东西。目前,它总是返回failed_tests
两个(或更多)相同的哈希值(相同的键值对)。我认为,这个问题是在某个地方failed_tests.each do |hash|
,但我找不到这个错误的原因,请指教。方法结果示例(.json 格式)
{
"passed_tests_count": 3,
"failed_tests_count": 2,
"failed_tests": [
{
"test_name": "As a user I want to use Recent searches tab",
"actual_status": "Failed",
"previous_status": "Failed"
},
{
"test_name": "As a user I want to use Recent searches tab",
"actual_status": "Failed",
"previous_status": "Failed"
}
]
}
UPD:hash1(第一个参数)-
{""=>"Passed",
"As a new user I want to use no fee rentals tab"=>"Passed",
"As a new user I want to use Luxury rentals tab"=>"Passed",
"As a user I want to use Recent searches tab"=>"Failed",
"As a user I want to use new listings for you tab"=>"Passed"}
hash2(第二个参数)-
{""=>"Passed",
"As a new user I want to use no fee rentals tab"=>"Failed",
"As a new user I want to use Luxury rentals tab"=>"Passed",
"As a user I want to use Recent searches tab"=>"Failed",
"As a user I want to use new listings for you tab"=>"Passed"}
所需输出的示例:
{
"passed":"count",
"failed":"count",
"failed_tests": [
{"test_name":"As a user I want to use Recent searches tab",
"actual_status":"failed",
"previous_status":"failed"},
{"test_name":"As a new user I want to use no fee rentals tab",
"actual_status":"failed",
"previous_status":"passed"}]
}