marcspec 1.5.0 → 1.6.1
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/CHANGES +32 -0
- data/Rakefile +21 -11
- data/VERSION +1 -1
- data/lib/marcspec.rb +9 -7
- data/lib/marcspec/constantspec.rb +16 -1
- data/lib/marcspec/controlfieldspec.rb +22 -1
- data/lib/marcspec/customspec.rb +37 -1
- data/lib/marcspec/dsl.rb +20 -5
- data/lib/marcspec/map.rb +8 -7
- data/lib/marcspec/multivaluemap.rb +1 -1
- data/lib/marcspec/solrfieldspec.rb +66 -2
- data/lib/marcspec/specset.rb +79 -11
- data/lib/marcspec/variablefieldspec.rb +52 -4
- data/spec/cachespot_spec.rb +1 -1
- data/spec/controlfieldspec_spec.rb +4 -4
- data/spec/dsl_spec.rb +52 -30
- data/spec/leaderspec_spec.rb +2 -2
- data/spec/maps_spec.rb +42 -42
- data/spec/marcfieldspecs_spec.rb +22 -22
- data/spec/solrfieldspec_spec.rb +24 -24
- data/spec/spec.opts +7 -0
- data/spec/spec_helper.rb +3 -6
- data/spec/specset_spec.rb +20 -19
- data/spec/variablefieldspec_spec.rb +9 -9
- metadata +156 -144
data/spec/dsl_spec.rb
CHANGED
@@ -60,8 +60,8 @@ describe "DSL" do
|
|
60
60
|
value "Bill"
|
61
61
|
end
|
62
62
|
end
|
63
|
-
ss.solrfieldspecs.size.should
|
64
|
-
ss.hash_from_marc(@one)['id'].should
|
63
|
+
ss.solrfieldspecs.size.should == 1
|
64
|
+
ss.hash_from_marc(@one)['id'].should == ['Bill']
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -80,7 +80,7 @@ describe "DSL" do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
ss.hash_from_marc(@one)['hello'].should
|
83
|
+
ss.hash_from_marc(@one)['hello'].should == ['Hello']
|
84
84
|
end
|
85
85
|
|
86
86
|
it "builds a custom that can take a single argument" do
|
@@ -93,7 +93,7 @@ describe "DSL" do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
ss.hash_from_marc(@one)['hello'].should
|
96
|
+
ss.hash_from_marc(@one)['hello'].should == ['Hello Bill']
|
97
97
|
end
|
98
98
|
|
99
99
|
it "builds a custom that can take two arguments" do
|
@@ -106,7 +106,7 @@ describe "DSL" do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
ss.hash_from_marc(@one)['hello'].should
|
109
|
+
ss.hash_from_marc(@one)['hello'].should == ['Hello Bill Dueber']
|
110
110
|
end
|
111
111
|
|
112
112
|
it "builds a custom that can take two arguments" do
|
@@ -119,7 +119,7 @@ describe "DSL" do
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
ss.hash_from_marc(@one)['hello'].should
|
122
|
+
ss.hash_from_marc(@one)['hello'].should == ['Hello 1 2 3 4 5']
|
123
123
|
end
|
124
124
|
|
125
125
|
it "works with multihead" do
|
@@ -131,8 +131,8 @@ describe "DSL" do
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
ss.hash_from_marc(@one)['a'].should
|
135
|
-
ss.hash_from_marc(@one)['b'].should
|
134
|
+
ss.hash_from_marc(@one)['a'].should == ['one']
|
135
|
+
ss.hash_from_marc(@one)['b'].should == ['two']
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
@@ -148,7 +148,7 @@ describe "DSL" do
|
|
148
148
|
spec('001')
|
149
149
|
end
|
150
150
|
end
|
151
|
-
ss.hash_from_marc(@one)['id'].should
|
151
|
+
ss.hash_from_marc(@one)['id'].should == ['afc99990058366']
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should allow integer tags" do
|
@@ -157,7 +157,7 @@ describe "DSL" do
|
|
157
157
|
spec(001)
|
158
158
|
end
|
159
159
|
end
|
160
|
-
ss.hash_from_marc(@one)['id'].should
|
160
|
+
ss.hash_from_marc(@one)['id'].should == ['afc99990058366']
|
161
161
|
end
|
162
162
|
|
163
163
|
it "can get a single char" do
|
@@ -168,7 +168,7 @@ describe "DSL" do
|
|
168
168
|
}
|
169
169
|
end
|
170
170
|
end
|
171
|
-
ss.hash_from_marc(@one)['tst'].should
|
171
|
+
ss.hash_from_marc(@one)['tst'].should == ['c']
|
172
172
|
end
|
173
173
|
|
174
174
|
it "can get a range" do
|
@@ -179,7 +179,7 @@ describe "DSL" do
|
|
179
179
|
}
|
180
180
|
end
|
181
181
|
end
|
182
|
-
ss.hash_from_marc(@one)['tst'].should
|
182
|
+
ss.hash_from_marc(@one)['tst'].should == ['c9999']
|
183
183
|
end
|
184
184
|
|
185
185
|
it "allows multiple char/chars per control field" do
|
@@ -191,7 +191,7 @@ describe "DSL" do
|
|
191
191
|
}
|
192
192
|
end
|
193
193
|
end
|
194
|
-
ss.hash_from_marc(@one)['tst'].should
|
194
|
+
ss.hash_from_marc(@one)['tst'].should == ['c', 'c9999']
|
195
195
|
end
|
196
196
|
|
197
197
|
|
@@ -199,17 +199,17 @@ describe "DSL" do
|
|
199
199
|
|
200
200
|
|
201
201
|
describe "variable fields DSL" do
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
202
|
+
before do
|
203
|
+
@one = MARC4J4R::Reader.new("#{DIR}/data/one.dat").first
|
204
|
+
end
|
205
|
+
|
206
206
|
it "can get a whole variable field" do
|
207
207
|
ss = MARCSpec.build do
|
208
208
|
field("tst") do
|
209
209
|
spec(260)
|
210
210
|
end
|
211
211
|
end
|
212
|
-
ss.hash_from_marc(@one)['tst'].should
|
212
|
+
ss.hash_from_marc(@one)['tst'].should == ['Medina, Texas, 1939.']
|
213
213
|
end
|
214
214
|
|
215
215
|
it "can get a single subfield" do
|
@@ -220,7 +220,7 @@ describe "DSL" do
|
|
220
220
|
}
|
221
221
|
end
|
222
222
|
end
|
223
|
-
ss.hash_from_marc(@one)['tst'].should
|
223
|
+
ss.hash_from_marc(@one)['tst'].should == ['Medina, Texas,']
|
224
224
|
end
|
225
225
|
|
226
226
|
|
@@ -232,7 +232,7 @@ describe "DSL" do
|
|
232
232
|
}
|
233
233
|
end
|
234
234
|
end
|
235
|
-
ss.hash_from_marc(@one)['tst'].should
|
235
|
+
ss.hash_from_marc(@one)['tst'].should == ['The Texas ranger Sung by Beale D. Taylor.']
|
236
236
|
end
|
237
237
|
|
238
238
|
it "can get multiple subfields as array" do
|
@@ -243,7 +243,7 @@ describe "DSL" do
|
|
243
243
|
}
|
244
244
|
end
|
245
245
|
end
|
246
|
-
ss.hash_from_marc(@one)['tst'].should
|
246
|
+
ss.hash_from_marc(@one)['tst'].should == ['The Texas ranger Sung by Beale D. Taylor.']
|
247
247
|
end
|
248
248
|
|
249
249
|
it "can get multiple different subfields from the same field" do
|
@@ -255,7 +255,7 @@ describe "DSL" do
|
|
255
255
|
}
|
256
256
|
end
|
257
257
|
end
|
258
|
-
ss.hash_from_marc(@one)['tst'].should
|
258
|
+
ss.hash_from_marc(@one)['tst'].should == ['The Texas ranger', 'Sung by Beale D. Taylor.']
|
259
259
|
end
|
260
260
|
|
261
261
|
it "can handle multiple specs" do
|
@@ -269,8 +269,30 @@ describe "DSL" do
|
|
269
269
|
}
|
270
270
|
end
|
271
271
|
end
|
272
|
-
ss.hash_from_marc(@one)['tst'].should
|
272
|
+
ss.hash_from_marc(@one)['tst'].should == ['The Texas ranger', 'Sung by Beale D. Taylor.']
|
273
|
+
end
|
274
|
+
|
275
|
+
it "can get tag/subs in the spec string" do
|
276
|
+
ss = MARCSpec.build do
|
277
|
+
field("tst") do
|
278
|
+
spec('245ac')
|
279
|
+
end
|
280
|
+
end
|
281
|
+
ss.hash_from_marc(@one)['tst'].should == ['The Texas ranger Sung by Beale D. Taylor.']
|
282
|
+
end
|
283
|
+
|
284
|
+
it "can get tag/subs in the spec string AND with a 'sub'" do
|
285
|
+
ss = MARCSpec.build do
|
286
|
+
field("tst") do
|
287
|
+
spec('245a') {
|
288
|
+
sub 'c'
|
289
|
+
}
|
290
|
+
end
|
291
|
+
end
|
292
|
+
ss.hash_from_marc(@one)['tst'].should == ['The Texas ranger', 'Sung by Beale D. Taylor.']
|
273
293
|
end
|
294
|
+
|
295
|
+
|
274
296
|
end
|
275
297
|
|
276
298
|
describe "SolrFieldSpec modifiers DSL" do
|
@@ -285,7 +307,7 @@ describe "DSL" do
|
|
285
307
|
end
|
286
308
|
end
|
287
309
|
|
288
|
-
ss.hash_from_marc(@one)['tst'].should
|
310
|
+
ss.hash_from_marc(@one)['tst'].should == ['Lomax, John Avery, 1867-1948']
|
289
311
|
end
|
290
312
|
|
291
313
|
it "works with default" do
|
@@ -299,7 +321,7 @@ describe "DSL" do
|
|
299
321
|
end
|
300
322
|
end
|
301
323
|
|
302
|
-
ss.hash_from_marc(@one)['tst'].should
|
324
|
+
ss.hash_from_marc(@one)['tst'].should == ['Default value']
|
303
325
|
end
|
304
326
|
end
|
305
327
|
|
@@ -320,8 +342,8 @@ describe "DSL" do
|
|
320
342
|
|
321
343
|
ss = MARCSpec::SpecSet.new
|
322
344
|
ss.instance_eval(string)
|
323
|
-
ss.hash_from_marc(@one)['tst'].should
|
324
|
-
ss.hash_from_marc(@one)['id'].should
|
345
|
+
ss.hash_from_marc(@one)['tst'].should == ['Default']
|
346
|
+
ss.hash_from_marc(@one)['id'].should == ['c9999']
|
325
347
|
end
|
326
348
|
|
327
349
|
it "works in compact form" do
|
@@ -338,8 +360,8 @@ describe "DSL" do
|
|
338
360
|
|
339
361
|
ss = MARCSpec::SpecSet.new
|
340
362
|
ss.instance_eval(string)
|
341
|
-
ss.hash_from_marc(@one)['tst'].should
|
342
|
-
ss.hash_from_marc(@one)['id'].should
|
363
|
+
ss.hash_from_marc(@one)['tst'].should == ['Default']
|
364
|
+
ss.hash_from_marc(@one)['id'].should == ['c9999']
|
343
365
|
end
|
344
366
|
|
345
367
|
it "bails on a missing map" do
|
@@ -359,7 +381,7 @@ describe "DSL" do
|
|
359
381
|
path = f.path
|
360
382
|
f.close
|
361
383
|
ss = MARCSpec::SpecSet.new
|
362
|
-
lambda{ss.buildSpecsFromDSLFile(path)}.should
|
384
|
+
lambda{ss.buildSpecsFromDSLFile(path)}.should raise_error(SystemExit)
|
363
385
|
f.unlink
|
364
386
|
|
365
387
|
end
|
data/spec/leaderspec_spec.rb
CHANGED
@@ -25,11 +25,11 @@ describe "LeaderSpec" do
|
|
25
25
|
|
26
26
|
it "Works with full leader" do
|
27
27
|
cfs = MARCSpec::LeaderSpec.new('LDR')
|
28
|
-
cfs.marc_values(@one).should
|
28
|
+
cfs.marc_values(@one).should == @one.leader
|
29
29
|
end
|
30
30
|
|
31
31
|
it "Works with substring of leader" do
|
32
32
|
cfs = MARCSpec::LeaderSpec.new('LDR', 3..5)
|
33
|
-
cfs.marc_values(@one).should
|
33
|
+
cfs.marc_values(@one).should == @one.leader[3..5]
|
34
34
|
end
|
35
35
|
end
|
data/spec/maps_spec.rb
CHANGED
@@ -6,53 +6,53 @@ describe "KV Maps" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it "knows its name" do
|
9
|
-
@kvmap.mapname.should
|
9
|
+
@kvmap.mapname.should == 'kvmap'
|
10
10
|
end
|
11
11
|
|
12
12
|
it "gets simple value from a kv map" do
|
13
|
-
@kvmap['one'].should
|
13
|
+
@kvmap['one'].should == '1'
|
14
14
|
end
|
15
15
|
|
16
16
|
it "gets a list value from a kv map" do
|
17
|
-
@kvmap['two'].should
|
17
|
+
@kvmap['two'].should == ['2', 'zwei']
|
18
18
|
end
|
19
19
|
|
20
20
|
it "gets nothing on nonmatches for kvmap" do
|
21
|
-
@kvmap['ddd'].should
|
21
|
+
@kvmap['ddd'].should == nil
|
22
22
|
end
|
23
23
|
|
24
24
|
it "gets default if set for nonmatches with KVMap" do
|
25
|
-
@kvmap['ddd', 'default'].should
|
25
|
+
@kvmap['ddd', 'default'].should == 'default'
|
26
26
|
end
|
27
27
|
|
28
28
|
it "gets key if default is :passthrough for nonmatches with KVMap" do
|
29
|
-
@kvmap['ddd', :passthrough].should
|
29
|
+
@kvmap['ddd', :passthrough].should == 'ddd'
|
30
30
|
end
|
31
31
|
|
32
32
|
|
33
33
|
it "correctly uses default value" do
|
34
|
-
@kvmap['ddd', 'default'].should
|
35
|
-
@kvmap['one', 'default'].should
|
34
|
+
@kvmap['ddd', 'default'].should == 'default'
|
35
|
+
@kvmap['one', 'default'].should == '1'
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should round-trip a kvmap" do
|
39
39
|
s = @kvmap.asPPString
|
40
40
|
newkvmap = MARCSpec::KVMap.fromPPString s
|
41
|
-
newkvmap.should
|
41
|
+
newkvmap.should == @kvmap
|
42
42
|
end
|
43
43
|
|
44
44
|
|
45
45
|
it "should read a kv solrmarc file" do
|
46
46
|
map = MARCSpec::KVMap.from_solrmarc_file "#{DIR}/data/umich/translation_maps/country_map.properties"
|
47
|
-
map.mapname.should
|
48
|
-
map["nl"].should
|
47
|
+
map.mapname.should == 'country_map'
|
48
|
+
map["nl"].should == "New Caledonia"
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should correctly deal with solrmarc files with escaped chars (via \\)" do
|
52
52
|
map = MARCSpec::KVMap.from_solrmarc_file "#{DIR}/data/umich/translation_maps/location_map.properties"
|
53
|
-
map['AAEL'].should
|
54
|
-
map['AAEL MICE'].should
|
55
|
-
map['BUHR AAEL'].should
|
53
|
+
map['AAEL'].should == 'AAEL'
|
54
|
+
map['AAEL MICE'].should == 'AAEL MICE'
|
55
|
+
map['BUHR AAEL'].should == 'BUHR'
|
56
56
|
end
|
57
57
|
|
58
58
|
|
@@ -64,13 +64,13 @@ describe "KV Maps" do
|
|
64
64
|
f.close
|
65
65
|
map2 = MARCSpec::Map.fromFile(path)
|
66
66
|
f.unlink
|
67
|
-
map.class.should
|
68
|
-
map.should
|
67
|
+
map.class.should == MARCSpec::KVMap
|
68
|
+
map.should == map2
|
69
69
|
end
|
70
70
|
|
71
71
|
it "can name a map based on the filename when using fromFile(path)" do
|
72
72
|
map = MARCSpec::Map.fromFile("#{DIR}/data/simplemap.rb")
|
73
|
-
map.mapname.should
|
73
|
+
map.mapname.should == 'simplemap'
|
74
74
|
end
|
75
75
|
|
76
76
|
end
|
@@ -94,33 +94,33 @@ describe "MVMaps" do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
it "knows its name" do
|
97
|
-
@mvmap.mapname.should
|
97
|
+
@mvmap.mapname.should == 'mvmap'
|
98
98
|
end
|
99
99
|
|
100
100
|
it "gets nothing on nonmatches for mvmap" do
|
101
|
-
@mvmap['ddd'].should
|
101
|
+
@mvmap['ddd'].should == nil
|
102
102
|
end
|
103
103
|
|
104
104
|
it "gets default if set for nonmatches with MVMap" do
|
105
|
-
@mvmap['ddd', 'default'].should
|
105
|
+
@mvmap['ddd', 'default'].should == 'default'
|
106
106
|
end
|
107
107
|
|
108
108
|
|
109
109
|
it "gets key if default is :passthrough for nonmatches with KVMap" do
|
110
|
-
@mvmap['ddd', :passthrough].should
|
110
|
+
@mvmap['ddd', :passthrough].should == 'ddd'
|
111
111
|
end
|
112
112
|
|
113
113
|
|
114
114
|
it "gets correct values from multivaluemap" do
|
115
|
-
@mvmap['bi'].should
|
116
|
-
@mvmap['bill'].should
|
117
|
-
@mvmap['mobi'].sort.should
|
118
|
-
@mvmap['Molly'].sort.should
|
115
|
+
@mvmap['bi'].should == ['Bill']
|
116
|
+
@mvmap['bill'].should == ['Bill']
|
117
|
+
@mvmap['mobi'].sort.should == ['Bill', 'Molly'].sort
|
118
|
+
@mvmap['Molly'].sort.should == ['Molly', 'Bill', 'One', 'Two'].sort
|
119
119
|
end
|
120
120
|
|
121
121
|
it "correctly uses default value" do
|
122
|
-
@mvmap['bi', 'default'].should
|
123
|
-
@mvmap['ddd', 'default'].should
|
122
|
+
@mvmap['bi', 'default'].should == ['Bill']
|
123
|
+
@mvmap['ddd', 'default'].should == 'default'
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should round trip a multivaluemap without a Proc" do
|
@@ -131,31 +131,31 @@ describe "MVMaps" do
|
|
131
131
|
@mvmap.map = cleanmap
|
132
132
|
s = @mvmap.asPPString
|
133
133
|
newmvmap = MARCSpec::MultiValueMap.fromPPString s
|
134
|
-
newmvmap.should
|
134
|
+
newmvmap.should == @mvmap
|
135
135
|
end
|
136
136
|
|
137
137
|
it "can't round-trip a multivaluemap with a Proc" do
|
138
138
|
s = @mvmap.asPPString
|
139
139
|
newmvmap = MARCSpec::MultiValueMap.fromPPString s
|
140
|
-
newmvmap.
|
140
|
+
newmvmap.should_not == @mvmap
|
141
141
|
end
|
142
142
|
|
143
143
|
|
144
144
|
it "can use a proc in a multivaluemap" do
|
145
|
-
@mvmap['Molly Dueber'].sort.should
|
145
|
+
@mvmap['Molly Dueber'].sort.should == ['Molly', 'Bill', 'Dueber', 'One', 'Two'].sort
|
146
146
|
end
|
147
147
|
|
148
148
|
it "can use a simple passthrough in a multivaluemap" do
|
149
149
|
@mvmap = MARCSpec::MultiValueMap.new('mvmap', [[/.*/, Proc.new {|m| m[0]}]])
|
150
|
-
@mvmap['one'].should
|
151
|
-
@mvmap['two'].should
|
150
|
+
@mvmap['one'].should == ['one']
|
151
|
+
@mvmap['two'].should == ['two']
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should read a pattern solrmarc file" do
|
155
155
|
map = MARCSpec::MultiValueMap.from_solrmarc_file "#{DIR}/data/umich/translation_maps/library_map.properties"
|
156
|
-
map.mapname.should
|
157
|
-
map['UMTRI Stuff'].should
|
158
|
-
map['HATCH DOCS'].should
|
156
|
+
map.mapname.should == 'library_map'
|
157
|
+
map['UMTRI Stuff'].should == ['Transportation Research Institute Library (UMTRI)']
|
158
|
+
map['HATCH DOCS'].should == ['Hatcher Graduate', 'Hatcher Graduate Documents Center']
|
159
159
|
end
|
160
160
|
|
161
161
|
it "can dump/load a multivalue map via generic map interface" do
|
@@ -166,16 +166,16 @@ describe "MVMaps" do
|
|
166
166
|
f.close
|
167
167
|
map2 = MARCSpec::Map.fromFile(path)
|
168
168
|
f.unlink
|
169
|
-
map.class.should
|
170
|
-
map.should
|
169
|
+
map.class.should == MARCSpec::MultiValueMap
|
170
|
+
map.should == map2
|
171
171
|
end
|
172
172
|
|
173
173
|
it "collapses ok" do
|
174
|
-
@mvmapCollapse['bill'].should
|
175
|
-
@mvmapCollapse['william'].should
|
176
|
-
@mvmapCollapse['bill dueber'].sort.should
|
177
|
-
@mvmapCollapse['Will "duebes" Dueber'].sort.should
|
178
|
-
@mvmapCollapse['notinthere'].should
|
174
|
+
@mvmapCollapse['bill'].should == ['William']
|
175
|
+
@mvmapCollapse['william'].should == ['William']
|
176
|
+
@mvmapCollapse['bill dueber'].sort.should == ['William', 'Dueber'].sort
|
177
|
+
@mvmapCollapse['Will "duebes" Dueber'].sort.should == ['William', 'Dueber'].sort
|
178
|
+
@mvmapCollapse['notinthere'].should == nil
|
179
179
|
end
|
180
180
|
|
181
181
|
|
data/spec/marcfieldspecs_spec.rb
CHANGED
@@ -29,29 +29,29 @@ describe "ControlFieldSpec" do
|
|
29
29
|
# 01234567890123 # index
|
30
30
|
it "gets a single full value" do
|
31
31
|
cfs = MARCSpec::ControlFieldSpec.new('001')
|
32
|
-
cfs.marc_values(@one).should
|
32
|
+
cfs.marc_values(@one).should == ["afc99990058366"]
|
33
33
|
end
|
34
34
|
|
35
35
|
it "gets a single character" do
|
36
36
|
cfs = MARCSpec::ControlFieldSpec.new('001', 10 )
|
37
|
-
cfs.marc_values(@one).should
|
37
|
+
cfs.marc_values(@one).should == ['8']
|
38
38
|
end
|
39
39
|
|
40
40
|
it "gets a range of characters" do
|
41
41
|
cfs = MARCSpec::ControlFieldSpec.new('001', 6..10 )
|
42
|
-
cfs.marc_values(@one).should
|
42
|
+
cfs.marc_values(@one).should == ['90058']
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should round trip" do
|
46
46
|
cfs = MARCSpec::ControlFieldSpec.new('001', 6..10 )
|
47
47
|
cfs2 = MARCSpec::ControlFieldSpec.fromPPString(cfs.asPPString)
|
48
|
-
cfs.should
|
48
|
+
cfs.should == cfs2
|
49
49
|
end
|
50
50
|
|
51
51
|
it "throws an error if you try to use a datafield tag" do
|
52
52
|
lambda{
|
53
53
|
cfs = MARCSpec::ControlFieldSpec.new('010', 6..10 )
|
54
|
-
}.should
|
54
|
+
}.should raise_error(ArgumentError)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "accepts various forms for the range" do
|
@@ -62,22 +62,22 @@ describe "ControlFieldSpec" do
|
|
62
62
|
# Range 4-7 is 9999
|
63
63
|
cfs1.range = 4
|
64
64
|
cfs2.range = 4..4
|
65
|
-
cfs1.marc_values(@one).should
|
66
|
-
cfs2.marc_values(@one).should
|
65
|
+
cfs1.marc_values(@one).should == ['9']
|
66
|
+
cfs2.marc_values(@one).should == ['9']
|
67
67
|
end
|
68
68
|
|
69
69
|
it "rejects bad ranges" do
|
70
70
|
lambda{
|
71
71
|
cfs = MARCSpec::ControlFieldSpec.new('010', -1)
|
72
|
-
}.should
|
72
|
+
}.should raise_error(ArgumentError)
|
73
73
|
|
74
74
|
lambda{
|
75
75
|
cfs = MARCSpec::ControlFieldSpec.new('010', -1..3)
|
76
|
-
}.should
|
76
|
+
}.should raise_error(ArgumentError)
|
77
77
|
|
78
78
|
lambda{
|
79
79
|
cfs = MARCSpec::ControlFieldSpec.new('010', [1,2,3])
|
80
|
-
}.should
|
80
|
+
}.should raise_error(ArgumentError)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -90,17 +90,17 @@ describe "LeaderSpec" do
|
|
90
90
|
it "must use LDR as the tag" do
|
91
91
|
lambda{
|
92
92
|
cfs = MARCSpec::LeaderSpec.new('008')
|
93
|
-
}.should
|
93
|
+
}.should raise_error(ArgumentError)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "Works with full leader" do
|
97
97
|
cfs = MARCSpec::LeaderSpec.new('LDR')
|
98
|
-
cfs.marc_values(@one).should
|
98
|
+
cfs.marc_values(@one).should == @one.leader
|
99
99
|
end
|
100
100
|
|
101
101
|
it "Works with substring of leader" do
|
102
102
|
cfs = MARCSpec::LeaderSpec.new('LDR', 3..5)
|
103
|
-
cfs.marc_values(@one).should
|
103
|
+
cfs.marc_values(@one).should == @one.leader[3..5]
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -114,39 +114,39 @@ describe "VariableFieldSpec" do
|
|
114
114
|
|
115
115
|
it "Should get a whole field separated by spaces" do
|
116
116
|
dfs = MARCSpec::VariableFieldSpec.new('260')
|
117
|
-
dfs.marc_values(@one).should
|
117
|
+
dfs.marc_values(@one).should == ["Medina, Texas, 1939."]
|
118
118
|
end
|
119
119
|
|
120
120
|
it "Should get just the $a" do
|
121
121
|
dfs = MARCSpec::VariableFieldSpec.new('260', 'a')
|
122
|
-
dfs.marc_values(@one).should
|
122
|
+
dfs.marc_values(@one).should == ["Medina, Texas,"]
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should return separate values for repeated subfields if only one code is specified" do
|
126
126
|
dfs = MARCSpec::VariableFieldSpec.new('651', 'z')
|
127
|
-
dfs.marc_values(@one).sort.should
|
127
|
+
dfs.marc_values(@one).sort.should == ['Texas', 'United States of America.']
|
128
128
|
end
|
129
129
|
|
130
|
-
it "Should get all fields via several
|
130
|
+
it "Should get all fields via several == routes" do
|
131
131
|
a = MARCSpec::VariableFieldSpec.new('260').marc_values(@one)
|
132
132
|
ac = MARCSpec::VariableFieldSpec.new('260', ['a', 'c']).marc_values(@one)
|
133
133
|
ca = MARCSpec::VariableFieldSpec.new('260', ['c', 'a']).marc_values(@one)
|
134
134
|
ca2 = MARCSpec::VariableFieldSpec.new('260', 'ca').marc_values(@one)
|
135
135
|
allrange = MARCSpec::VariableFieldSpec.new('260', 'a'..'z').marc_values(@one)
|
136
|
-
a.should
|
137
|
-
ac.should
|
138
|
-
ca.should
|
136
|
+
a.should == ac
|
137
|
+
ac.should == ca
|
138
|
+
ca.should == allrange
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should get all three 700a's" do
|
142
142
|
a = MARCSpec::VariableFieldSpec.new('700', 'a').marc_values(@one)
|
143
|
-
a.should
|
143
|
+
a.should == ["Lomax, John Avery, 1867-1948", "Lomax, Ruby T. (Ruby Terrill)", "Taylor, Beale D."]
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should round trip" do
|
147
147
|
ac = MARCSpec::VariableFieldSpec.new('260', ['a', 'c'])
|
148
148
|
ac2 = MARCSpec::VariableFieldSpec.fromPPString(ac.asPPString)
|
149
|
-
ac.should
|
149
|
+
ac.should == ac2
|
150
150
|
end
|
151
151
|
|
152
152
|
end
|