rdf-spec 1.1.13 → 1.99.0

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