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