Skip to content
Newer
Older
100644 29 lines (23 sloc) 893 Bytes
77d639e @ManuelArno * added validator spec
ManuelArno authored Jun 7, 2011
1 require 'minitest/autorun'
2 require 'json-schema'
3 require 'awesome_print'
4
5 SCHEMA_FILE = File.join(File.dirname(File.expand_path(__FILE__)) , 'schema', 'question.json')
6 QUESTIONS_PATH = File.join(File.dirname(File.expand_path(__FILE__)) , 'questions')
7 schema = File.open(SCHEMA_FILE) { |f| JSON.parse(f.read) }
8
9 describe 'question' do
10 Dir["#{QUESTIONS_PATH}/**/*\.*"].each do |file|
11 it "#{file.sub(/\..*$/,'')} contains valid json" do
12
13 question = File.open(file) { |f| JSON.parse(f.read) }['question']
14
15 begin
16 JSON::Validator.validate!(schema, question, version: :draft3 )
17 rescue JSON::Schema::ValidationError => schema_error
18 assertion = false, schema_error.message
19 rescue JSON::ParserError => parser_error
20 assertion = false, parser_error.message
21 else
22 assertion = true
23 end
24
25 assert *assertion
26 end
27 end
28 end
Something went wrong with that request. Please try again.