rdf-spec 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -1
- data/README +23 -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 +301 -328
- data/lib/rdf/spec/format.rb +3 -2
- data/lib/rdf/spec/indexable.rb +6 -13
- data/lib/rdf/spec/mutable.rb +62 -49
- 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 +38 -44
- 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,444 +7,417 @@ 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
24
|
subject {@enumerable}
|
26
25
|
it {should respond_to(:supports?)}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
it {should respond_to(:quads)}
|
41
|
-
it {should respond_to(:has_quad?)}
|
42
|
-
it {should respond_to(:each_quad)}
|
43
|
-
it {should respond_to(:enum_quad)}
|
44
|
-
|
45
|
-
it {should respond_to(:subjects)}
|
46
|
-
it {should respond_to(:has_subject?)}
|
47
|
-
it {should respond_to(:each_subject)}
|
48
|
-
it {should respond_to(:enum_subject)}
|
49
|
-
|
50
|
-
it {should respond_to(:predicates)}
|
51
|
-
it {should respond_to(:has_predicate?)}
|
52
|
-
it {should respond_to(:each_predicate)}
|
53
|
-
it {should respond_to(:enum_predicate)}
|
54
|
-
|
55
|
-
it {should respond_to(:objects)}
|
56
|
-
it {should respond_to(:has_object?)}
|
57
|
-
it {should respond_to(:each_object)}
|
58
|
-
it {should respond_to(:enum_object)}
|
59
|
-
|
60
|
-
it {should respond_to(:contexts)}
|
61
|
-
it {should respond_to(:has_context?)}
|
62
|
-
it {should respond_to(:each_context)}
|
63
|
-
it {should respond_to(:enum_context)}
|
64
|
-
|
65
|
-
it {should respond_to(:each_graph)}
|
66
|
-
it {should respond_to(:enum_graph)}
|
67
|
-
|
68
|
-
it {should respond_to(:to_hash)}
|
69
|
-
it {should respond_to(:dump)}
|
70
|
-
|
71
|
-
it {should be_valid}
|
72
|
-
it {should_not be_empty}
|
73
|
-
its(:size) {should == @statements.size}
|
74
|
-
its(:count) {should == @statements.size}
|
75
|
-
|
76
|
-
it "returns is_invalid if any statement is invalid" do
|
77
|
-
if subject.respond_to?(:<<)
|
78
|
-
s = RDF::Statement.from([nil, nil, nil])
|
79
|
-
s.should_not be_valid
|
80
|
-
subject << s
|
81
|
-
subject.should_not be_valid
|
26
|
+
|
27
|
+
describe "valid?" do
|
28
|
+
it {should be_valid}
|
29
|
+
|
30
|
+
it "returns false if any statement is invalid" do
|
31
|
+
if subject.respond_to?(:<<) && (subject.writable? rescue true)
|
32
|
+
s = RDF::Statement.from([nil, nil, nil])
|
33
|
+
s.should_not be_valid
|
34
|
+
subject << s
|
35
|
+
subject.should_not be_valid
|
36
|
+
else
|
37
|
+
pending("can't add statement to immutable enumerable")
|
38
|
+
end
|
82
39
|
end
|
83
40
|
end
|
84
41
|
|
85
|
-
context "when
|
86
|
-
|
87
|
-
it {
|
88
|
-
|
89
|
-
its(:count) {should ==
|
42
|
+
context "when counting statements" do
|
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}
|
55
|
+
end
|
90
56
|
end
|
91
57
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
subject.statements.
|
58
|
+
context "when enumerating statements" do
|
59
|
+
it {should respond_to(:statements)}
|
60
|
+
its(:statements) {should be_an_enumerator}
|
61
|
+
|
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 }}
|
98
65
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
66
|
+
|
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
|
102
75
|
end
|
103
|
-
end
|
104
76
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
112
85
|
end
|
113
86
|
end
|
87
|
+
|
88
|
+
it "does not have an unknown statement" do
|
89
|
+
subject.has_statement?(unknown_statement).should be_false
|
90
|
+
end
|
114
91
|
end
|
115
92
|
|
116
|
-
it
|
117
|
-
|
118
|
-
|
93
|
+
it {should respond_to(:each_statement)}
|
94
|
+
its(:each_statement) {should be_an_enumerator}
|
95
|
+
it "should implement #each_statement" do
|
96
|
+
subject.each_statement { |statement| statement.should be_a_statement }
|
119
97
|
end
|
120
|
-
end
|
121
98
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
126
107
|
end
|
127
108
|
end
|
128
109
|
end
|
129
110
|
|
130
|
-
|
131
|
-
|
132
|
-
it {should
|
133
|
-
it
|
134
|
-
|
135
|
-
end
|
136
|
-
end
|
111
|
+
context "when enumerating triples" do
|
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)}
|
137
116
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
it {should be_enumerable}
|
143
|
-
it {should be_queryable}
|
144
|
-
it "should all be statements" do
|
145
|
-
subject { |statement| statement.should be_a_statement }
|
146
|
-
end
|
147
|
-
it "should have all statements" do
|
148
|
-
subject.to_a.should =~ @statements.to_a
|
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 }}
|
149
121
|
end
|
150
|
-
end
|
151
122
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
128
|
+
end
|
158
129
|
end
|
159
|
-
end
|
160
130
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
subject.should have_triple(statement.to_triple)
|
165
|
-
end
|
131
|
+
its(:each_triple) {should be_an_enumerator}
|
132
|
+
context "#each_triple" do
|
133
|
+
specify {subject.each_triple { |*triple| triple.should be_a_triple }}
|
166
134
|
end
|
167
|
-
end
|
168
135
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
triple.should be_a_triple
|
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
|
175
141
|
end
|
176
142
|
end
|
177
143
|
end
|
178
144
|
|
179
|
-
|
180
|
-
|
181
|
-
it {should
|
182
|
-
it {should
|
183
|
-
it
|
184
|
-
subject.to_a.should =~ @enumerable.each_triple.to_a
|
185
|
-
end
|
186
|
-
end
|
145
|
+
context "when enumerating quads" do
|
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)}
|
187
150
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
it "should all be quads" do
|
193
|
-
subject.each {|quad| quad.should be_a_quad}
|
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 }}
|
194
155
|
end
|
195
|
-
end
|
196
156
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
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
|
201
164
|
end
|
202
165
|
end
|
203
|
-
end
|
204
166
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
it "has all quads" do
|
209
|
-
subject do |*quad|
|
210
|
-
quad.should be_a_quad
|
211
|
-
end
|
167
|
+
its(:each_quad) {should be_an_enumerator}
|
168
|
+
context "#each_quad" do
|
169
|
+
specify {subject.each_quad {|*quad| quad.should be_a_quad }}
|
212
170
|
end
|
213
|
-
end
|
214
171
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
221
178
|
end
|
222
179
|
end
|
223
180
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
181
|
+
context "when enumerating subjects" do
|
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)}
|
186
|
+
|
187
|
+
its(:subjects) {should be_an_enumerator}
|
188
|
+
context "#subjects" do
|
189
|
+
subject {@enumerable.subjects}
|
230
190
|
specify {subject.should be_an_enumerator}
|
231
191
|
specify {subject.each { |value| value.should be_a_resource }}
|
192
|
+
context ":unique => false" do
|
193
|
+
subject {@enumerable.subjects(:unique => false)}
|
194
|
+
specify {subject.should be_an_enumerator}
|
195
|
+
specify {subject.each { |value| value.should be_a_resource }}
|
196
|
+
end
|
232
197
|
end
|
233
|
-
end
|
234
198
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
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
|
241
208
|
end
|
242
|
-
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
243
|
-
subject.should_not have_subject(uri)
|
244
209
|
end
|
245
|
-
end
|
246
210
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
subject.
|
253
|
-
subject do |term|
|
254
|
-
term.should be_a_term
|
255
|
-
subjects.should include(term)
|
256
|
-
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)}}
|
257
217
|
end
|
258
|
-
end
|
259
218
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
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
|
266
225
|
end
|
267
226
|
end
|
268
227
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
228
|
+
context "when enumerating predicates" do
|
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)}
|
233
|
+
|
234
|
+
its(:predicates) {should be_an_enumerator}
|
235
|
+
context "#predicates" do
|
236
|
+
subject {@enumerable.predicates}
|
275
237
|
specify {subject.should be_an_enumerator}
|
276
|
-
specify {subject.each { |value| value.should
|
238
|
+
specify {subject.each { |value| value.should be_a_uri }}
|
239
|
+
context ":unique => false" do
|
240
|
+
subject {@enumerable.predicates(:unique => false)}
|
241
|
+
specify {subject.should be_an_enumerator}
|
242
|
+
specify {subject.each { |value| value.should be_a_uri }}
|
243
|
+
end
|
277
244
|
end
|
278
|
-
end
|
279
245
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
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
|
286
255
|
end
|
287
|
-
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
288
|
-
subject.should_not have_predicate(uri)
|
289
256
|
end
|
290
|
-
end
|
291
257
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
subject.
|
298
|
-
subject do |term|
|
299
|
-
term.should be_a_term
|
300
|
-
predicates.should include(term)
|
301
|
-
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)}}
|
302
264
|
end
|
303
|
-
end
|
304
265
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
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
|
311
272
|
end
|
312
273
|
end
|
313
274
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
275
|
+
context "when enumerating objects" do
|
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)}
|
280
|
+
|
281
|
+
its(:objects) {should be_an_enumerator}
|
282
|
+
context "#objects" do
|
283
|
+
subject {@enumerable.objects}
|
320
284
|
specify {subject.should be_an_enumerator}
|
321
285
|
specify {subject.each { |value| value.should be_a_term }}
|
286
|
+
context ":unique => false" do
|
287
|
+
subject {@enumerable.objects(:unique => false)}
|
288
|
+
specify {subject.should be_an_enumerator}
|
289
|
+
specify {subject.each { |value| value.should be_a_term }}
|
290
|
+
end
|
322
291
|
end
|
323
|
-
end
|
324
292
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
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
|
331
302
|
end
|
332
|
-
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
333
|
-
subject.should_not have_object(uri)
|
334
303
|
end
|
335
|
-
end
|
336
304
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
subject.
|
343
|
-
subject do |term|
|
344
|
-
term.should be_a_term
|
345
|
-
objects.should include(term)
|
346
|
-
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)}}
|
347
311
|
end
|
348
|
-
end
|
349
312
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
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
|
356
319
|
end
|
357
320
|
end
|
358
321
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
322
|
+
context "when enumerating contexts" do
|
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)}
|
327
|
+
|
328
|
+
its(:contexts) {should be_an_enumerator}
|
329
|
+
describe "#contexts" do
|
330
|
+
subject {@enumerable.contexts}
|
365
331
|
specify {subject.should be_an_enumerator}
|
366
|
-
|
332
|
+
it "values should be resources" do
|
333
|
+
subject.each { |value| value.should be_a_resource }
|
334
|
+
end
|
335
|
+
context ":unique => false" do
|
336
|
+
subject {@enumerable.contexts(:unique => false)}
|
337
|
+
specify {subject.should be_an_enumerator}
|
338
|
+
it "values should be resources" do
|
339
|
+
subject.each { |value| value.should be_a_resource }
|
340
|
+
end
|
341
|
+
end
|
367
342
|
end
|
368
|
-
end
|
369
343
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
344
|
+
it "should implement #has_context?" do
|
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
|
375
353
|
end
|
376
|
-
uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
|
377
|
-
subject.should_not have_context(uri)
|
378
354
|
end
|
379
|
-
end
|
380
355
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
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
|
362
|
+
end
|
363
|
+
end
|
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)}
|
391
369
|
end
|
392
370
|
end
|
393
|
-
end
|
394
371
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
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
|
401
378
|
end
|
402
379
|
end
|
403
380
|
|
404
|
-
|
405
|
-
|
406
|
-
it {should
|
407
|
-
|
408
|
-
|
381
|
+
context "when enumerating graphs" do
|
382
|
+
it {should respond_to(:each_graph)}
|
383
|
+
it {should respond_to(:enum_graph)}
|
384
|
+
|
385
|
+
describe "#each_graph" do
|
386
|
+
subject {@enumerable.each_graph}
|
387
|
+
it {should be_an_enumerator}
|
388
|
+
specify {subject.each { |value| value.should be_a_graph }}
|
409
389
|
end
|
410
|
-
end
|
411
390
|
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
391
|
+
describe "#enum_graph" do
|
392
|
+
subject {@enumerable.enum_graph}
|
393
|
+
it {subject.should be_an_enumerator}
|
394
|
+
it {subject.should be_countable}
|
395
|
+
it "enumerates the same as #each_graph" do
|
396
|
+
subject.to_a.should == @enumerable.each_graph.to_a
|
397
|
+
end
|
418
398
|
end
|
419
399
|
end
|
420
400
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
401
|
+
context "when converting" do
|
402
|
+
it {should respond_to(:to_hash)}
|
403
|
+
its(:to_hash) {should be_instance_of(Hash)}
|
404
|
+
context "#to_hash" do
|
405
|
+
it "should have as many keys as subjects" do
|
406
|
+
subject.to_hash.keys.size.should == @enumerable.subjects.to_a.size
|
407
|
+
end
|
426
408
|
end
|
427
409
|
end
|
428
410
|
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
411
|
+
context "when dumping" do
|
412
|
+
it {should respond_to(:dump)}
|
413
|
+
|
414
|
+
it "should implement #dump" do
|
415
|
+
subject.dump(:ntriples).should == RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
|
433
416
|
end
|
434
|
-
|
417
|
+
|
435
418
|
it "raises error on unknown format" do
|
436
|
-
lambda {
|
419
|
+
lambda {subject.dump(:foobar)}.should raise_error(RDF::WriterError, /No writer found/)
|
437
420
|
end
|
438
421
|
end
|
439
|
-
|
440
|
-
context "#to_{writer}" do
|
441
|
-
it "should write to a writer" do
|
442
|
-
writer = mock("writer")
|
443
|
-
writer.should_receive(:buffer)
|
444
|
-
RDF::Writer.should_receive(:for).with(:a_writer).and_return(writer)
|
445
|
-
subject.send(:to_a_writer)
|
446
|
-
end
|
447
|
-
end
|
448
|
-
|
449
422
|
end
|
450
423
|
end
|