-
Notifications
You must be signed in to change notification settings - Fork 22
/
validation_spec.rb
66 lines (51 loc) · 1.48 KB
/
validation_spec.rb
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
57
58
59
60
61
62
63
64
65
require 'nokogiri'
require 'pp'
RSpec.describe 'Validate Examples' do
before :all do
@xsd = Nokogiri::XML::Schema(File.read('BuildingSync.xsd'))
end
it 'should validate xmls' do
total_errors = 0
Dir['examples/*.xml'].each do |xml|
puts "Validating file: #{xml}"
# skip the invalid schema file
next if xml =~ /Invalid Schema/
doc = Nokogiri::XML(File.read(xml))
errors = []
@xsd.validate(doc).each do |error|
errors << { file: xml, error: error }
end
unless errors.size.zero?
puts " There were #{errors.size} errors!"
pp errors
end
total_errors += errors.size
puts "\n"
end
expect(total_errors).to eq 0
end
end
RSpec.describe 'No Tabs in Examples' do
it 'should not have any tabs in the XMLS' do
total_errors = 0
Dir['examples/*.xml', 'BuildingSync.xsd'].each do |xml|
puts "Checking for tabs in file: #{xml}"
errors = []
if File.read(xml).include? "\t"
errors << "File #{xml} includes tabs, please remove the Tabs (run 'rake remove_tabs')"
end
unless errors.size.zero?
puts " There were #{errors.size} errors!"
pp errors
end
total_errors += errors.size
puts "\n"
end
expect(total_errors).to eq 0
end
end
RSpec.describe 'No complexContent in XSD' do
it 'should not have any complexContent' do
expect(File.read('BuildingSync.xsd').include? "complexContent").to eq false
end
end