mods 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/spec/part_spec.rb CHANGED
@@ -3,29 +3,7 @@ require 'spec_helper'
3
3
  describe "Mods <part> Element" do
4
4
  before(:all) do
5
5
  @mods_rec = Mods::Record.new
6
- @ex = @mods_rec.from_str('<mods><part>
7
- <detail>
8
- <title>Wayfarers (Poem)</title>
9
- </detail>
10
- <extent unit="pages">
11
- <start>97</start>
12
- <end>98</end>
13
- </extent>
14
- </part></mods>').part
15
- @ex2 = @mods_rec.from_str('<mods><part>
16
- <detail type="page number">
17
- <number>3</number>
18
- </detail>
19
- <extent unit="pages">
20
- <start>3</start>
21
- </extent>
22
- </part></mods>').part
23
- @detail = @mods_rec.from_str('<mods><part>
24
- <detail type="issue">
25
- <number>1</number>
26
- <caption>no.</caption>
27
- </detail>
28
- </part></mods>').part
6
+ @ns_decl = "xmlns='#{Mods::MODS_NS}'"
29
7
  end
30
8
 
31
9
  it "should normalize dates" do
@@ -33,204 +11,461 @@ describe "Mods <part> Element" do
33
11
  end
34
12
 
35
13
  context "basic <part> terminology pieces" do
36
- it "should be a NodeSet" do
37
- [@ex, @ex2, @detail].each { |p| p.should be_an_instance_of(Nokogiri::XML::NodeSet) }
38
- end
39
- it "should have as many members as there are <part> elements in the xml" do
40
- [@ex, @ex2, @detail].each { |p| p.size.should == 1 }
41
- end
42
- it "should recognize type(_at) attribute on <part> element" do
43
- @mods_rec.from_str("<mods><part type='val'>anything</part></mods>")
44
- @mods_rec.part.type_at.should == ['val']
45
- end
46
- it "should recognize order attribute on <part> element" do
47
- @mods_rec.from_str("<mods><part order='val'>anything</part></mods>")
48
- @mods_rec.part.order.should == ['val']
49
- end
50
- it "should recognize ID attribute on <part> element as id_at term" do
51
- @mods_rec.from_str("<mods><part ID='val'>anything</part></mods>")
52
- @mods_rec.part.id_at.should == ['val']
53
- end
54
-
55
- context "<detail> child element" do
14
+
15
+ context "WITH namespaces" do
16
+ before(:all) do
17
+ @ex = @mods_rec.from_str("<mods #{@ns_decl}><part>
18
+ <detail>
19
+ <title>Wayfarers (Poem)</title>
20
+ </detail>
21
+ <extent unit='pages'>
22
+ <start>97</start>
23
+ <end>98</end>
24
+ </extent>
25
+ </part></mods>").part
26
+ @ex2 = @mods_rec.from_str("<mods #{@ns_decl}><part>
27
+ <detail type='page number'>
28
+ <number>3</number>
29
+ </detail>
30
+ <extent unit='pages'>
31
+ <start>3</start>
32
+ </extent>
33
+ </part></mods>").part
34
+ @detail = @mods_rec.from_str("<mods #{@ns_decl}><part>
35
+ <detail type='issue'>
36
+ <number>1</number>
37
+ <caption>no.</caption>
38
+ </detail>
39
+ </part></mods>").part
40
+ end
41
+
56
42
  it "should be a NodeSet" do
57
- [@ex, @ex2, @detail].each { |p| p.detail.should be_an_instance_of(Nokogiri::XML::NodeSet) }
43
+ [@ex, @ex2, @detail].each { |p| p.should be_an_instance_of(Nokogiri::XML::NodeSet) }
58
44
  end
59
- it "detail NodeSet should have as many Nodes as there are <detail> elements in the xml" do
60
- [@ex, @ex2, @detail].each { |p| p.detail.size.should == 1 }
45
+ it "should have as many members as there are <part> elements in the xml" do
46
+ [@ex, @ex2, @detail].each { |p| p.size.should == 1 }
61
47
  end
62
- it "should recognize type(_at) attribute on <detail> element" do
63
- @ex2.detail.type_at.should == ['page number']
64
- @detail.detail.type_at.should == ['issue']
48
+ it "should recognize type(_at) attribute on <part> element" do
49
+ @mods_rec.from_str("<mods #{@ns_decl}><part type='val'>anything</part></mods>")
50
+ @mods_rec.part.type_at.should == ['val']
65
51
  end
66
- it "should recognize level attribute on <detail> element" do
67
- @mods_rec.from_str("<mods><part><detail level='val'>anything</detail></part></mods>")
68
- @mods_rec.part.detail.level.should == ['val']
52
+ it "should recognize order attribute on <part> element" do
53
+ @mods_rec.from_str("<mods #{@ns_decl}><part order='val'>anything</part></mods>")
54
+ @mods_rec.part.order.should == ['val']
69
55
  end
70
- context "<number> child element" do
56
+ it "should recognize ID attribute on <part> element as id_at term" do
57
+ @mods_rec.from_str("<mods #{@ns_decl}><part ID='val'>anything</part></mods>")
58
+ @mods_rec.part.id_at.should == ['val']
59
+ end
60
+
61
+ context "<detail> child element" do
62
+ it "should be a NodeSet" do
63
+ [@ex, @ex2, @detail].each { |p| p.detail.should be_an_instance_of(Nokogiri::XML::NodeSet) }
64
+ end
65
+ it "detail NodeSet should have as many Nodes as there are <detail> elements in the xml" do
66
+ [@ex, @ex2, @detail].each { |p| p.detail.size.should == 1 }
67
+ end
68
+ it "should recognize type(_at) attribute on <detail> element" do
69
+ @ex2.detail.type_at.should == ['page number']
70
+ @detail.detail.type_at.should == ['issue']
71
+ end
72
+ it "should recognize level attribute on <detail> element" do
73
+ @mods_rec.from_str("<mods #{@ns_decl}><part><detail level='val'>anything</detail></part></mods>")
74
+ @mods_rec.part.detail.level.should == ['val']
75
+ end
76
+ context "<number> child element" do
77
+ it "should be a NodeSet" do
78
+ [@ex, @ex2, @detail].each { |p| p.detail.number.should be_an_instance_of(Nokogiri::XML::NodeSet) }
79
+ end
80
+ it "number NodeSet should have as many Nodes as there are <number> elements in the xml" do
81
+ [@ex2, @detail].each { |p| p.detail.number.size.should == 1 }
82
+ @ex.detail.number.size.should == 0
83
+ end
84
+ it "text should get element value" do
85
+ @ex2.detail.number.map { |n| n.text }.should == ['3']
86
+ @detail.detail.number.map { |n| n.text }.should == ['1']
87
+ end
88
+ end # <number>
89
+ context "<caption> child element" do
90
+ before(:all) do
91
+ @mods_rec.from_str("<mods #{@ns_decl}><part><detail><caption>anything</caption></detail></part></mods>")
92
+ @caption = @mods_rec.part.detail.caption
93
+ end
94
+ it "should be a NodeSet" do
95
+ [@ex, @ex2, @detail].each { |p| p.detail.caption.should be_an_instance_of(Nokogiri::XML::NodeSet) }
96
+ @caption.should be_an_instance_of(Nokogiri::XML::NodeSet)
97
+ end
98
+ it "caption NodeSet should have as many Nodes as there are <caption> elements in the xml" do
99
+ [@ex, @ex2].each { |p| p.detail.caption.size.should == 0 }
100
+ @detail.detail.caption.size.should == 1
101
+ @caption.size.should == 1
102
+ end
103
+ it "text should get element value" do
104
+ @detail.detail.caption.map { |n| n.text }.should == ['no.']
105
+ @caption.map { |n| n.text }.should == ['anything']
106
+ end
107
+ end # <caption>
108
+ context "<title> child element" do
109
+ it "should be a NodeSet" do
110
+ [@ex, @ex2, @detail].each { |p| p.detail.title.should be_an_instance_of(Nokogiri::XML::NodeSet) }
111
+ end
112
+ it "title NodeSet should have as many Nodes as there are <title> elements in the xml" do
113
+ @ex.detail.title.size.should == 1
114
+ [@ex2, @detail].each { |p| p.detail.title.size.should == 0 }
115
+ end
116
+ it "text should get element value" do
117
+ @ex.detail.title.map { |n| n.text }.should == ['Wayfarers (Poem)']
118
+ [@ex2, @detail].each { |p| p.detail.title.map { |n| n.text }.should == [] }
119
+ end
120
+ end # <title>
121
+ end # <detail>
122
+
123
+ context "<extent> child element" do
71
124
  it "should be a NodeSet" do
72
- [@ex, @ex2, @detail].each { |p| p.detail.number.should be_an_instance_of(Nokogiri::XML::NodeSet) }
125
+ [@ex, @ex2, @detail].each { |p| p.extent.should be_an_instance_of(Nokogiri::XML::NodeSet) }
73
126
  end
74
- it "number NodeSet should have as many Nodes as there are <number> elements in the xml" do
75
- [@ex2, @detail].each { |p| p.detail.number.size.should == 1 }
76
- @ex.detail.number.size.should == 0
127
+ it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
128
+ [@ex, @ex2].each { |p| p.extent.size.should == 1 }
129
+ @detail.extent.size.should == 0
77
130
  end
78
- it "text should get element value" do
79
- @ex2.detail.number.map { |n| n.text }.should == ['3']
80
- @detail.detail.number.map { |n| n.text }.should == ['1']
131
+ it "should recognize unit attribute on <extent> element" do
132
+ [@ex, @ex2].each { |p| p.extent.unit.should == ['pages'] }
81
133
  end
82
- end # <number>
83
- context "<caption> child element" do
134
+ context "<start> child element" do
135
+ it "should be a NodeSet" do
136
+ [@ex, @ex2, @detail].each { |p| p.extent.start.should be_an_instance_of(Nokogiri::XML::NodeSet) }
137
+ end
138
+ it "start NodeSet should have as many Nodes as there are <start> elements in the xml" do
139
+ [@ex, @ex2].each { |p| p.extent.start.size.should == 1 }
140
+ @detail.extent.start.size.should == 0
141
+ end
142
+ it "text should get element value" do
143
+ @ex.extent.start.map { |n| n.text }.should == ['97']
144
+ @ex2.extent.start.map { |n| n.text }.should == ['3']
145
+ end
146
+ end # <start>
147
+ context "<end> child element" do
148
+ it "should be a NodeSet" do
149
+ [@ex, @ex2, @detail].each { |p| p.extent.end.should be_an_instance_of(Nokogiri::XML::NodeSet) }
150
+ end
151
+ it "end NodeSet should have as many Nodes as there are <end> elements in the xml" do
152
+ @ex.extent.end.size.should == 1
153
+ [@ex2, @detail].each { |p| p.extent.end.size.should == 0 }
154
+ end
155
+ it "text should get element value" do
156
+ @ex.extent.end.map { |n| n.text }.should == ['98']
157
+ end
158
+ end # <end>
159
+ context "<total> child element" do
160
+ before(:all) do
161
+ @mods_rec.from_str("<mods #{@ns_decl}><part><extent><total>anything</total></extent></part></mods>")
162
+ @total = @mods_rec.part.extent.total
163
+ end
164
+ it "should be a NodeSet" do
165
+ [@ex, @ex2, @detail].each { |p| p.extent.total.should be_an_instance_of(Nokogiri::XML::NodeSet) }
166
+ @total.should be_an_instance_of(Nokogiri::XML::NodeSet)
167
+ end
168
+ it "total NodeSet should have as many Nodes as there are <total> elements in the xml" do
169
+ [@ex, @ex2, @detail].each { |p| p.extent.total.size.should == 0 }
170
+ @total.size.should == 1
171
+ end
172
+ it "text should get element value" do
173
+ @total.map { |n| n.text }.should == ['anything']
174
+ end
175
+ end # <total>
176
+ context "<list> child element" do
177
+ before(:all) do
178
+ @mods_rec.from_str("<mods #{@ns_decl}><part><extent><list>anything</list></extent></part></mods>")
179
+ @list = @mods_rec.part.extent.list
180
+ end
181
+ it "should be a NodeSet" do
182
+ [@ex, @ex2, @detail].each { |p| p.extent.list.should be_an_instance_of(Nokogiri::XML::NodeSet) }
183
+ @list.should be_an_instance_of(Nokogiri::XML::NodeSet)
184
+ end
185
+ it "list NodeSet should have as many Nodes as there are <list> elements in the xml" do
186
+ [@ex, @ex2, @detail].each { |p| p.extent.list.size.should == 0 }
187
+ @list.size.should == 1
188
+ end
189
+ it "text should get element value" do
190
+ @list.map { |n| n.text }.should == ['anything']
191
+ end
192
+ end # <list>
193
+ end # <extent>
194
+
195
+ context "<date> child element" do
84
196
  before(:all) do
85
- @mods_rec.from_str("<mods><part><detail><caption>anything</caption></detail></part></mods>")
86
- @caption = @mods_rec.part.detail.caption
197
+ @date = @mods_rec.from_str("<mods #{@ns_decl}><part><date encoding='w3cdtf'>1999</date></part></mods>").part.date
87
198
  end
88
199
  it "should be a NodeSet" do
89
- [@ex, @ex2, @detail].each { |p| p.detail.caption.should be_an_instance_of(Nokogiri::XML::NodeSet) }
90
- @caption.should be_an_instance_of(Nokogiri::XML::NodeSet)
200
+ [@ex, @ex2, @detail].each { |p| p.date.should be_an_instance_of(Nokogiri::XML::NodeSet) }
201
+ @date.should be_an_instance_of(Nokogiri::XML::NodeSet)
202
+ end
203
+ it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
204
+ [@ex, @ex2, @detail].each { |p| p.date.size.should == 0 }
205
+ @date.size.should == 1
206
+ end
207
+ it "should recognize all date attributes except keyDate" do
208
+ Mods::DATE_ATTRIBS.reject { |n| n == 'keyDate' }.each { |a|
209
+ @mods_rec.from_str("<mods #{@ns_decl}><part><date #{a}='attr_val'>zzz</date></part></mods>")
210
+ @mods_rec.part.date.send(a.to_sym).should == ['attr_val']
211
+ }
91
212
  end
92
- it "caption NodeSet should have as many Nodes as there are <caption> elements in the xml" do
93
- [@ex, @ex2].each { |p| p.detail.caption.size.should == 0 }
94
- @detail.detail.caption.size.should == 1
95
- @caption.size.should == 1
213
+ it "should not recognize keyDate attribute" do
214
+ @mods_rec.from_str("<mods #{@ns_decl}><part><date keyDate='yes'>zzz</date></part></mods>")
215
+ expect { @mods_rec.part.date.keyDate }.to raise_error(NoMethodError, /undefined method.*keyDate/)
96
216
  end
97
- it "text should get element value" do
98
- @detail.detail.caption.map { |n| n.text }.should == ['no.']
99
- @caption.map { |n| n.text }.should == ['anything']
217
+ end # <date>
218
+
219
+ context "<text> child element as .text_el term" do
220
+ before(:all) do
221
+ @text_ns = @mods_rec.from_str("<mods #{@ns_decl}><part><text encoding='w3cdtf'>1999</text></part></mods>").part.text_el
100
222
  end
101
- end # <caption>
102
- context "<title> child element" do
103
223
  it "should be a NodeSet" do
104
- [@ex, @ex2, @detail].each { |p| p.detail.title.should be_an_instance_of(Nokogiri::XML::NodeSet) }
224
+ [@ex, @ex2, @detail].each { |p| p.text_el.should be_an_instance_of(Nokogiri::XML::NodeSet) }
225
+ @text_ns.should be_an_instance_of(Nokogiri::XML::NodeSet)
226
+ end
227
+ it "text_el NodeSet should have as many Nodes as there are <text> elements in the xml" do
228
+ [@ex, @ex2, @detail].each { |p| p.text_el.size.should == 0 }
229
+ @text_ns.size.should == 1
105
230
  end
106
- it "title NodeSet should have as many Nodes as there are <title> elements in the xml" do
107
- @ex.detail.title.size.should == 1
108
- [@ex2, @detail].each { |p| p.detail.title.size.should == 0 }
231
+ it "should recognize displayLabel attribute" do
232
+ @mods_rec.from_str("<mods #{@ns_decl}><part><text displayLabel='foo'>zzz</text></part></mods>")
233
+ @mods_rec.part.text_el.displayLabel.should == ['foo']
109
234
  end
110
- it "text should get element value" do
111
- @ex.detail.title.map { |n| n.text }.should == ['Wayfarers (Poem)']
112
- [@ex2, @detail].each { |p| p.detail.title.map { |n| n.text }.should == [] }
235
+ it "should recognize type(_at) attribute on <text> element" do
236
+ @mods_rec.from_str("<mods #{@ns_decl}><part><text type='bar'>anything</text></part></mods>")
237
+ @mods_rec.part.text_el.type_at.should == ['bar']
113
238
  end
114
- end # <title>
115
- end # <detail>
239
+ end # <text>
240
+ end # WITH namespaces
116
241
 
117
- context "<extent> child element" do
242
+ context "WITHOUT namespaces" do
243
+ before(:all) do
244
+ @ex = @mods_rec.from_str("<mods><part>
245
+ <detail>
246
+ <title>Wayfarers (Poem)</title>
247
+ </detail>
248
+ <extent unit='pages'>
249
+ <start>97</start>
250
+ <end>98</end>
251
+ </extent>
252
+ </part></mods>", false).part
253
+ @ex2 = @mods_rec.from_str("<mods><part>
254
+ <detail type='page number'>
255
+ <number>3</number>
256
+ </detail>
257
+ <extent unit='pages'>
258
+ <start>3</start>
259
+ </extent>
260
+ </part></mods>", false).part
261
+ @detail = @mods_rec.from_str("<mods><part>
262
+ <detail type='issue'>
263
+ <number>1</number>
264
+ <caption>no.</caption>
265
+ </detail>
266
+ </part></mods>", false).part
267
+ end
268
+
118
269
  it "should be a NodeSet" do
119
- [@ex, @ex2, @detail].each { |p| p.extent.should be_an_instance_of(Nokogiri::XML::NodeSet) }
270
+ [@ex, @ex2, @detail].each { |p| p.should be_an_instance_of(Nokogiri::XML::NodeSet) }
271
+ end
272
+ it "should have as many members as there are <part> elements in the xml" do
273
+ [@ex, @ex2, @detail].each { |p| p.size.should == 1 }
120
274
  end
121
- it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
122
- [@ex, @ex2].each { |p| p.extent.size.should == 1 }
123
- @detail.extent.size.should == 0
275
+ it "should recognize type(_at) attribute on <part> element" do
276
+ @mods_rec.from_str("<mods><part type='val'>anything</part></mods>", false)
277
+ @mods_rec.part.type_at.should == ['val']
124
278
  end
125
- it "should recognize unit attribute on <extent> element" do
126
- [@ex, @ex2].each { |p| p.extent.unit.should == ['pages'] }
279
+ it "should recognize order attribute on <part> element" do
280
+ @mods_rec.from_str("<mods><part order='val'>anything</part></mods>", false)
281
+ @mods_rec.part.order.should == ['val']
127
282
  end
128
- context "<start> child element" do
283
+ it "should recognize ID attribute on <part> element as id_at term" do
284
+ @mods_rec.from_str("<mods><part ID='val'>anything</part></mods>", false)
285
+ @mods_rec.part.id_at.should == ['val']
286
+ end
287
+
288
+ context "<detail> child element" do
129
289
  it "should be a NodeSet" do
130
- [@ex, @ex2, @detail].each { |p| p.extent.start.should be_an_instance_of(Nokogiri::XML::NodeSet) }
290
+ [@ex, @ex2, @detail].each { |p| p.detail.should be_an_instance_of(Nokogiri::XML::NodeSet) }
131
291
  end
132
- it "start NodeSet should have as many Nodes as there are <start> elements in the xml" do
133
- [@ex, @ex2].each { |p| p.extent.start.size.should == 1 }
134
- @detail.extent.start.size.should == 0
292
+ it "detail NodeSet should have as many Nodes as there are <detail> elements in the xml" do
293
+ [@ex, @ex2, @detail].each { |p| p.detail.size.should == 1 }
135
294
  end
136
- it "text should get element value" do
137
- @ex.extent.start.map { |n| n.text }.should == ['97']
138
- @ex2.extent.start.map { |n| n.text }.should == ['3']
295
+ it "should recognize type(_at) attribute on <detail> element" do
296
+ @ex2.detail.type_at.should == ['page number']
297
+ @detail.detail.type_at.should == ['issue']
139
298
  end
140
- end # <start>
141
- context "<end> child element" do
299
+ it "should recognize level attribute on <detail> element" do
300
+ @mods_rec.from_str("<mods><part><detail level='val'>anything</detail></part></mods>", false)
301
+ @mods_rec.part.detail.level.should == ['val']
302
+ end
303
+ context "<number> child element" do
304
+ it "should be a NodeSet" do
305
+ [@ex, @ex2, @detail].each { |p| p.detail.number.should be_an_instance_of(Nokogiri::XML::NodeSet) }
306
+ end
307
+ it "number NodeSet should have as many Nodes as there are <number> elements in the xml" do
308
+ [@ex2, @detail].each { |p| p.detail.number.size.should == 1 }
309
+ @ex.detail.number.size.should == 0
310
+ end
311
+ it "text should get element value" do
312
+ @ex2.detail.number.map { |n| n.text }.should == ['3']
313
+ @detail.detail.number.map { |n| n.text }.should == ['1']
314
+ end
315
+ end # <number>
316
+ context "<caption> child element" do
317
+ before(:all) do
318
+ @mods_rec.from_str("<mods><part><detail><caption>anything</caption></detail></part></mods>", false)
319
+ @caption = @mods_rec.part.detail.caption
320
+ end
321
+ it "should be a NodeSet" do
322
+ [@ex, @ex2, @detail].each { |p| p.detail.caption.should be_an_instance_of(Nokogiri::XML::NodeSet) }
323
+ @caption.should be_an_instance_of(Nokogiri::XML::NodeSet)
324
+ end
325
+ it "caption NodeSet should have as many Nodes as there are <caption> elements in the xml" do
326
+ [@ex, @ex2].each { |p| p.detail.caption.size.should == 0 }
327
+ @detail.detail.caption.size.should == 1
328
+ @caption.size.should == 1
329
+ end
330
+ it "text should get element value" do
331
+ @detail.detail.caption.map { |n| n.text }.should == ['no.']
332
+ @caption.map { |n| n.text }.should == ['anything']
333
+ end
334
+ end # <caption>
335
+ context "<title> child element" do
336
+ it "should be a NodeSet" do
337
+ [@ex, @ex2, @detail].each { |p| p.detail.title.should be_an_instance_of(Nokogiri::XML::NodeSet) }
338
+ end
339
+ it "title NodeSet should have as many Nodes as there are <title> elements in the xml" do
340
+ @ex.detail.title.size.should == 1
341
+ [@ex2, @detail].each { |p| p.detail.title.size.should == 0 }
342
+ end
343
+ it "text should get element value" do
344
+ @ex.detail.title.map { |n| n.text }.should == ['Wayfarers (Poem)']
345
+ [@ex2, @detail].each { |p| p.detail.title.map { |n| n.text }.should == [] }
346
+ end
347
+ end # <title>
348
+ end # <detail>
349
+
350
+ context "<extent> child element" do
142
351
  it "should be a NodeSet" do
143
- [@ex, @ex2, @detail].each { |p| p.extent.end.should be_an_instance_of(Nokogiri::XML::NodeSet) }
352
+ [@ex, @ex2, @detail].each { |p| p.extent.should be_an_instance_of(Nokogiri::XML::NodeSet) }
144
353
  end
145
- it "end NodeSet should have as many Nodes as there are <end> elements in the xml" do
146
- @ex.extent.end.size.should == 1
147
- [@ex2, @detail].each { |p| p.extent.end.size.should == 0 }
354
+ it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
355
+ [@ex, @ex2].each { |p| p.extent.size.should == 1 }
356
+ @detail.extent.size.should == 0
148
357
  end
149
- it "text should get element value" do
150
- @ex.extent.end.map { |n| n.text }.should == ['98']
358
+ it "should recognize unit attribute on <extent> element" do
359
+ [@ex, @ex2].each { |p| p.extent.unit.should == ['pages'] }
151
360
  end
152
- end # <end>
153
- context "<total> child element" do
361
+ context "<start> child element" do
362
+ it "should be a NodeSet" do
363
+ [@ex, @ex2, @detail].each { |p| p.extent.start.should be_an_instance_of(Nokogiri::XML::NodeSet) }
364
+ end
365
+ it "start NodeSet should have as many Nodes as there are <start> elements in the xml" do
366
+ [@ex, @ex2].each { |p| p.extent.start.size.should == 1 }
367
+ @detail.extent.start.size.should == 0
368
+ end
369
+ it "text should get element value" do
370
+ @ex.extent.start.map { |n| n.text }.should == ['97']
371
+ @ex2.extent.start.map { |n| n.text }.should == ['3']
372
+ end
373
+ end # <start>
374
+ context "<end> child element" do
375
+ it "should be a NodeSet" do
376
+ [@ex, @ex2, @detail].each { |p| p.extent.end.should be_an_instance_of(Nokogiri::XML::NodeSet) }
377
+ end
378
+ it "end NodeSet should have as many Nodes as there are <end> elements in the xml" do
379
+ @ex.extent.end.size.should == 1
380
+ [@ex2, @detail].each { |p| p.extent.end.size.should == 0 }
381
+ end
382
+ it "text should get element value" do
383
+ @ex.extent.end.map { |n| n.text }.should == ['98']
384
+ end
385
+ end # <end>
386
+ context "<total> child element" do
387
+ before(:all) do
388
+ @mods_rec.from_str("<mods><part><extent><total>anything</total></extent></part></mods>", false)
389
+ @total = @mods_rec.part.extent.total
390
+ end
391
+ it "should be a NodeSet" do
392
+ [@ex, @ex2, @detail].each { |p| p.extent.total.should be_an_instance_of(Nokogiri::XML::NodeSet) }
393
+ @total.should be_an_instance_of(Nokogiri::XML::NodeSet)
394
+ end
395
+ it "total NodeSet should have as many Nodes as there are <total> elements in the xml" do
396
+ [@ex, @ex2, @detail].each { |p| p.extent.total.size.should == 0 }
397
+ @total.size.should == 1
398
+ end
399
+ it "text should get element value" do
400
+ @total.map { |n| n.text }.should == ['anything']
401
+ end
402
+ end # <total>
403
+ context "<list> child element" do
404
+ before(:all) do
405
+ @mods_rec.from_str("<mods><part><extent><list>anything</list></extent></part></mods>", false)
406
+ @list = @mods_rec.part.extent.list
407
+ end
408
+ it "should be a NodeSet" do
409
+ [@ex, @ex2, @detail].each { |p| p.extent.list.should be_an_instance_of(Nokogiri::XML::NodeSet) }
410
+ @list.should be_an_instance_of(Nokogiri::XML::NodeSet)
411
+ end
412
+ it "list NodeSet should have as many Nodes as there are <list> elements in the xml" do
413
+ [@ex, @ex2, @detail].each { |p| p.extent.list.size.should == 0 }
414
+ @list.size.should == 1
415
+ end
416
+ it "text should get element value" do
417
+ @list.map { |n| n.text }.should == ['anything']
418
+ end
419
+ end # <list>
420
+ end # <extent>
421
+
422
+ context "<date> child element" do
154
423
  before(:all) do
155
- @mods_rec.from_str("<mods><part><extent><total>anything</total></extent></part></mods>")
156
- @total = @mods_rec.part.extent.total
424
+ @date = @mods_rec.from_str("<mods><part><date encoding='w3cdtf'>1999</date></part></mods>", false).part.date
157
425
  end
158
426
  it "should be a NodeSet" do
159
- [@ex, @ex2, @detail].each { |p| p.extent.total.should be_an_instance_of(Nokogiri::XML::NodeSet) }
160
- @total.should be_an_instance_of(Nokogiri::XML::NodeSet)
427
+ [@ex, @ex2, @detail].each { |p| p.date.should be_an_instance_of(Nokogiri::XML::NodeSet) }
428
+ @date.should be_an_instance_of(Nokogiri::XML::NodeSet)
161
429
  end
162
- it "total NodeSet should have as many Nodes as there are <total> elements in the xml" do
163
- [@ex, @ex2, @detail].each { |p| p.extent.total.size.should == 0 }
164
- @total.size.should == 1
430
+ it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
431
+ [@ex, @ex2, @detail].each { |p| p.date.size.should == 0 }
432
+ @date.size.should == 1
165
433
  end
166
- it "text should get element value" do
167
- @total.map { |n| n.text }.should == ['anything']
434
+ it "should recognize all date attributes except keyDate" do
435
+ Mods::DATE_ATTRIBS.reject { |n| n == 'keyDate' }.each { |a|
436
+ @mods_rec.from_str("<mods><part><date #{a}='attr_val'>zzz</date></part></mods>", false)
437
+ @mods_rec.part.date.send(a.to_sym).should == ['attr_val']
438
+ }
168
439
  end
169
- end # <total>
170
- context "<list> child element" do
440
+ it "should not recognize keyDate attribute" do
441
+ @mods_rec.from_str("<mods><part><date keyDate='yes'>zzz</date></part></mods>", false)
442
+ expect { @mods_rec.part.date.keyDate }.to raise_error(NoMethodError, /undefined method.*keyDate/)
443
+ end
444
+ end # <date>
445
+
446
+ context "<text> child element as .text_el term" do
171
447
  before(:all) do
172
- @mods_rec.from_str("<mods><part><extent><list>anything</list></extent></part></mods>")
173
- @list = @mods_rec.part.extent.list
448
+ @text_ns = @mods_rec.from_str("<mods><part><text encoding='w3cdtf'>1999</text></part></mods>", false).part.text_el
174
449
  end
175
450
  it "should be a NodeSet" do
176
- [@ex, @ex2, @detail].each { |p| p.extent.list.should be_an_instance_of(Nokogiri::XML::NodeSet) }
177
- @list.should be_an_instance_of(Nokogiri::XML::NodeSet)
451
+ [@ex, @ex2, @detail].each { |p| p.text_el.should be_an_instance_of(Nokogiri::XML::NodeSet) }
452
+ @text_ns.should be_an_instance_of(Nokogiri::XML::NodeSet)
178
453
  end
179
- it "list NodeSet should have as many Nodes as there are <list> elements in the xml" do
180
- [@ex, @ex2, @detail].each { |p| p.extent.list.size.should == 0 }
181
- @list.size.should == 1
454
+ it "text_el NodeSet should have as many Nodes as there are <text> elements in the xml" do
455
+ [@ex, @ex2, @detail].each { |p| p.text_el.size.should == 0 }
456
+ @text_ns.size.should == 1
182
457
  end
183
- it "text should get element value" do
184
- @list.map { |n| n.text }.should == ['anything']
458
+ it "should recognize displayLabel attribute" do
459
+ @mods_rec.from_str("<mods><part><text displayLabel='foo'>zzz</text></part></mods>", false)
460
+ @mods_rec.part.text_el.displayLabel.should == ['foo']
185
461
  end
186
- end # <list>
187
- end # <extent>
188
-
189
- context "<date> child element" do
190
- before(:all) do
191
- @date = @mods_rec.from_str('<mods><part><date encoding="w3cdtf">1999</date></part></mods').part.date
192
- end
193
- it "should be a NodeSet" do
194
- [@ex, @ex2, @detail].each { |p| p.date.should be_an_instance_of(Nokogiri::XML::NodeSet) }
195
- @date.should be_an_instance_of(Nokogiri::XML::NodeSet)
196
- end
197
- it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
198
- [@ex, @ex2, @detail].each { |p| p.date.size.should == 0 }
199
- @date.size.should == 1
200
- end
201
- it "should recognize all date attributes except keyDate" do
202
- Mods::DATE_ATTRIBS.reject { |n| n == 'keyDate' }.each { |a|
203
- @mods_rec.from_str("<mods><part><date #{a}='attr_val'>zzz</date></part></mods>")
204
- @mods_rec.part.date.send(a.to_sym).should == ['attr_val']
205
- }
206
- end
207
- it "should not recognize keyDate attribute" do
208
- @mods_rec.from_str("<mods><part><date keyDate='yes'>zzz</date></part></mods>")
209
- expect { @mods_rec.part.date.keyDate }.to raise_error(NoMethodError, /undefined method.*keyDate/)
210
- end
211
- end # <date>
462
+ it "should recognize type(_at) attribute on <text> element" do
463
+ @mods_rec.from_str("<mods><part><text type='bar'>anything</text></part></mods>", false)
464
+ @mods_rec.part.text_el.type_at.should == ['bar']
465
+ end
466
+ end # <text>
467
+ end # WITHOUT namespaces
212
468
 
213
- context "<text> child element as .text_el term" do
214
- before(:all) do
215
- @text_ns = @mods_rec.from_str('<mods><part><text encoding="w3cdtf">1999</text></part></mods').part.text_el
216
- end
217
- it "should be a NodeSet" do
218
- [@ex, @ex2, @detail].each { |p| p.text_el.should be_an_instance_of(Nokogiri::XML::NodeSet) }
219
- @text_ns.should be_an_instance_of(Nokogiri::XML::NodeSet)
220
- end
221
- it "text_el NodeSet should have as many Nodes as there are <text> elements in the xml" do
222
- [@ex, @ex2, @detail].each { |p| p.text_el.size.should == 0 }
223
- @text_ns.size.should == 1
224
- end
225
- it "should recognize displayLabel attribute" do
226
- @mods_rec.from_str("<mods><part><text displayLabel='foo'>zzz</text></part></mods>")
227
- @mods_rec.part.text_el.displayLabel.should == ['foo']
228
- end
229
- it "should recognize type(_at) attribute on <text> element" do
230
- @mods_rec.from_str("<mods><part><text type='bar'>anything</text></part></mods>")
231
- @mods_rec.part.text_el.type_at.should == ['bar']
232
- end
233
- end # <text>
234
469
 
235
470
  end # basic <part> terminoology
236
471
  end