Created
June 28, 2013 15:51
-
-
Save chebyte/5885717 to your computer and use it in GitHub Desktop.
custom rspec matcher for json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#spec/supports/custom_matchers.rb | |
RSpec::Matchers.define :be_json do |expected| | |
match do |actual| | |
actual = ActiveSupport::JSON.decode(actual).with_indifferent_access | |
expected = ActiveSupport::JSON.decode(expected) unless expected.is_a?(Hash) | |
expected = expected.with_indifferent_access | |
actual.diff(expected) == {} | |
end | |
end | |
#spec | |
expect(response.body).to be_json({"error"=>"Unauthorized"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment