Skip to content

Instantly share code, notes, and snippets.

@nicksieger
Created May 9, 2012 19:49
Show Gist options
  • Save nicksieger/2648327 to your computer and use it in GitHub Desktop.
Save nicksieger/2648327 to your computer and use it in GitHub Desktop.
RSpec::Matchers.define :have_jsonish_contents do |expected|
def matches_at_this_level?(exp, act)
if exp.respond_to?(:to_a) && act.respond_to?(:to_a)
exp_arr = exp.to_a
act_arr = act.to_a
return false if exp_arr.length != act_arr.length
exp_arr.each_with_index do |elem,i|
return false unless matches_at_this_level?(elem, act_arr[i])
end
return true
else
return exp == act
end
end
match do |actual|
matches_at_this_level?(expected, actual)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment