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