This post originated from an RSS feed registered with Agile Buzz
by Oliver Steele.
Original Post: JCON: Ruby Gem for JSON type conformance
Feed Title: Oliver Steele on Software
Feed URL: http://feeds.feedburner.com/osteele
Feed Description: Languages of the real and artificial.
JCON (the JavaScript Conformance gem) tests JSON values against ECMAScript 4.0-style type definitions
(PDF) such as string?, (int, boolean), or [string, (int, boolean), {x:double, y:double}?].
Use JCON together with the JavaScript Fu Rails plugin to test the argument values to functions in generated JavaScript:
# this will succeed if e.g. response contains a script tag that includes# fn("id", {x:1, y:2}, true)
response.should call_js(‘fn’)do |args|
args[0].should conform_to_js(‘string’)
args[1].should conform_to_js(‘{x:int, y:int}’)
args[2].should conform_to_js(‘boolean’)# or:
args.should conform_to_js(‘[string, {x:int, y:int}, boolean]’)end
JCON is at version 0.1 because it’s just a few days old and I had to guess about the ECMAScript 4.0 type syntax from the examples in the overview. I can’t imagine that I got everything right.