Marc Love

Programmer, Entrepreneur, Citizen, Equality Activist

Posts tagged ruby

May 1 '12

RSpec Matcher for JSON

I’m currently building a Rails app that will only act as an API client to a fat javascript client and wanted a way to test my responses in RSpec. So I decided to write a custom RSpec matcher:

It takes advantage of the Rails JSON parsing and its hash extensions Hash#with_indifferent_access and Hash#diff to turn both values to a Ruby hash and then check to see if there’s any differences between the two.

1 note Tags: rspec ruby rails json