xsd-reader 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/element_spec.rb CHANGED
@@ -2,22 +2,25 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe XsdReader::Element do
4
4
 
5
- before :all do
6
- @reader ||= XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-ern-v36.xsd')))
7
- @element = @reader.elements[0]
8
- end
5
+ let(:reader){
6
+ XsdReader::XML.new(:xsd_file => File.expand_path(File.join(File.dirname(__FILE__), 'examples', 'ddex-v36', 'ddex-ern-v36.xsd')))
7
+ }
8
+
9
+ let(:element){
10
+ reader.elements[0]
11
+ }
9
12
 
10
13
  it "gives the element's name" do
11
- expect(@element.name).to eq 'NewReleaseMessage'
14
+ expect(element.name).to eq 'NewReleaseMessage'
12
15
  end
13
16
 
14
17
  it "gives a complex type reader" do
15
- expect(@element.complex_type.class).to eq XsdReader::ComplexType
18
+ expect(element.complex_type.class).to eq XsdReader::ComplexType
16
19
  end
17
20
 
18
21
  it "gives child elements defined within a complex type" do
19
22
  # byebug
20
- expect(@element.elements.map(&:name)).to eq [
23
+ expect(element.elements.map(&:name)).to eq [
21
24
  "MessageHeader",
22
25
  "UpdateIndicator",
23
26
  "IsBackfill",
@@ -31,24 +34,24 @@ describe XsdReader::Element do
31
34
  end
32
35
 
33
36
  describe "External type definition" do
34
- before :each do
35
- @element = @element.elements.first
36
- end
37
+ let(:header){
38
+ element.elements.first
39
+ }
37
40
 
38
41
  it "gives the type name" do
39
- expect(@element.type_name).to eq 'MessageHeader'
42
+ expect(header.type_name).to eq 'MessageHeader'
40
43
  end
41
44
 
42
45
  it "gives the type namespace" do
43
- expect(@element.type_namespace).to eq 'ern'
46
+ expect(header.type_namespace).to eq 'ern'
44
47
  end
45
48
 
46
49
  it "gives the type string" do
47
- expect(@element.type).to eq 'ern:MessageHeader'
50
+ expect(header.type).to eq 'ern:MessageHeader'
48
51
  end
49
52
 
50
53
  it "gives the remote complex_type, linked by type" do
51
- expect(@element.complex_type.name).to eq 'MessageHeader'
54
+ expect(header.complex_type.name).to eq 'MessageHeader'
52
55
  end
53
56
 
54
57
  it "includes child elements defined in external the complex type type definitions" do
@@ -64,15 +67,15 @@ describe XsdReader::Element do
64
67
  "Comment",
65
68
  "MessageControlType"]
66
69
 
67
- expect(@element.elements.map(&:name)).to eq expected
68
- expect(@element.complex_type.all_elements.map(&:name)).to eq expected
70
+ expect(header.elements.map(&:name)).to eq expected
71
+ expect(header.complex_type.all_elements.map(&:name)).to eq expected
69
72
  end
70
73
  end
71
74
 
72
75
  describe "#elements" do
73
76
 
74
77
  it "includes elements within a choice node" do
75
- el = @element.elements[3]
78
+ el = element.elements[3]
76
79
  expect(el.name).to eq 'CatalogTransfer'
77
80
  elements_without = ["CatalogTransferCompleted", "EffectiveTransferDate", "CatalogReleaseReferenceList", "TransferringFrom", "TransferringTo"]
78
81
  elements_with = ["CatalogTransferCompleted", "EffectiveTransferDate", "CatalogReleaseReferenceList", "TerritoryCode", "ExcludedTerritoryCode", "TransferringFrom", "TransferringTo"]
@@ -111,18 +114,18 @@ describe XsdReader::Element do
111
114
 
112
115
  # byebug
113
116
 
114
- expect(@reader['NewReleaseMessage']['DealList']['ReleaseDeal']['Deal']['DealTerms'].elements.map(&:name)).to eq expected
117
+ expect(reader['NewReleaseMessage']['DealList']['ReleaseDeal']['Deal']['DealTerms'].elements.map(&:name)).to eq expected
115
118
  end
116
119
  end
117
120
 
118
121
  # # this is pretty slow...
119
122
  # describe "#family_tree" do
120
123
  # before :each do
121
- # @element = @reader.elements[0]
124
+ # element = reader.elements[0]
122
125
  # end
123
126
 
124
127
  # it "gives a family tree as a nested list of children, keys being nodes name, values being either another hash of children of strings with the names of the children" do
125
- # expect(@element.family_tree.keys).to eq [
128
+ # expect(element.family_tree.keys).to eq [
126
129
  # "MessageHeader",
127
130
  # "UpdateIndicator",
128
131
  # "IsBackfill",
@@ -135,7 +138,7 @@ describe XsdReader::Element do
135
138
  # "DealList"
136
139
  # ]
137
140
 
138
- # expect(@element.family_tree['ResourceList'].keys).to eq [
141
+ # expect(element.family_tree['ResourceList'].keys).to eq [
139
142
  # "SoundRecording",
140
143
  # "MIDI",
141
144
  # "Video",
@@ -146,7 +149,7 @@ describe XsdReader::Element do
146
149
  # "UserDefinedResource"
147
150
  # ]
148
151
 
149
- # expect(@element.family_tree['DealList']['ReleaseDeal']['Deal']['DealTerms']['RightsClaimPolicy']['Condition']['Unit']).to eq 'type:UnitOfConditionValue'
152
+ # expect(element.family_tree['DealList']['ReleaseDeal']['Deal']['DealTerms']['RightsClaimPolicy']['Condition']['Unit']).to eq 'type:UnitOfConditionValue'
150
153
  # end
151
154
  # end
152
155
 
@@ -157,12 +160,12 @@ describe XsdReader::Element do
157
160
  "BusinessProfileVersionId",
158
161
  "ReleaseProfileVersionId",
159
162
  "LanguageAndScriptCode"]
160
- expect(@element.attributes.map(&:name)).to eq expected
161
- expect(@element.complex_type.attributes.map(&:name)).to eq expected
163
+ expect(element.attributes.map(&:name)).to eq expected
164
+ expect(element.complex_type.attributes.map(&:name)).to eq expected
162
165
  end
163
166
 
164
167
  it "gives attributes defined in a simpleContent extension" do
165
- expect(@element['ResourceList']['SoundRecording']['SoundRecordingDetailsByTerritory']['DisplayArtist']['ArtistRole'].attributes.map(&:name)).to eq ["Namespace", "UserDefinedValue"]
168
+ expect(element['ResourceList']['SoundRecording']['SoundRecordingDetailsByTerritory']['DisplayArtist']['ArtistRole'].attributes.map(&:name)).to eq ["Namespace", "UserDefinedValue"]
166
169
  end
167
170
  end
168
171