1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
describe MetadataJsonLint::Schema do
describe '#schema' do
it { expect(subject.schema).to be_a(Hash) }
end
describe '#validate' do
let(:minimal) do
{ author: '', dependencies: [], license: 'A', name: 'a-a', source: '', summary: '', version: '1.0.0' }
end
context 'with empty hash' do
subject { described_class.new.validate({}) }
it { is_expected.to be_a(Array) }
it { expect(subject.size).to eq(7) }
it { is_expected.to include(field: 'root', message: "The file did not contain a required property of 'author'") }
end
context 'with minimal entries' do
subject { described_class.new.validate(minimal) }
it { is_expected.to eq([]) }
end
context 'with validation error on entry' do
subject { described_class.new.validate(minimal.merge(summary: 'A' * 145)) }
it {
expect(subject).to eq([{ field: 'summary',
message: "The property 'summary' was not of a maximum string length of 144", }])
}
end
context 'with validation error on nested entry' do
subject { described_class.new.validate(minimal.merge(dependencies: [{ name: 'in###id' }])) }
it { expect(subject.size).to eq(1) }
it {
expect(subject).to include(field: 'dependencies',
message: a_string_matching(%r{The property 'dependencies/0/name' value "in###id" did not match the regex}))
}
end
context 'with semver validation failure' do
subject { described_class.new.validate(minimal.merge(version: 'a')) }
it { expect(subject.size).to eq(1) }
it {
expect(subject).to include(field: 'version',
message: a_string_matching(/The property 'version' must be a valid semantic version/))
}
end
end
end
|