Verifying JSON in Rails functional tests

Posted by on Oct 8, 2010 in code | No Comments

If your rails controllers return JSON, 30 you can call ActiveSupport::JSON.decode Setting on the response body to get a hash you can validate in your cheap mlb jerseys functional tests. Since that doesn’t quite wholesale mlb jerseys roll off the tongue, I’ve added this method wholesale nba jerseys to my test-helper.rb:

class  свободу  ActionController::TestCase
  def  интернет-магазина  json
    ActiveSupport::JSON.decode @response.body
  end
end

Now I can evaluate the JSON like this:

get  cheap jerseys  :index, :format =>  Basket  "json"
assert_equal  wholesale nfl jerseys  json['foo']['bar'].size, 2
assert json['foo']['bar'].include?('baz')

Leave a Reply