Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ jobs:
- name: Install ruby dependencies
run: bundle install --jobs 4 --retry 3
- name: Validate YAML
run: USEKWALIFY="yes" bundle exec rake lint
run: |
bundle exec rake lint
USEKWALIFY="yes" bundle exec rake lint
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source 'https://rubygems.org'

gem 'rake'
gem 'faraday', '~> 2.0'
gem 'kwalify', '~> 0.1'
gem 'json_schemer', '~> 2.0'
gem 'rspec', '~> 3.0'

Expand Down
12 changes: 11 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ namespace :lint do
abort "Please run `gem install rspec` to install RSpec."
end
end

# json
RSpec::Core::RakeTask.new(:schema) do |t|
t.pattern = 'spec/schema_validation_spec.rb'
end

# non-kwalify and kwalify
RSpec::Core::RakeTask.new(:yaml) do |t|
t.exclude_pattern = 'spec/schema_validation_spec.rb'
end
end

desc "Sync GitHub RubyGem Advisories into this project"
Expand All @@ -18,5 +28,5 @@ task :sync_github_advisories, [:gem_name] do |_, args|
GitHub::GitHubAdvisorySync.sync(gem_name: args[:gem_name])
end

task :lint => ['lint:yaml']
task :lint => [ 'lint:schema', 'lint:yaml' ]
task :default => :lint
11 changes: 11 additions & 0 deletions spec/gem_advisory_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,16 @@
end
end

if ENV['USEKWALIFY'] == 'yes'
let(:schema_file) { File.join(__dir__, 'schemas/gem.yml') }

it "should have valid schema" do
schema = YAML.safe_load_file(schema_file)
validator = Kwalify::Validator.new(schema)
errors = validator.validate(advisory)

expect(errors).to be_empty
end
end
end
end
11 changes: 11 additions & 0 deletions spec/ruby_advisory_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@
end
end

if ENV['USEKWALIFY'] == 'yes'
let(:schema_file) { File.join(__dir__, 'schemas/ruby.yml') }

it "should have valid schema" do
schema = YAML.safe_load_file(schema_file)
validator = Kwalify::Validator.new(schema)
errors = validator.validate(advisory)

expect(errors).to be_empty
end
end
end
end
13 changes: 9 additions & 4 deletions spec/schema_validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ def format_errors(errors)
filename = path.split('/')[-2..].join('/')

it "#{filename} conforms to schema" do
raw_data = YAML.safe_load_file(path, permitted_classes: [Date])
data = normalize_for_json(raw_data)
errors = raw_yaml_field_checks(raw_data) + schemer.validate(data).to_a

if ENV['USEKWALIFY'] == 'yes'
data = normalize_for_json(YAML.safe_load_file(path,
permitted_classes: [Date]))
errors = schemer.validate(data).to_a
else
raw_data = YAML.safe_load_file(path, permitted_classes: [Date])
data = normalize_for_json(raw_data)
errors = raw_yaml_field_checks(raw_data) + schemer.validate(data).to_a
end
expect(errors).to be_empty, lambda {
"#{filename}\n#{format_errors(errors)}"
}
Expand Down
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
require 'strscan'

class StringScanner
def peep(len)
peek(len)
end
end
require 'kwalify'

require 'date'
require 'rspec'

Expand Down