/
code_list_spec.rb
112 lines (90 loc) · 2.79 KB
/
code_list_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require File.expand_path('../../../spec_helper', __FILE__)
require 'nokogiri'
module NcsNavigator::Mdes
describe CodeListEntry do
describe '.from_xsd_enumeration' do
def code_list_entry(xml_s)
CodeListEntry.from_xsd_enumeration(schema_element(xml_s), :log => logger)
end
let(:missing) {
code_list_entry(<<-XSD)
<xs:enumeration value="-4" ncsdoc:label="Missing in Error" ncsdoc:desc="" ncsdoc:global_value="99-4" ncsdoc:master_cl="missing_data"/>
XSD
}
describe '#value' do
it 'is set' do
missing.value.should == "-4"
end
it 'warns when missing' do
code_list_entry('<xs:enumeration ncsdoc:label="Foo"/>')
logger[:warn].first.should == 'Missing value for code list entry on line 2'
end
describe 'with external whitespace on the value' do
let(:missing) {
code_list_entry(<<-XSD)
<xs:enumeration value=" -4 " ncsdoc:label="Missing in Error" ncsdoc:desc="" ncsdoc:global_value="99-4" ncsdoc:master_cl="missing_data"/>
XSD
}
it 'removes the whitespace' do
missing.value.should == '-4'
end
end
end
describe "#label" do
it 'is set' do
missing.label.should == "Missing in Error"
end
end
describe '#global_value' do
it 'is set' do
missing.global_value.should == '99-4'
end
end
describe '#master_cl' do
it 'is set' do
missing.master_cl.should == 'missing_data'
end
end
end
describe '#to_s' do
it 'is the value' do
CodeListEntry.new('14').to_s.should == '14'
end
end
describe '#diff' do
let(:a) { CodeListEntry.new('A') }
let(:aprime) { CodeListEntry.new('A') }
let(:diff) { a.diff(aprime) }
it 'reports nothing for no differences' do
diff.should be_nil
end
describe 'value' do
let(:b) { CodeListEntry.new('B') }
it 'reports a difference' do
b.diff(a)[:value].should be_a_value_diff('B', 'A')
end
end
describe 'label' do
it 'reports a difference' do
a.label = 'Aleph'
aprime.label = 'Alpha'
diff[:label].should be_a_value_diff('Aleph', 'Alpha')
end
end
describe 'global_value' do
it 'reports a difference' do
a.global_value = '0'
aprime.global_value = '-0'
diff[:global_value].should be_a_value_diff('0', '-0')
end
end
describe 'master_cl' do
it 'reports a difference' do
a.master_cl = 'C'
aprime.master_cl = 'Cprime'
diff[:master_cl].should be_a_value_diff('C', 'Cprime')
end
end
end
end
end