Created
June 25, 2014 08:45
-
-
Save polarblau/ef9b36aa77f7dc8f1f3d to your computer and use it in GitHub Desktop.
Rspec matcher to check if input is 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
RSpec::Matchers.define :be_json do | |
match do |actual| | |
begin | |
!!JSON.parse(actual) | |
rescue | |
false | |
end | |
end | |
failure_message_for_should do |actual| | |
"expected input to be JSON" | |
end | |
failure_message_for_should_not do |actual| | |
"expected input not to be JSON" | |
end | |
description do | |
"checks if input is JSON" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment