Created
March 15, 2012 07:51
-
-
Save willnet/2042787 to your computer and use it in GitHub Desktop.
RSpec custom matcher's
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 :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