How can I assert my Ajax request and test the JSON output from Ruby on Rails functional tests?
None of the answers provides a nice maintainable way to verify a JSON response. I find this one to be the best:
https://github.com/ruby-json-schema/json-schema
It provides a nice implementation for the standard json schema
You can write a schema like:
schema = {
"type"=>"object",
"required" => ["a"],
"properties" => {
"a" => {
"type" => "integer",
"default" => 42
},
"b" => {
"type" => "object",
"properties" => {
"x" => {
"type" => "integer"
}
}
}
}
}
and use it like: JSON::Validator.validate(schema, { "a" => 5 })
Best way to verify it against my android client implementation.