Skip to content

Instantly share code, notes, and snippets.

@polarblau
Created June 25, 2014 08:45
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 polarblau/ef9b36aa77f7dc8f1f3d to your computer and use it in GitHub Desktop.
Save polarblau/ef9b36aa77f7dc8f1f3d to your computer and use it in GitHub Desktop.
Rspec matcher to check if input is JSON.
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