Ruby: comparing two Arrays of Hashes and mapping one to the other
def mapped_tasks(expected, subtasks, fields)
  fields_match = -&gt;(t1, t2) {fields.all? {|f| t1[f] == t2[f]}}
  expected.map do |e| 
    subtask = subtasks.find {|s| fields_match.(e,s)}
    subtask ? e.merge(subtask) : nil
  end.compact
end


should do the same as your original.


use merge rather than explicitly adding each field you want
create a lambda to name the condition of "all relevant fields matching".  this makes the loop within which it is called more readable.
rather than procedurally declaring an array and adding items to it, simply use map to chang all the expected items.  the ones that don't match are changed to nil, and we remove them at the end using compact


notes on the original code:


the data structures that we're assuming exist seem ill-fitted to the problem.  if they're within your control, consider simplifying them.  this should make the solution to the problem here more natural
avoid extraneous information in your variable names.  it gives the illusion of greater clarity but in fact makes the code harder to read at a glance.  eg fields is a clearer name than fields_to_check