Browse Source

assume schema validation true for test

pull/91/head
magicmilo 3 years ago
parent
commit
b410ca04f8
  1. 6
      lib/tasks/form_definition.rake
  2. 3
      spec/lib/tasks/form_definition_validator_spec.rb

6
lib/tasks/form_definition.rake

@ -15,7 +15,6 @@ namespace :form_definition do
desc "Validate JSON against Generic Form Schema" desc "Validate JSON against Generic Form Schema"
task validate_all: :environment do task validate_all: :environment do
directories = ["config/forms", "spec/fixtures/forms"] directories = ["config/forms", "spec/fixtures/forms"]
paths = get_all_form_paths(directories) paths = get_all_form_paths(directories)
@ -26,7 +25,6 @@ namespace :form_definition do
end end
task :validate, %i[path] => :environment do |_task, args| task :validate, %i[path] => :environment do |_task, args|
puts args puts args
path = Rails.root.join("config/forms/schema/generic.json") path = Rails.root.join("config/forms/schema/generic.json")
@ -36,11 +34,13 @@ namespace :form_definition do
puts path puts path
binding.pry
if JSON::Validator.validate(meta_schema, schema) if JSON::Validator.validate(meta_schema, schema)
puts "Schema Definition is Valid" puts "Schema Definition is Valid"
else else
puts "Schema Definition in #{path} is not valid against draft4 json schema." puts "Schema Definition in #{path} is not valid against draft4 json schema."
return next
end end
path = Rails.root.join(args.path) path = Rails.root.join(args.path)

3
spec/lib/tasks/form_definition_validator_spec.rb

@ -22,11 +22,12 @@ describe "rake form_definition:validate", type: :task do
before do before do
Rake.application.rake_require("tasks/form_definition") Rake.application.rake_require("tasks/form_definition")
Rake::Task.define_task(:environment) Rake::Task.define_task(:environment)
allow(JSON::Validator).to receive(:validate).and_return(true)
task.reenable task.reenable
end end
it "runs the validate task for the given form definition" do it "runs the validate task for the given form definition" do
expect(JSON::Validator).to receive(:validate!).at_least(1).time expect(JSON::Validator).to receive(:validate!).at_least(2).times
task.invoke("config/forms/2021_2022.json") task.invoke("config/forms/2021_2022.json")
end end
end end

Loading…
Cancel
Save