i've written template stuff json object, example:
{ "list": [ <% ['a', 'b', 'c', 'd'].each |letter| %> <%= puts "{ \"letter\": \"" + letter + "\" }," %> <% end %> ] }
how can write unit test check if json output valid? i'm new ruby don't know tools use this. also, there better way make list of json objects in erb template?
i don't have access to, or knowledge of thing that's processing template i'm not positive ruby libraries can consume.
note: rails not involved. vanilla ruby.
if trying return object or list json, can call render json: object
controller. can test same way can test other controller: http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers
if absolutely need in erb whatever reason, can call .to_json
method on object between erb tags: <%= object.to_json %>
.
the .to_json
method return valid json.
Comments
Post a Comment