rdf-spec 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rdf/spec.rb +2 -2
- data/lib/rdf/spec/countable.rb +3 -2
- data/lib/rdf/spec/durable.rb +20 -18
- data/lib/rdf/spec/enumerable.rb +337 -314
- data/lib/rdf/spec/format.rb +31 -28
- data/lib/rdf/spec/indexable.rb +19 -16
- data/lib/rdf/spec/inferable.rb +5 -2
- data/lib/rdf/spec/matchers.rb +6 -6
- data/lib/rdf/spec/mutable.rb +110 -107
- data/lib/rdf/spec/queryable.rb +331 -330
- data/lib/rdf/spec/readable.rb +10 -7
- data/lib/rdf/spec/reader.rb +119 -116
- data/lib/rdf/spec/repository.rb +39 -36
- data/lib/rdf/spec/transaction.rb +44 -40
- data/lib/rdf/spec/writable.rb +86 -57
- data/lib/rdf/spec/writer.rb +126 -123
- metadata +4 -6
- data/lib/rdf/spec/query.rb +0 -7
- data/lib/rdf/spec/vocab.rb +0 -7
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.9
|
data/lib/rdf/spec.rb
CHANGED
@@ -24,7 +24,7 @@ module RDF
|
|
24
24
|
# @enumerable = @statements.dup.extend(RDF::Enumerable)
|
25
25
|
# end
|
26
26
|
#
|
27
|
-
#
|
27
|
+
# include RDF_Enumerable
|
28
28
|
# end
|
29
29
|
#
|
30
30
|
# @example Using the shared examples for `RDF::Repository`
|
@@ -35,7 +35,7 @@ module RDF
|
|
35
35
|
# @repository = RDF::Repository.new
|
36
36
|
# end
|
37
37
|
#
|
38
|
-
#
|
38
|
+
# include RDF_Repository
|
39
39
|
# end
|
40
40
|
#
|
41
41
|
# @see http://rubygems.org/gems/rdf
|
data/lib/rdf/spec/countable.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rdf/spec'
|
2
2
|
|
3
|
-
|
3
|
+
module RDF_Countable
|
4
|
+
extend RSpec::SharedContext
|
4
5
|
include RDF::Spec::Matchers
|
5
6
|
|
6
7
|
before :each do
|
@@ -18,7 +19,7 @@ share_as :RDF_Countable do
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
describe
|
22
|
+
describe RDF::Countable do
|
22
23
|
it "responds to #empty?" do
|
23
24
|
@countable.should respond_to(:empty?)
|
24
25
|
end
|
data/lib/rdf/spec/durable.rb
CHANGED
@@ -14,10 +14,11 @@ require 'rdf/spec'
|
|
14
14
|
# File.delete('test.db') if File.exists?('test.db')
|
15
15
|
# end
|
16
16
|
#
|
17
|
-
#
|
17
|
+
# include RDF_Repository
|
18
18
|
# end
|
19
19
|
#end
|
20
|
-
|
20
|
+
module RDF_Durable
|
21
|
+
extend RSpec::SharedContext
|
21
22
|
include RDF::Spec::Matchers
|
22
23
|
|
23
24
|
before :each do
|
@@ -26,25 +27,26 @@ share_as :RDF_Durable do
|
|
26
27
|
@filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
|
27
28
|
end
|
28
29
|
|
30
|
+
describe RDF::Durable do
|
31
|
+
it "should support #durable?" do
|
32
|
+
@load_durable.call.should respond_to(:durable?)
|
33
|
+
[true,false].member?(@load_durable.call.durable?).should be_true
|
34
|
+
end
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
it "should support #nondurable?" do
|
36
|
-
@load_durable.call.should respond_to(:nondurable?)
|
37
|
-
[true,false].member?(@load_durable.call.nondurable?).should be_true
|
38
|
-
end
|
36
|
+
it "should support #nondurable?" do
|
37
|
+
@load_durable.call.should respond_to(:nondurable?)
|
38
|
+
[true,false].member?(@load_durable.call.nondurable?).should be_true
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
it "should not be both durable and nondurable" do
|
42
|
+
@load_durable.call.nondurable?.should_not == @load_durable.call.durable?
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
it "should save contents between instantiations" do
|
46
|
+
if @load_durable.call.durable?
|
47
|
+
@load_durable.call.load(@filename)
|
48
|
+
@load_durable.call.count.should == File.readlines(@filename).size
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
data/lib/rdf/spec/enumerable.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rdf/spec'
|
2
2
|
|
3
|
-
|
3
|
+
module RDF_Enumerable
|
4
|
+
extend RSpec::SharedContext
|
4
5
|
include RDF::Spec::Matchers
|
5
6
|
|
6
7
|
before :each do
|
@@ -20,415 +21,437 @@ share_as :RDF_Enumerable do
|
|
20
21
|
@supports_context = @enumerable.respond_to?(:supports?) && @enumerable.supports?(:context)
|
21
22
|
end
|
22
23
|
|
23
|
-
describe
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
context "when counting statements" do
|
30
|
-
it "should respond to #empty?" do
|
31
|
-
@enumerable.should respond_to(:empty?)
|
24
|
+
describe RDF::Enumerable do
|
25
|
+
describe "#supports?" do
|
26
|
+
it "responds to #supports?" do
|
27
|
+
@enumerable.respond_to?(:support?)
|
28
|
+
end
|
32
29
|
end
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
context "when counting statements" do
|
32
|
+
it "should respond to #empty?" do
|
33
|
+
@enumerable.should respond_to(:empty?)
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
36
|
+
it "should respond to #count and #size" do
|
37
|
+
@enumerable.should respond_to(*%w(count size))
|
38
|
+
end
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
@enumerable.
|
40
|
+
it "should implement #empty?" do
|
41
|
+
([].extend(RDF::Enumerable)).empty?.should be_true
|
42
|
+
@enumerable.empty?.should be_false
|
46
43
|
end
|
47
|
-
end
|
48
|
-
end
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
it "should implement #count and #size" do
|
46
|
+
%w(count size).each do |method|
|
47
|
+
@enumerable.send(method).should == @statements.size
|
48
|
+
end
|
49
|
+
end
|
53
50
|
end
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
context "when enumerating statements" do
|
53
|
+
it "should respond to #statements" do
|
54
|
+
@enumerable.should respond_to(:statements)
|
55
|
+
end
|
58
56
|
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
it "should respond to #has_statement?" do
|
58
|
+
@enumerable.should respond_to(:has_statement?)
|
59
|
+
end
|
62
60
|
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
it "should respond to #each_statement" do
|
62
|
+
@enumerable.should respond_to(:each_statement)
|
63
|
+
end
|
66
64
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
@enumerable.statements.each { |statement| statement.should be_a_statement }
|
71
|
-
end
|
65
|
+
it "should respond to #enum_statement" do
|
66
|
+
@enumerable.should respond_to(:enum_statement)
|
67
|
+
end
|
72
68
|
|
73
|
-
|
74
|
-
|
75
|
-
@enumerable.
|
69
|
+
it "should implement #statements" do
|
70
|
+
@enumerable.statements.should be_an_enumerator
|
71
|
+
@enumerable.statements.to_a.size.should == @statements.size
|
72
|
+
@enumerable.statements.each { |statement| statement.should be_a_statement }
|
76
73
|
end
|
77
74
|
|
78
|
-
|
79
|
-
context = RDF::URI.new("urn:context:1")
|
75
|
+
it "should implement #has_statement?" do
|
80
76
|
@statements.each do |statement|
|
81
|
-
|
82
|
-
s.context = context
|
83
|
-
@enumerable.has_statement?(s).should be_false
|
77
|
+
@enumerable.has_statement?(statement).should be_true
|
84
78
|
end
|
85
|
-
end
|
86
79
|
|
87
|
-
|
88
|
-
|
89
|
-
|
80
|
+
if @supports_context
|
81
|
+
context = RDF::URI.new("urn:context:1")
|
82
|
+
@statements.each do |statement|
|
83
|
+
s = statement.dup
|
84
|
+
s.context = context
|
85
|
+
@enumerable.has_statement?(s).should be_false
|
86
|
+
end
|
87
|
+
end
|
90
88
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
89
|
+
unknown_statement = RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)
|
90
|
+
@enumerable.has_statement?(unknown_statement).should be_false
|
91
|
+
end
|
95
92
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
@enumerable.enum_statement.should be_queryable
|
101
|
-
@enumerable.enum_statement.to_a.should == @enumerable.each_statement.to_a
|
102
|
-
end
|
103
|
-
end
|
93
|
+
it "should implement #each_statement" do
|
94
|
+
@enumerable.each_statement.should be_an_enumerator
|
95
|
+
@enumerable.each_statement { |statement| statement.should be_a_statement }
|
96
|
+
end
|
104
97
|
|
105
|
-
|
106
|
-
|
107
|
-
|
98
|
+
it "should implement #enum_statement" do
|
99
|
+
@enumerable.enum_statement.should be_an_enumerator
|
100
|
+
@enumerable.enum_statement.should be_countable
|
101
|
+
@enumerable.enum_statement.should be_enumerable
|
102
|
+
@enumerable.enum_statement.should be_queryable
|
103
|
+
@enumerable.enum_statement.to_a.should == @enumerable.each_statement.to_a
|
104
|
+
end
|
108
105
|
end
|
109
106
|
|
110
|
-
|
111
|
-
|
112
|
-
|
107
|
+
context "when enumerating triples" do
|
108
|
+
it "should respond to #triples" do
|
109
|
+
@enumerable.should respond_to(:triples)
|
110
|
+
end
|
113
111
|
|
114
|
-
|
115
|
-
|
116
|
-
|
112
|
+
it "should respond to #has_triple?" do
|
113
|
+
@enumerable.should respond_to(:has_triple?)
|
114
|
+
end
|
117
115
|
|
118
|
-
|
119
|
-
|
120
|
-
|
116
|
+
it "should respond to #each_triple" do
|
117
|
+
@enumerable.should respond_to(:each_triple)
|
118
|
+
end
|
121
119
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
@enumerable.triples.each { |triple| triple.should be_a_triple }
|
126
|
-
end
|
120
|
+
it "should respond to #enum_triple" do
|
121
|
+
@enumerable.should respond_to(:enum_triple)
|
122
|
+
end
|
127
123
|
|
128
|
-
|
129
|
-
|
130
|
-
@enumerable.
|
124
|
+
it "should implement #triples" do
|
125
|
+
@enumerable.triples.should be_an_enumerator
|
126
|
+
@enumerable.triples.to_a.size.should == @statements.size
|
127
|
+
@enumerable.triples.each { |triple| triple.should be_a_triple }
|
131
128
|
end
|
132
|
-
end
|
133
129
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
130
|
+
it "should implement #has_triple?" do
|
131
|
+
@statements.each do |statement|
|
132
|
+
@enumerable.has_triple?(statement.to_triple).should be_true
|
133
|
+
end
|
134
|
+
end
|
138
135
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
end
|
144
|
-
end
|
136
|
+
it "should implement #each_triple" do
|
137
|
+
@enumerable.each_triple.should be_an_enumerator
|
138
|
+
@enumerable.each_triple { |*triple| triple.should be_a_triple }
|
139
|
+
end
|
145
140
|
|
146
|
-
|
147
|
-
|
148
|
-
|
141
|
+
it "should implement #enum_triple" do
|
142
|
+
@enumerable.enum_triple.should be_an_enumerator
|
143
|
+
@enumerable.enum_triple.should be_countable
|
144
|
+
@enumerable.enum_triple.to_a.should == @enumerable.each_triple.to_a
|
145
|
+
end
|
149
146
|
end
|
150
147
|
|
151
|
-
|
152
|
-
|
153
|
-
|
148
|
+
context "when enumerating quads" do
|
149
|
+
it "should respond to #quads" do
|
150
|
+
@enumerable.should respond_to(:quads)
|
151
|
+
end
|
154
152
|
|
155
|
-
|
156
|
-
|
157
|
-
|
153
|
+
it "should respond to #has_quad?" do
|
154
|
+
@enumerable.should respond_to(:has_quad?)
|
155
|
+
end
|
158
156
|
|
159
|
-
|
160
|
-
|
161
|
-
|
157
|
+
it "should respond to #each_quad" do
|
158
|
+
@enumerable.should respond_to(:each_quad)
|
159
|
+
end
|
162
160
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
@enumerable.quads.each { |quad| quad.should be_a_quad }
|
167
|
-
end
|
161
|
+
it "should respond to #enum_quad" do
|
162
|
+
@enumerable.should respond_to(:enum_quad)
|
163
|
+
end
|
168
164
|
|
169
|
-
|
170
|
-
|
171
|
-
@enumerable.
|
165
|
+
it "should implement #quads" do
|
166
|
+
@enumerable.quads.should be_an_enumerator
|
167
|
+
@enumerable.quads.to_a.size.should == @statements.size
|
168
|
+
@enumerable.quads.each { |quad| quad.should be_a_quad }
|
172
169
|
end
|
173
|
-
end
|
174
170
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
171
|
+
it "should implement #has_quad?" do
|
172
|
+
@statements.each do |statement|
|
173
|
+
@enumerable.has_quad?(statement.to_quad).should be_true
|
174
|
+
end
|
175
|
+
end
|
179
176
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
end
|
185
|
-
end
|
177
|
+
it "should implement #each_quad" do
|
178
|
+
@enumerable.each_quad.should be_an_enumerator
|
179
|
+
@enumerable.each_quad { |*quad| quad.should be_a_quad }
|
180
|
+
end
|
186
181
|
|
187
|
-
|
188
|
-
|
189
|
-
|
182
|
+
it "should implement #enum_quad" do
|
183
|
+
@enumerable.enum_quad.should be_an_enumerator
|
184
|
+
@enumerable.enum_quad.should be_countable
|
185
|
+
@enumerable.enum_quad.to_a.should == @enumerable.each_quad.to_a
|
186
|
+
end
|
190
187
|
end
|
191
188
|
|
192
|
-
|
193
|
-
|
194
|
-
|
189
|
+
context "when enumerating subjects" do
|
190
|
+
it "should respond to #subjects" do
|
191
|
+
@enumerable.should respond_to(:subjects)
|
192
|
+
end
|
195
193
|
|
196
|
-
|
197
|
-
|
198
|
-
|
194
|
+
it "should respond to #has_subject?" do
|
195
|
+
@enumerable.should respond_to(:has_subject?)
|
196
|
+
end
|
199
197
|
|
200
|
-
|
201
|
-
|
202
|
-
|
198
|
+
it "should respond to #each_subject" do
|
199
|
+
@enumerable.should respond_to(:each_subject)
|
200
|
+
end
|
203
201
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
# TODO: subjects(:unique => false)
|
208
|
-
end
|
202
|
+
it "should respond to #enum_subject" do
|
203
|
+
@enumerable.should respond_to(:enum_subject)
|
204
|
+
end
|
209
205
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
206
|
+
describe "#subjects" do
|
207
|
+
subject {@enumerable.subjects}
|
208
|
+
specify {subject.should be_an_enumerator}
|
209
|
+
specify {subject.each { |value| value.should be_a_resource }}
|
210
|
+
context ":unique => false" do
|
211
|
+
subject {@enumerable.subjects(:unique => false)}
|
212
|
+
specify {subject.should be_an_enumerator}
|
213
|
+
specify {subject.each { |value| value.should be_a_resource }}
|
214
|
+
end
|
215
215
|
end
|
216
|
-
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
217
|
-
@enumerable.has_predicate?(uri).should be_false
|
218
|
-
end
|
219
216
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
217
|
+
it "should implement #has_subject?" do
|
218
|
+
checked = []
|
219
|
+
@statements.each do |statement|
|
220
|
+
@enumerable.has_subject?(statement.subject).should be_true unless checked.include?(statement.subject)
|
221
|
+
checked << statement.subject
|
222
|
+
end
|
223
|
+
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
224
|
+
@enumerable.has_predicate?(uri).should be_false
|
227
225
|
end
|
228
|
-
end
|
229
226
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
227
|
+
it "should implement #each_subject" do
|
228
|
+
@enumerable.each_subject.should be_an_enumerator
|
229
|
+
subjects = @statements.map { |s| s.subject }.uniq
|
230
|
+
@enumerable.each_subject.to_a.size.should == subjects.size
|
231
|
+
@enumerable.each_subject do |value|
|
232
|
+
value.should be_a_value
|
233
|
+
subjects.should include(value)
|
234
|
+
end
|
235
|
+
end
|
236
236
|
|
237
|
-
|
238
|
-
|
239
|
-
|
237
|
+
it "should implement #enum_subject" do
|
238
|
+
@enumerable.enum_subject.should be_an_enumerator
|
239
|
+
@enumerable.enum_subject.should be_countable
|
240
|
+
@enumerable.enum_subject.to_a.should == @enumerable.each_subject.to_a
|
241
|
+
end
|
240
242
|
end
|
241
243
|
|
242
|
-
|
243
|
-
|
244
|
-
|
244
|
+
context "when enumerating predicates" do
|
245
|
+
it "should respond to #predicates" do
|
246
|
+
@enumerable.should respond_to(:predicates)
|
247
|
+
end
|
245
248
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
+
it "should respond to #has_predicate?" do
|
250
|
+
@enumerable.should respond_to(:has_predicate?)
|
251
|
+
end
|
249
252
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
+
it "should respond to #each_predicate" do
|
254
|
+
@enumerable.should respond_to(:each_predicate)
|
255
|
+
end
|
253
256
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
# TODO: predicates(:unique => false)
|
258
|
-
end
|
257
|
+
it "should respond to #enum_predicate" do
|
258
|
+
@enumerable.should respond_to(:enum_predicate)
|
259
|
+
end
|
259
260
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
261
|
+
describe "#predicates" do
|
262
|
+
subject {@enumerable.predicates}
|
263
|
+
specify {subject.should be_an_enumerator}
|
264
|
+
specify {subject.each { |value| value.should be_a_uri }}
|
265
|
+
context ":unique => false" do
|
266
|
+
subject {@enumerable.predicates(:unique => false)}
|
267
|
+
specify {subject.should be_an_enumerator}
|
268
|
+
specify {subject.each { |value| value.should be_a_resource }}
|
269
|
+
end
|
265
270
|
end
|
266
|
-
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
267
|
-
@enumerable.has_predicate?(uri).should be_false
|
268
|
-
end
|
269
271
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
272
|
+
it "should implement #has_predicate?" do
|
273
|
+
checked = []
|
274
|
+
@statements.each do |statement|
|
275
|
+
@enumerable.has_predicate?(statement.predicate).should be_true unless checked.include?(statement.object)
|
276
|
+
checked << statement.predicate
|
277
|
+
end
|
278
|
+
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
279
|
+
@enumerable.has_predicate?(uri).should be_false
|
277
280
|
end
|
278
|
-
end
|
279
281
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
282
|
+
it "should implement #each_predicate" do
|
283
|
+
predicates = @statements.map { |s| s.predicate }.uniq
|
284
|
+
@enumerable.each_predicate.should be_an_enumerator
|
285
|
+
@enumerable.each_predicate.to_a.size.should == predicates.size
|
286
|
+
@enumerable.each_predicate do |value|
|
287
|
+
value.should be_a_uri
|
288
|
+
predicates.should include(value)
|
289
|
+
end
|
290
|
+
end
|
286
291
|
|
287
|
-
|
288
|
-
|
289
|
-
|
292
|
+
it "should implement #enum_predicate" do
|
293
|
+
@enumerable.enum_predicate.should be_an_enumerator
|
294
|
+
@enumerable.enum_predicate.should be_countable
|
295
|
+
@enumerable.enum_predicate.to_a.should == @enumerable.each_predicate.to_a
|
296
|
+
end
|
290
297
|
end
|
291
298
|
|
292
|
-
|
293
|
-
|
294
|
-
|
299
|
+
context "when enumerating objects" do
|
300
|
+
it "should respond to #objects" do
|
301
|
+
@enumerable.should respond_to(:objects)
|
302
|
+
end
|
295
303
|
|
296
|
-
|
297
|
-
|
298
|
-
|
304
|
+
it "should respond to #has_object?" do
|
305
|
+
@enumerable.should respond_to(:has_object?)
|
306
|
+
end
|
299
307
|
|
300
|
-
|
301
|
-
|
302
|
-
|
308
|
+
it "should respond to #each_object" do
|
309
|
+
@enumerable.should respond_to(:each_object)
|
310
|
+
end
|
303
311
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
# TODO: objects(:unique => false)
|
308
|
-
end
|
312
|
+
it "should respond to #enum_object" do
|
313
|
+
@enumerable.should respond_to(:enum_object)
|
314
|
+
end
|
309
315
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
316
|
+
describe "#objects" do
|
317
|
+
subject {@enumerable.objects}
|
318
|
+
specify {subject.should be_an_enumerator}
|
319
|
+
specify {subject.each { |value| value.should be_a_value }}
|
320
|
+
context ":unique => false" do
|
321
|
+
subject {@enumerable.objects(:unique => false)}
|
322
|
+
specify {subject.should be_an_enumerator}
|
323
|
+
specify {subject.each { |value| value.should be_a_value }}
|
324
|
+
end
|
315
325
|
end
|
316
|
-
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
317
|
-
@enumerable.has_object?(uri).should be_false
|
318
|
-
end
|
319
326
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
+
it "should implement #has_object?" do
|
328
|
+
checked = []
|
329
|
+
@statements.each do |statement|
|
330
|
+
@enumerable.has_object?(statement.object).should be_true unless checked.include?(statement.object)
|
331
|
+
checked << statement.object
|
332
|
+
end
|
333
|
+
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
334
|
+
@enumerable.has_object?(uri).should be_false
|
327
335
|
end
|
328
|
-
end
|
329
336
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
337
|
+
it "should implement #each_object" do
|
338
|
+
objects = @statements.map { |s| s.object }.uniq
|
339
|
+
@enumerable.each_object.should be_an_enumerator
|
340
|
+
@enumerable.each_object.to_a.size.should == objects.size
|
341
|
+
@enumerable.each_object do |value|
|
342
|
+
value.should be_a_value
|
343
|
+
objects.should include(value)
|
344
|
+
end
|
345
|
+
end
|
336
346
|
|
337
|
-
|
338
|
-
|
339
|
-
|
347
|
+
it "should implement #enum_object" do
|
348
|
+
@enumerable.enum_object.should be_an_enumerator
|
349
|
+
@enumerable.enum_object.should be_countable
|
350
|
+
@enumerable.enum_object.to_a.should == @enumerable.each_object.to_a
|
351
|
+
end
|
340
352
|
end
|
341
353
|
|
342
|
-
|
343
|
-
|
344
|
-
|
354
|
+
context "when enumerating contexts" do
|
355
|
+
it "should respond to #contexts" do
|
356
|
+
@enumerable.should respond_to(:contexts)
|
357
|
+
end
|
345
358
|
|
346
|
-
|
347
|
-
|
348
|
-
|
359
|
+
it "should respond to #has_context?" do
|
360
|
+
@enumerable.should respond_to(:has_context?)
|
361
|
+
end
|
349
362
|
|
350
|
-
|
351
|
-
|
352
|
-
|
363
|
+
it "should respond to #each_context" do
|
364
|
+
@enumerable.should respond_to(:each_context)
|
365
|
+
end
|
353
366
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
# TODO: contexts(:unique => false)
|
358
|
-
end
|
367
|
+
it "should respond to #enum_context" do
|
368
|
+
@enumerable.should respond_to(:enum_context)
|
369
|
+
end
|
359
370
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
371
|
+
describe "#contexts" do
|
372
|
+
subject {@enumerable.contexts}
|
373
|
+
specify {subject.should be_an_enumerator}
|
374
|
+
specify {subject.each { |value| value.should be_a_resource }}
|
375
|
+
context ":unique => false" do
|
376
|
+
subject {@enumerable.contexts(:unique => false)}
|
377
|
+
specify {subject.should be_an_enumerator}
|
378
|
+
specify {subject.each { |value| value.should be_a_resource }}
|
364
379
|
end
|
365
380
|
end
|
366
|
-
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
367
|
-
@enumerable.has_context?(uri).should be_false
|
368
|
-
end
|
369
381
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
382
|
+
it "should implement #has_context?" do
|
383
|
+
@statements.each do |statement|
|
384
|
+
if statement.has_context?
|
385
|
+
@enumerable.has_context?(statement.context).should be_true
|
386
|
+
end
|
387
|
+
end
|
388
|
+
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
389
|
+
@enumerable.has_context?(uri).should be_false
|
378
390
|
end
|
379
|
-
end
|
380
391
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
392
|
+
it "should implement #each_context" do
|
393
|
+
contexts = @statements.map { |s| s.context }.uniq
|
394
|
+
contexts.delete nil
|
395
|
+
@enumerable.each_context.should be_an_enumerator
|
396
|
+
@enumerable.each_context.to_a.size.should == contexts.size
|
397
|
+
@enumerable.each_context do |value|
|
398
|
+
value.should be_a_resource
|
399
|
+
contexts.should include(value)
|
400
|
+
end
|
401
|
+
end
|
387
402
|
|
388
|
-
|
389
|
-
|
390
|
-
|
403
|
+
it "should implement #enum_context" do
|
404
|
+
@enumerable.enum_context.should be_an_enumerator
|
405
|
+
@enumerable.enum_context.should be_countable
|
406
|
+
@enumerable.enum_context.to_a.should == @enumerable.each_context.to_a
|
407
|
+
end
|
391
408
|
end
|
392
409
|
|
393
|
-
|
394
|
-
|
395
|
-
|
410
|
+
context "when enumerating graphs" do
|
411
|
+
it "should respond to #each_graph" do
|
412
|
+
@enumerable.should respond_to(:enum_graph)
|
413
|
+
end
|
396
414
|
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
# TODO: relying on #contexts, check that the returned values are correct.
|
401
|
-
end
|
415
|
+
it "should respond to #enum_graph" do
|
416
|
+
@enumerable.should respond_to(:enum_graph)
|
417
|
+
end
|
402
418
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
end
|
419
|
+
describe "#each_graph" do
|
420
|
+
subject {@enumerable.each_graph}
|
421
|
+
specify {subject.should be_an_enumerator}
|
422
|
+
specify {subject.each { |value| value.should be_a_graph }}
|
423
|
+
end
|
409
424
|
|
410
|
-
|
411
|
-
|
412
|
-
|
425
|
+
it "should implement #enum_graph" do
|
426
|
+
@enumerable.enum_graph.should be_an_enumerator
|
427
|
+
@enumerable.enum_graph.should be_countable
|
428
|
+
@enumerable.enum_graph.to_a.should == @enumerable.each_graph.to_a
|
429
|
+
end
|
413
430
|
end
|
414
431
|
|
415
|
-
|
416
|
-
|
417
|
-
|
432
|
+
context "when converting" do
|
433
|
+
it "should respond to #to_hash" do
|
434
|
+
@enumerable.should respond_to(:to_hash)
|
435
|
+
end
|
436
|
+
|
437
|
+
it "should implement #to_hash" do
|
438
|
+
@enumerable.to_hash.should be_instance_of(Hash)
|
439
|
+
@enumerable.to_hash.keys.size.should == @enumerable.subjects.to_a.size
|
440
|
+
end
|
418
441
|
end
|
419
|
-
end
|
420
442
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
443
|
+
context "when dumping" do
|
444
|
+
it "should respond to #dump" do
|
445
|
+
@enumerable.should respond_to(:dump)
|
446
|
+
end
|
425
447
|
|
426
|
-
|
427
|
-
|
428
|
-
|
448
|
+
it "should implement #dump" do
|
449
|
+
@enumerable.dump(:ntriples).should == RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
|
450
|
+
end
|
429
451
|
|
430
|
-
|
431
|
-
|
452
|
+
it "raises error on unknown format" do
|
453
|
+
lambda {@enumerable.dump(:foobar)}.should raise_error(RDF::WriterError, /No writer found/)
|
454
|
+
end
|
432
455
|
end
|
433
456
|
end
|
434
457
|
end
|