Skip to content

Instantly share code, notes, and snippets.

@willnet
Created March 15, 2012 07:51
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 willnet/2042787 to your computer and use it in GitHub Desktop.
Save willnet/2042787 to your computer and use it in GitHub Desktop.
RSpec custom matcher's
RSpec::Matchers.define :have_json do |hash|
match do |response|
hash.all? do |k,v|
JSON.parse(response.body)[k] == v
end
end
failure_message_for_should do |response|
body = JSON.parse(response.body)
"expected that #{body} would have #{hash}"
end
end
RSpec::Matchers.define :have_json_key do |key|
match do |response|
JSON.parse(response.body)[key].present?
end
end
RSpec::Matchers.define :eq_with_time do |other|
match do |time|
time.to_a == other.to_a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment