rdf-rdfxml 0.3.2.1 → 0.3.3

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/writer_spec.rb CHANGED
@@ -14,368 +14,576 @@ describe "RDF::RDFXML::Writer" do
14
14
  it_should_behave_like RDF_Writer
15
15
 
16
16
  describe "#buffer" do
17
- describe "with types" do
18
- it "should serialize resource without type" do
19
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
20
- check_xpaths(
21
- serialize(:max_depth => 1, :attributes => :untyped),
17
+ context "typed resources" do
18
+ context "resource without type" do
19
+ subject do
20
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
21
+ serialize(:max_depth => 1, :attributes => :untyped)
22
+ end
23
+
24
+ {
22
25
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
23
26
  "/rdf:RDF/rdf:Description/@dc:title" => "foo"
24
- )
27
+ }.each do |path, value|
28
+ it "returns #{value.inspect} for xpath #{path}" do
29
+ subject.should have_xpath(path, value)
30
+ end
31
+ end
25
32
  end
26
33
 
27
- it "should serialize resource with type" do
28
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
29
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
30
- check_xpaths(
31
- serialize(:max_depth => 1, :attributes => :untyped),
34
+ context "resource with type" do
35
+ subject do
36
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
37
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
38
+ serialize(:max_depth => 1, :attributes => :untyped)
39
+ end
40
+
41
+ {
32
42
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
33
43
  "/rdf:RDF/foo:Release/@dc:title" =>"foo",
34
44
  "/rdf:RDF/foo:Release/rdf:type" => ""
35
- )
45
+ }.each do |path, value|
46
+ it "returns #{value.inspect} for xpath #{path}" do
47
+ subject.should have_xpath(path, value)
48
+ end
49
+ end
36
50
  end
37
51
 
38
- it "should serialize resource with two types as attribute" do
39
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
40
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
41
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
42
- check_xpaths(
43
- serialize(:max_depth => 1, :attributes => :untyped),
52
+ context "resource with two types as attribute" do
53
+ subject do
54
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
55
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
56
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
57
+ serialize(:max_depth => 1, :attributes => :untyped)
58
+ end
59
+
60
+ {
44
61
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
45
62
  "/rdf:RDF/foo:Release/@dc:title" => "foo",
46
63
  "/rdf:RDF/foo:Release/@rdf:type" => FOO.XtraRelease.to_s
47
- )
64
+ }.each do |path, value|
65
+ it "returns #{value.inspect} for xpath #{path}" do
66
+ subject.should have_xpath(path, value)
67
+ end
68
+ end
48
69
  end
49
70
 
50
- it "should serialize resource with two types as element" do
51
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
52
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
53
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
54
- check_xpaths(
55
- serialize(:max_depth => 1, :attributes => :none),
71
+ context "resource with two types as element" do
72
+ subject do
73
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
74
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
75
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
76
+ serialize(:max_depth => 1, :attributes => :none)
77
+ end
78
+
79
+ {
56
80
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
57
- "/rdf:RDF/foo:Release/dc:title" => true,
58
- %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
81
+ "/rdf:RDF/foo:Release/dc:title/text()" => "foo",
82
+ %(/rdf:RDF/foo:Release/rdf:type/@rdf:resource) => FOO.XtraRelease.to_s,
59
83
  %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.Release}"]) => false
60
- )
84
+ }.each do |path, value|
85
+ it "returns #{value.inspect} for xpath #{path}" do
86
+ subject.should have_xpath(path, value)
87
+ end
88
+ end
61
89
  end
62
90
 
63
- it "should serialize resource with three types as element" do
64
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
65
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
66
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XXtraRelease]
67
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
68
- check_xpaths(
69
- serialize(:max_depth => 1, :attributes => :typed),
91
+ context "resource with three types as element" do
92
+ subject do
93
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
94
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XtraRelease]
95
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.XXtraRelease]
96
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
97
+ serialize(:max_depth => 1, :attributes => :typed)
98
+ end
99
+
100
+ {
70
101
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
71
- "/rdf:RDF/foo:Release/@dc:title" => true,
72
- %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => true,
73
- %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) => true
74
- )
102
+ "/rdf:RDF/foo:Release/@dc:title" => "foo",
103
+ %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XtraRelease}"]) => %r(#{FOO.XtraRelease}),
104
+ %(/rdf:RDF/foo:Release/rdf:type[@rdf:resource="#{FOO.XXtraRelease}"]) => %r(#{FOO.XXtraRelease})
105
+ }.each do |path, value|
106
+ it "returns #{value.inspect} for xpath #{path}" do
107
+ subject.should have_xpath(path, value)
108
+ end
109
+ end
75
110
  end
76
111
  end
77
112
 
78
- describe "with children" do
79
- it "should serialize referenced resource by ref" do
80
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
81
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
82
- @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
83
- @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
84
- @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
85
- check_xpaths(
86
- serialize(:max_depth => 1, :attributes => :untyped),
113
+ context "with children" do
114
+ context "referenced resource by ref" do
115
+ subject do
116
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
117
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
118
+ @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
119
+ @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
120
+ @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
121
+ serialize(:max_depth => 1, :attributes => :untyped)
122
+ end
123
+
124
+ {
87
125
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
88
126
  "/rdf:RDF/foo:Release/@dc:title" => "foo",
89
127
  "/rdf:RDF/foo:Release/foo:releaseContributor/@rdf:resource" => "http://release/contributor",
90
128
  "/rdf:RDF/foo:Contributor/@rdf:about" => "http://release/contributor",
91
129
  "/rdf:RDF/foo:Contributor/@dc:title" => "bar"
92
- )
130
+ }.each do |path, value|
131
+ it "returns #{value.inspect} for xpath #{path}" do
132
+ subject.should have_xpath(path, value)
133
+ end
134
+ end
93
135
  end
94
136
 
95
- it "should serialize referenced resource by inclusion" do
96
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
97
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
98
- @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
99
- @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
100
- @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
101
- check_xpaths(
102
- serialize(:max_depth => 3, :attributes => :untyped),
137
+ context "referenced resource by inclusion" do
138
+ subject do
139
+ @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
140
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
141
+ @graph << [RDF::URI.new("http://release/contributor"), RDF.type, FOO.Contributor]
142
+ @graph << [RDF::URI.new("http://release/contributor"), RDF::DC.title, "bar"]
143
+ @graph << [RDF::URI.new("http://release/"), FOO.releaseContributor, RDF::URI.new("http://release/contributor")]
144
+ serialize(:max_depth => 3, :attributes => :untyped)
145
+ end
146
+
147
+ {
103
148
  "/rdf:RDF/foo:Release/@rdf:about" => "http://release/",
104
149
  "/rdf:RDF/foo:Release/@dc:title" => "foo",
105
150
  "/rdf:RDF/foo:Release/foo:releaseContributor/foo:Contributor/@rdf:about" => "http://release/contributor"
106
- )
151
+ }.each do |path, value|
152
+ it "returns #{value.inspect} for xpath #{path}" do
153
+ subject.should have_xpath(path, value)
154
+ end
155
+ end
107
156
  end
108
157
  end
109
158
 
110
- describe "with sequences" do
111
- it "should serialize rdf:Seq with rdf:_n" do
112
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
113
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
114
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
115
- check_xpaths(
116
- serialize(:max_depth => 1, :attributes => :none),
159
+ context "with sequences" do
160
+ context "rdf:Seq with rdf:_n" do
161
+ subject do
162
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
163
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
164
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
165
+ serialize(:max_depth => 1, :attributes => :none)
166
+ end
167
+
168
+ {
117
169
  "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
118
- %(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => true,
119
- %(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => true
120
- )
170
+ %(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
171
+ %(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => /second/
172
+ }.each do |path, value|
173
+ it "returns #{value.inspect} for xpath #{path}" do
174
+ subject.should have_xpath(path, value)
175
+ end
176
+ end
121
177
  end
122
178
 
123
- it "should serialize rdf:Seq with rdf:_n in proper sequence" do
124
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
125
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
126
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
127
- check_xpaths(
128
- serialize(:max_depth => 1, :attributes => :none),
179
+ context "rdf:Seq with rdf:_n in proper sequence" do
180
+ subject do
181
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
182
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
183
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
184
+ serialize(:max_depth => 1, :attributes => :none)
185
+ end
186
+
187
+ {
129
188
  "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
130
- %(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => true,
131
- %(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => true
132
- )
189
+ %(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
190
+ %(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => /secon/
191
+ }.each do |path, value|
192
+ it "returns #{value.inspect} for xpath #{path}" do
193
+ subject.should have_xpath(path, value)
194
+ end
195
+ end
133
196
  end
134
197
 
135
- it "should serialize rdf:Bag with rdf:_n" do
136
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Bag]
137
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
138
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
139
- check_xpaths(
140
- serialize(:max_depth => 1, :attributes => :none),
198
+ context "rdf:Bag with rdf:_n" do
199
+ subject do
200
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Bag]
201
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
202
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
203
+ serialize(:max_depth => 1, :attributes => :none)
204
+ end
205
+
206
+ {
141
207
  "/rdf:RDF/rdf:Bag/@rdf:about" => "http://example/seq",
142
- %(/rdf:RDF/rdf:Bag/rdf:_1[@rdf:resource="http://example/first"]) => true,
143
- %(/rdf:RDF/rdf:Bag/rdf:_2[@rdf:resource="http://example/second"]) => true
144
- )
208
+ %(/rdf:RDF/rdf:Bag/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
209
+ %(/rdf:RDF/rdf:Bag/rdf:_2[@rdf:resource="http://example/second"]) => /secon/
210
+ }.each do |path, value|
211
+ it "returns #{value.inspect} for xpath #{path}" do
212
+ subject.should have_xpath(path, value)
213
+ end
214
+ end
145
215
  end
146
216
 
147
- it "should serialize rdf:Alt with rdf:_n" do
148
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Alt]
149
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
150
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
151
- check_xpaths(
152
- serialize(:max_depth => 1, :attributes => :none),
217
+ context "rdf:Alt with rdf:_n" do
218
+ subject do
219
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Alt]
220
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
221
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
222
+ serialize(:max_depth => 1, :attributes => :none)
223
+ end
224
+
225
+ {
153
226
  "/rdf:RDF/rdf:Alt/@rdf:about" => "http://example/seq",
154
- %(/rdf:RDF/rdf:Alt/rdf:_1[@rdf:resource="http://example/first"]) => true,
155
- %(/rdf:RDF/rdf:Alt/rdf:_2[@rdf:resource="http://example/second"]) => true
156
- )
227
+ %(/rdf:RDF/rdf:Alt/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
228
+ %(/rdf:RDF/rdf:Alt/rdf:_2[@rdf:resource="http://example/second"]) => /secon/
229
+ }.each do |path, value|
230
+ it "returns #{value.inspect} for xpath #{path}" do
231
+ subject.should have_xpath(path, value)
232
+ end
233
+ end
157
234
  end
158
235
  end
159
236
 
160
237
  describe "with lists" do
161
- it "should serialize List rdf:first/rdf:rest" do
162
- @graph = parse(%(
163
- @prefix foo: <http://foo/> . foo:author foo:is (:Gregg :Barnum :Kellogg) .
164
- ), :base_uri => "http://foo/", :reader => RDF::N3::Reader)
165
- check_xpaths(
166
- serialize({}),
238
+ context "List rdf:first/rdf:rest" do
239
+ subject do
240
+ @graph = parse(%(
241
+ @prefix foo: <http://foo/> . foo:author foo:is (:Gregg :Barnum :Kellogg) .
242
+ ), :base_uri => "http://foo/", :reader => RDF::N3::Reader)
243
+ serialize({})
244
+ end
245
+
246
+ {
167
247
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://foo/author",
168
248
  "/rdf:RDF/rdf:Description/foo:is/@rdf:parseType" => "Collection",
169
- %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => true,
170
- %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => true,
171
- %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => true,
249
+ %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Gregg"]) => /Gregg/,
250
+ %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Barnum"]) => /Barnum/,
251
+ %(/rdf:RDF/rdf:Description/foo:is/rdf:Description[@rdf:about="http://foo/#Kellogg"]) => /Kellogg/,
172
252
  %(//rdf:first) => false
173
- )
253
+ }.each do |path, value|
254
+ it "returns #{value.inspect} for xpath #{path}" do
255
+ subject.should have_xpath(path, value)
256
+ end
257
+ end
174
258
  end
175
259
 
176
- it "should serialize resource with rdf:_n in proper sequence" do
177
- @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
178
- @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
179
- @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
180
- check_xpaths(
181
- serialize(:max_depth => 1, :attributes => :none),
260
+ context "resource with rdf:_n in proper sequence" do
261
+ subject do
262
+ @graph << [RDF::URI.new("http://example/seq"), RDF.type, RDF.Seq]
263
+ @graph << [RDF::URI.new("http://example/seq"), RDF._2, RDF::URI.new("http://example/second")]
264
+ @graph << [RDF::URI.new("http://example/seq"), RDF._1, RDF::URI.new("http://example/first")]
265
+ serialize(:max_depth => 1, :attributes => :none)
266
+ end
267
+
268
+ {
182
269
  "/rdf:RDF/rdf:Seq/@rdf:about" => "http://example/seq",
183
- %(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => true,
184
- %(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => true
185
- )
270
+ %(/rdf:RDF/rdf:Seq/rdf:_1[@rdf:resource="http://example/first"]) => /first/,
271
+ %(/rdf:RDF/rdf:Seq/rdf:_2[@rdf:resource="http://example/second"]) => /second/
272
+ }.each do |path, value|
273
+ it "returns #{value.inspect} for xpath #{path}" do
274
+ subject.should have_xpath(path, value)
275
+ end
276
+ end
186
277
  end
187
278
  end
188
279
 
189
- describe "with untyped literals" do
190
- it "should seralize as element if :attributes == :none" do
191
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
192
- check_xpaths(
193
- serialize(:attributes => :none),
280
+ context "with untyped literals" do
281
+ context ":attributes == :none" do
282
+ subject do
283
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
284
+ serialize(:attributes => :none)
285
+ end
286
+
287
+ {
194
288
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
195
- "/rdf:RDF/rdf:Description/dc:title" => "<dc:title>foo</dc:title>"
196
- )
289
+ "/rdf:RDF/rdf:Description/dc:title/text()" => "foo"
290
+ }.each do |path, value|
291
+ it "returns #{value.inspect} for xpath #{path}" do
292
+ subject.should have_xpath(path, value)
293
+ end
294
+ end
197
295
  end
198
296
 
199
- it "should seralize as attribute if :attributes == :untyped or :typed" do
200
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
201
- check_xpaths(
202
- serialize(:attributes => :untyped),
203
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
204
- "/rdf:RDF/rdf:Description/@dc:title" => "foo"
205
- )
206
- check_xpaths(
207
- serialize(:attributes => :typed),
208
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
209
- "/rdf:RDF/rdf:Description/@dc:title" => "foo"
210
- )
297
+ [:untyped, :typed].each do |opt|
298
+ context ":attributes == #{opt}" do
299
+ subject do
300
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
301
+ serialize(:attributes => opt)
302
+ end
303
+
304
+ {
305
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
306
+ "/rdf:RDF/rdf:Description/@dc:title" => "foo"
307
+ }.each do |path, value|
308
+ it "returns #{value.inspect} for xpath #{path}" do
309
+ subject.should have_xpath(path, value)
310
+ end
311
+ end
312
+ end
211
313
  end
212
314
 
213
- it "should output untyped without lang if attribute lang set" do
214
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
215
- check_xpaths(
216
- serialize(:attributes => :untyped, :lang => "de"),
315
+ context "untyped without lang if attribute lang set" do
316
+ subject do
317
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
318
+ serialize(:attributes => :untyped, :lang => "de")
319
+ end
320
+
321
+ {
217
322
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
218
323
  "/rdf:RDF/rdf:Description/@dc:title" => "foo"
219
- )
324
+ }.each do |path, value|
325
+ it "returns #{value.inspect} for xpath #{path}" do
326
+ subject.should have_xpath(path, value)
327
+ end
328
+ end
220
329
  end
221
330
 
222
- describe "with language" do
223
- it "should output property for title with language" do
224
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
225
- check_xpaths(
226
- serialize(:attributes => :untyped, :lang => "de"),
331
+ context "with language" do
332
+ context "property for title" do
333
+ subject do
334
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
335
+ serialize(:attributes => :untyped, :lang => "de")
336
+ end
337
+
338
+ {
227
339
  "/rdf:RDF/@xml:lang" => "de",
228
340
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
229
341
  "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="en-us">foo</dc:title>)
230
- )
342
+ }.each do |path, value|
343
+ it "returns #{value.inspect} for xpath #{path}" do
344
+ subject.should have_xpath(path, value)
345
+ end
346
+ end
231
347
  end
232
348
  end
233
349
 
234
- it "should output untyped as attribute if lang is default" do
235
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
236
- check_xpaths(
237
- serialize(:attributes => :untyped, :lang => "de"),
350
+ context "attribute if lang is default" do
351
+ subject do
352
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
353
+ serialize(:attributes => :untyped, :lang => "de")
354
+ end
355
+
356
+ {
238
357
  "/rdf:RDF/@xml:lang" => "de",
239
358
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
240
359
  "/rdf:RDF/rdf:Description/@dc:title" => "foo"
241
- )
360
+ }.each do |path, value|
361
+ it "returns #{value.inspect} for xpath #{path}" do
362
+ subject.should have_xpath(path, value)
363
+ end
364
+ end
242
365
  end
243
366
 
244
- it "should output untyped as property if lang set and no default" do
245
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
246
- check_xpaths(
247
- serialize(:attributes => :untyped),
367
+ context "untyped as property if lang set and no default" do
368
+ subject do
369
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
370
+ serialize(:attributes => :untyped)
371
+ end
372
+
373
+ {
248
374
  "/rdf:RDF/@xml:lang" => false,
249
375
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
250
376
  "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
251
- )
377
+ }.each do |path, value|
378
+ it "returns #{value.inspect} for xpath #{path}" do
379
+ subject.should have_xpath(path, value)
380
+ end
381
+ end
252
382
  end
253
383
 
254
- it "should output untyped as property if lang set and not default" do
255
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
256
- check_xpaths(
257
- serialize(:attributes => :untyped, :lang => "en-us"),
384
+ context "untyped as property if lang set and not default" do
385
+ subject do
386
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
387
+ serialize(:attributes => :untyped, :lang => "en-us")
388
+ end
389
+
390
+ {
258
391
  "/rdf:RDF/@xml:lang" => "en-us",
259
392
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
260
393
  "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
261
- )
394
+ }.each do |path, value|
395
+ it "returns #{value.inspect} for xpath #{path}" do
396
+ subject.should have_xpath(path, value)
397
+ end
398
+ end
262
399
  end
263
400
 
264
- it "should output multiple untyped attributes values through properties" do
265
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
266
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
267
- check_xpaths(
268
- serialize(:attributes => :untyped, :lang => "en-us"),
401
+ context "multiple untyped attributes values through properties" do
402
+ subject do
403
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "de")]
404
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :language => "en-us")]
405
+ serialize(:attributes => :untyped, :lang => "en-us")
406
+ end
407
+
408
+ {
269
409
  "/rdf:RDF/@xml:lang" => "en-us",
270
410
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
271
- "/rdf:RDF/rdf:Description/dc:title[lang('de')]" => %(<dc:title xml:lang="de">foo</dc:title>),
272
- "/rdf:RDF/rdf:Description/dc:title[lang('en-us')]" => %(<dc:title>foo</dc:title>)
273
- )
411
+ "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title xml:lang="de">foo</dc:title>)
412
+ }.each do |path, value|
413
+ it "returns #{value.inspect} for xpath #{path}" do
414
+ subject.should have_xpath(path, value)
415
+ end
416
+ end
274
417
  end
275
418
 
276
- it "should output typed node as attribute" do
277
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
278
- check_xpaths(
279
- serialize(:attributes => :untyped),
419
+ context "typed node as element if :untyped" do
420
+ subject do
421
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
422
+ serialize(:attributes => :untyped)
423
+ end
424
+
425
+ {
280
426
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
281
427
  "/rdf:RDF/rdf:Description/dc:title" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>)
282
- )
283
- check_xpaths(
284
- serialize(:attributes => :typed),
428
+ }.each do |path, value|
429
+ it "returns #{value.inspect} for xpath #{path}" do
430
+ subject.should have_xpath(path, value)
431
+ end
432
+ end
433
+ end
434
+
435
+ context "typed node as attribute if :typed" do
436
+ subject do
437
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
438
+ serialize(:attributes => :typed)
439
+ end
440
+
441
+ {
285
442
  "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
286
443
  "/rdf:RDF/rdf:Description/@dc:title" => "foo",
287
- :reparse => false
288
- )
444
+ }.each do |path, value|
445
+ it "returns #{value.inspect} for xpath #{path}" do
446
+ subject.should have_xpath(path, value)
447
+ end
448
+ end
289
449
  end
290
450
 
291
- it "should output multiple typed values through properties" do
292
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
293
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("bar", :datatype => RDF::XSD.string)]
294
- check_xpaths(
295
- serialize(:attributes => :untyped),
296
- "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
297
- "/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>),
298
- "/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">bar</dc:title>)
299
- )
451
+ context "multiple typed values through properties" do
452
+ subject do
453
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("foo", :datatype => RDF::XSD.string)]
454
+ @graph << [RDF::URI.new("http://release/"), RDF::DC.title, RDF::Literal.new("bar", :datatype => RDF::XSD.string)]
455
+ serialize(:attributes => :untyped)
456
+ end
457
+
458
+ {
459
+ "/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
460
+ "/rdf:RDF/rdf:Description/dc:title[contains(., 'foo')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">foo</dc:title>),
461
+ "/rdf:RDF/rdf:Description/dc:title[contains(., 'bar')]" => %(<dc:title rdf:datatype="#{RDF::XSD.string}">bar</dc:title>)
462
+ }.each do |path, value|
463
+ it "returns #{value.inspect} for xpath #{path}" do
464
+ subject.should have_xpath(path, value)
465
+ end
466
+ end
300
467
  end
301
468
  end
302
469
 
303
- describe "with default namespace" do
304
- it "should serialize with default namespace" do
470
+ context "with namespace" do
471
+ before(:each) do
305
472
  @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
306
473
  @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
307
474
  @graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
308
-
309
- xml = serialize(:max_depth => 1, :attributes => :none,
310
- :default_namespace => FOO.to_s,
311
- :prefixes => {:foo => FOO.to_s})
312
- xml.should =~ /<Release/
313
- xml.should =~ /<pred/
314
- doc = Nokogiri::XML.parse(xml)
315
- doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
316
475
  end
317
476
 
318
- it "should serialize with nil namespace" do
319
- @graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]
320
- @graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
321
- @graph << [RDF::URI.new("http://release/"), FOO.pred, FOO.obj]
322
-
323
- xml = serialize(:max_depth => 1, :attributes => :none,
324
- :prefixes => {nil => FOO.to_s, :foo => FOO.to_s})
325
- xml.should =~ /<Release/
326
- xml.should =~ /<pred/
327
- doc = Nokogiri::XML.parse(xml)
328
- doc.at_xpath("/rdf:RDF/foo:Release/foo:pred/@rdf:resource", doc.namespaces).to_s.should == FOO.obj.to_s
477
+ context "default namespace" do
478
+ subject do
479
+ serialize(:max_depth => 1, :attributes => :none,
480
+ :default_namespace => FOO.to_s,
481
+ :prefixes => {:foo => FOO.to_s})
482
+ end
483
+
484
+ {
485
+ "/rdf:RDF/foo:Release/foo:pred/@rdf:resource" => FOO.obj.to_s,
486
+ }.each do |path, value|
487
+ it "returns #{value.inspect} for xpath #{path}" do
488
+ subject.should have_xpath(path, value, {"foo" => FOO.to_s})
489
+ end
490
+ end
491
+
492
+ specify { subject.should =~ /<Release/ }
493
+ specify { subject.should =~ /<pred/ }
494
+ end
495
+
496
+ context "nil namespace" do
497
+ subject do
498
+ serialize(:max_depth => 1, :attributes => :none,
499
+ :prefixes => {nil => FOO.to_s, :foo => FOO.to_s})
500
+ end
501
+
502
+ {
503
+ "/rdf:RDF/foo:Release/foo:pred/@rdf:resource" => FOO.obj.to_s,
504
+ }.each do |path, value|
505
+ it "returns #{value.inspect} for xpath #{path}" do
506
+ subject.should have_xpath(path, value, {"foo" => FOO.to_s})
507
+ end
508
+ end
509
+
510
+ specify { subject.should =~ /<Release/ }
511
+ specify { subject.should =~ /<pred/ }
329
512
  end
330
513
  end
331
514
 
332
515
  describe "with base" do
333
- it "should generate relative about URI" do
334
- @graph << [RDF::URI.new("http://release/a"), FOO.ref, RDF::URI.new("http://release/b")]
335
- check_xpaths(
336
- serialize(:attributes => :untyped, :base_uri => "http://release/"),
516
+ context "relative about URI" do
517
+ subject do
518
+ @graph << [RDF::URI.new("http://release/a"), FOO.ref, RDF::URI.new("http://release/b")]
519
+ serialize(:attributes => :untyped, :base_uri => "http://release/")
520
+ end
521
+
522
+ {
337
523
  "/rdf:RDF/rdf:Description/@rdf:about" => "a",
338
524
  "/rdf:RDF/rdf:Description/foo:ref/@rdf:resource" => "b"
339
- )
525
+ }.each do |path, value|
526
+ it "returns #{value.inspect} for xpath #{path}" do
527
+ subject.should have_xpath(path, value)
528
+ end
529
+ end
340
530
  end
341
531
  end
342
532
 
343
- describe "with bnodes" do
344
- it "should not generate nodeID attribute unless node is referenced as an object" do
345
- @graph << [RDF::Node.new("a"), RDF::DC.title, "foo"]
346
- check_xpaths(
347
- serialize(:attributes => :untyped, :base => "http://release/"),
533
+ context "with bnodes" do
534
+ context "no nodeID attribute unless node is referenced as an object" do
535
+ subject do
536
+ @graph << [RDF::Node.new("a"), RDF::DC.title, "foo"]
537
+ serialize(:attributes => :untyped, :base_uri => "http://release/")
538
+ end
539
+
540
+ {
348
541
  "/rdf:RDF/rdf:Description/@dc:title" => "foo",
349
542
  "/rdf:RDF/rdf:Description/@rdf:nodeID" => false
350
- )
543
+ }.each do |path, value|
544
+ it "returns #{value.inspect} for xpath #{path}" do
545
+ subject.should have_xpath(path, value)
546
+ end
547
+ end
351
548
  end
352
549
 
353
- it "should generate a nodeID attribute if node is referenced as an object" do
354
- bn = RDF::Node.new("a")
355
- @graph << [bn, RDF::DC.title, "foo"]
356
- @graph << [bn, RDF::OWL.equals, bn]
357
- check_xpaths(
358
- serialize(:attributes => :untyped, :base => "http://release/"),
550
+ context "nodeID attribute if node is referenced as an object" do
551
+ subject do
552
+ bn = RDF::Node.new("a")
553
+ @graph << [bn, RDF::DC.title, "foo"]
554
+ @graph << [bn, RDF::OWL.equals, bn]
555
+ serialize(:attributes => :untyped, :base_uri => "http://release/")
556
+ end
557
+
558
+ {
359
559
  "/rdf:RDF/rdf:Description/@dc:title" => "foo",
360
560
  "/rdf:RDF/rdf:Description/@rdf:nodeID" => /a$/,
361
561
  "/rdf:RDF/rdf:Description/owl:equals/@rdf:nodeID" => /a$/
362
- )
562
+ }.each do |path, value|
563
+ it "returns #{value.inspect} for xpath #{path}" do
564
+ subject.should have_xpath(path, value)
565
+ end
566
+ end
363
567
  end
364
568
 
365
- it "should use rdf::nodeID for forced BNode generation" do
366
- @graph = parse(%(
367
- @prefix : <http://example/> .
368
- _:bar :list (_:foo (_:foo)).
369
- ))
569
+ context "rdf:nodeID for forced BNode generation" do
570
+ subject do
571
+ bn = RDF::Node.new("a")
572
+ @graph = parse(%(
573
+ @prefix : <http://example/> .
574
+ _:bar :list (_:foo (_:foo)).
575
+ ))
576
+ serialize
577
+ end
370
578
 
371
- graph_check = parse(serialize).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
579
+ specify { parse(subject).should be_equivalent_graph(@graph, :trace => @debug.join("\n")) }
372
580
  end
373
581
 
374
582
  it "should replicate rdfcore/rdfms-seq-representation" do
375
583
  @graph = parse(%(
376
584
  <http://example.org/eg#eric> a [ <http://example.org/eg#intersectionOf> (<http://example.org/eg#Person> <http://example.org/eg#Male>)] .
377
585
  ), :reader => RDF::N3::Reader)
378
- graph_check = parse(serialize).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
586
+ parse(serialize).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
379
587
  end
380
588
 
381
589
  it "should not generate extraneous BNode" do
@@ -391,7 +599,7 @@ describe "RDF::RDFXML::Writer" do
391
599
  [ a <http://www.w3.org/2002/07/owl#Class>;
392
600
  <http://www.w3.org/2002/07/owl#intersectionOf> (<a> <b>)] .
393
601
  ), :reader => RDF::N3::Reader)
394
- graph_check = parse(serialize).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
602
+ parse(serialize).should be_equivalent_graph(@graph, :trace => @debug.join("\n"))
395
603
  end
396
604
  end
397
605
 
@@ -467,7 +675,7 @@ describe "RDF::RDFXML::Writer" do
467
675
 
468
676
  require 'rdf/n3'
469
677
  def parse(input, options = {})
470
- reader_class = options.fetch(:reader, detect_format(input))
678
+ reader_class = options.fetch(:reader, RDF::Reader.for(detect_format(input)))
471
679
 
472
680
  graph = RDF::Graph.new
473
681
  reader_class.new(input, options).each do |statement|
@@ -489,14 +697,16 @@ describe "RDF::RDFXML::Writer" do
489
697
  end
490
698
 
491
699
  describe "#get_qname" do
492
- subject { RDF::RDFXML::Writer.new }
493
- describe "with undefined predicate URIs" do
700
+ subject { RDF::RDFXML::Writer.new(StringIO.new, :prefixes => {:foo => "http://foo/"}) }
701
+ context "with undefined predicate URIs" do
494
702
  {
495
- "http://a/b" => [:ns0, :b],
496
- "dc:title" => [:ns0, :title]
703
+ "http://a/b" => "ns0:b",
704
+ "dc:title" => "ns0:title",
705
+ "http://a/%b" => "ns0:b",
706
+ "http://foo/%bar" => "ns0:bar"
497
707
  }.each_pair do |uri, qname|
498
708
  it "returns #{qname.inspect} given #{uri}" do
499
- subject.get_qname(uri).should == qname
709
+ subject.get_qname(RDF::URI(uri)).should == qname
500
710
  end
501
711
  end
502
712
  end