Skip to content

Instantly share code, notes, and snippets.

@jbnv
Created March 1, 2016 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbnv/0f8ac9531fff4671334c to your computer and use it in GitHub Desktop.
Save jbnv/0f8ac9531fff4671334c to your computer and use it in GitHub Desktop.
A function that goes in Ruby unit tests to check an array of hashes by property. Supply a list of symbols to check.
def compare_arrays_of_hashes(expected_array,actual_array,symbols)
expected_array.each_with_index do |expected,index|
actual = actual_array[index]
symbols.each do |symbol|
assert_equal expected[symbol],actual[symbol],"#{symbol} of element #{index} doesn't match"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment