rdf-spec 1.99.0 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/{README → README.md} +2 -0
  3. data/VERSION +1 -1
  4. data/lib/rdf/spec.rb +18 -0
  5. data/lib/rdf/spec/countable.rb +5 -28
  6. data/lib/rdf/spec/dataset.rb +47 -0
  7. data/lib/rdf/spec/durable.rb +8 -23
  8. data/lib/rdf/spec/enumerable.rb +118 -102
  9. data/lib/rdf/spec/format.rb +4 -26
  10. data/lib/rdf/spec/http_adapter.rb +1 -23
  11. data/lib/rdf/spec/indexable.rb +1 -23
  12. data/lib/rdf/spec/inferable.rb +0 -16
  13. data/lib/rdf/spec/inspects.rb +4 -5
  14. data/lib/rdf/spec/matchers.rb +95 -4
  15. data/lib/rdf/spec/mutable.rb +227 -81
  16. data/lib/rdf/spec/queryable.rb +122 -165
  17. data/lib/rdf/spec/readable.rb +0 -22
  18. data/lib/rdf/spec/reader.rb +21 -29
  19. data/lib/rdf/spec/repository.rb +80 -40
  20. data/lib/rdf/spec/transactable.rb +43 -0
  21. data/lib/rdf/spec/transaction.rb +294 -71
  22. data/lib/rdf/spec/version.rb +2 -2
  23. data/lib/rdf/spec/writable.rb +78 -100
  24. data/lib/rdf/spec/writer.rb +51 -28
  25. data/spec/countable_spec.rb +11 -0
  26. data/spec/dataset_spec.rb +14 -0
  27. data/spec/durable_spec.rb +12 -0
  28. data/spec/enumerable_spec.rb +11 -0
  29. data/spec/format_spec.rb +12 -0
  30. data/spec/http_adapter_spec.rb +15 -0
  31. data/spec/indexable.rb +15 -0
  32. data/spec/literal_spec.rb +75 -0
  33. data/spec/mutable_spec.rb +11 -0
  34. data/spec/queryable_spec.rb +13 -0
  35. data/spec/readable.rb +11 -0
  36. data/spec/reader_spec.rb +17 -0
  37. data/spec/repository_spec.rb +11 -0
  38. data/spec/spec_helper.rb +13 -0
  39. data/spec/transaction_spec.rb +7 -0
  40. data/spec/version_spec.rb +2 -0
  41. data/spec/writable_spec.rb +13 -0
  42. data/spec/writer_spec.rb +11 -0
  43. metadata +56 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f20ea6160511bc458dbf138ed1fe61d828f1d40
4
- data.tar.gz: 03830cb0bc7e6322ed30a39a9938a64be387728c
3
+ metadata.gz: d6c4e07996e14e39f5680298b067deb592c89412
4
+ data.tar.gz: 3b418d1e0af6691520024e00c6742993d8f55cff
5
5
  SHA512:
6
- metadata.gz: bd8eb7f3e272f487d4f1114a4df4cc68b061e81f36cb4b3355578d6b254ce92efa1f1e8304aae27191c35383221212f430e95cb2c747b285273c85331fc0be92
7
- data.tar.gz: 83afd3996484fcec39368ece2024c2ba15f04ec6bcb213ddd59f817816eead5fe124493b54c2d52b22dd4c481598d6f7f78de7c204d661cae53b286365c58e13
6
+ metadata.gz: 95437e8b1f673a0ba04145c6e2dfcc749d454d66d92e93de3486ca7e508f2908fe8a25080200b339cc77adfdba09443acb962f03fa6b8dadbe8ce6b385bdddcc
7
+ data.tar.gz: dd579471099ff0b7f84ede5a437167c94c444395e0e58a06b7ce7a6624b667d13707fc2afb3d26f9ce92f9a06d3831902128f5e97b2bdcc81770bd8638739dc6
@@ -6,6 +6,8 @@ and shared examples for Ruby projects that use RDF.rb and RSpec.
6
6
  * <http://github.com/ruby-rdf/rdf-spec>
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/rdf-spec.png)](http://badge.fury.io/rb/rdf-spec)
9
+ [![Build Status](https://travis-ci.org/ruby-rdf/rdf-spec.png?branch=master)](http://travis-ci.org/ruby-rdf/rdf-spec)
10
+ [![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-spec/badge.svg)](https://coveralls.io/r/ruby-rdf/rdf-spec)
9
11
 
10
12
  ## Documentation
11
13
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.99.0
1
+ 2.0.0.beta1
@@ -1,4 +1,5 @@
1
1
  require 'rdf' # @see http://rubygems.org/gems/rdf
2
+ require 'rdf/isomorphic' # @see http://rubygems.org/gems/rdf-isomorphic
2
3
  require 'rspec' # @see http://rubygems.org/gems/rspec
3
4
  require 'rdf/spec/inspects'
4
5
  require 'rspec/its'
@@ -68,5 +69,22 @@ module RDF
68
69
  require 'rdf/ntriples'
69
70
  (@triples ||= RDF::NTriples::Reader.new(File.open(TRIPLES_FILE)).to_a).dup
70
71
  end
72
+
73
+ # Logger used for Specs; allows clearing and converting to string
74
+ require 'logger'
75
+ def self.logger
76
+ logger = Logger.new(StringIO.new)
77
+ def logger.clear
78
+ @logdev.instance_variable_set(:@dev, StringIO.new)
79
+ end
80
+ def logger.to_s
81
+ dev = @logdev.instance_variable_get(:@dev)
82
+ dev.rewind
83
+ dev.read
84
+ end
85
+ logger.level = Logger::DEBUG
86
+ logger.formatter = lambda {|severity, datetime, progname, msg| "#{severity} #{msg}\n"}
87
+ logger
88
+ end
71
89
  end # Spec
72
90
  end # RDF
@@ -3,17 +3,16 @@ require 'rdf/spec'
3
3
  RSpec.shared_examples 'an RDF::Countable' do
4
4
  include RDF::Spec::Matchers
5
5
 
6
+ let(:statements) {RDF::Spec.quads}
6
7
  before do
7
8
  raise 'countable must be set with `let(:countable)' unless
8
9
  defined? countable
9
10
 
10
- @statements = RDF::Spec.quads
11
-
12
11
  if countable.empty?
13
12
  if (countable.writable? rescue false)
14
- countable.send(:insert_statements, @statements)
13
+ countable.send(:insert_statements, statements)
15
14
  elsif countable.respond_to?(:<<)
16
- @statements.each { |statement| countable << statement }
15
+ statements.each { |statement| countable << statement }
17
16
  else
18
17
  raise "+countable+ must respond to #<< or be pre-populated with the" \
19
18
  "statements in #{RDF::Spec::TRIPLES_FILE} in a before block"
@@ -27,9 +26,9 @@ RSpec.shared_examples 'an RDF::Countable' do
27
26
  it {is_expected.to respond_to(:empty?)}
28
27
  it {is_expected.to_not be_empty}
29
28
  it {is_expected.to respond_to(:count)}
30
- its(:count) {is_expected.to eq @statements.size}
29
+ its(:count) {is_expected.to eq statements.size}
31
30
  it {is_expected.to respond_to(:size)}
32
- its(:size) {is_expected.to eq @statements.size}
31
+ its(:size) {is_expected.to eq statements.size}
33
32
 
34
33
  context "when empty" do
35
34
  subject {[].extend(RDF::Countable)}
@@ -45,25 +44,3 @@ RSpec.shared_examples 'an RDF::Countable' do
45
44
  end
46
45
  end
47
46
  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
@@ -0,0 +1,47 @@
1
+ require 'rdf/spec'
2
+
3
+ RSpec.shared_examples 'an RDF::Dataset' do
4
+ include RDF::Spec::Matchers
5
+
6
+ before :each do
7
+ raise 'dataset must be set with `let(:dataset)' unless
8
+ defined? dataset
9
+
10
+ if dataset.empty?
11
+ raise "+dataset+ must respond be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before block"
12
+ end
13
+ end
14
+
15
+ let(:countable) { dataset }
16
+ let(:enumerable) { dataset }
17
+ let(:queryable) { dataset }
18
+
19
+ context "when counting statements" do
20
+ require 'rdf/spec/countable'
21
+ it_behaves_like 'an RDF::Countable'
22
+ end
23
+
24
+ context "when enumerating statements" do
25
+ require 'rdf/spec/enumerable'
26
+ it_behaves_like 'an RDF::Enumerable'
27
+ end
28
+
29
+ context "as durable" do
30
+ require 'rdf/spec/durable'
31
+ before { @load_durable ||= lambda { dataset } }
32
+
33
+ it_behaves_like 'an RDF::Durable'
34
+ end
35
+
36
+ context "when querying statements" do
37
+ require 'rdf/spec/queryable'
38
+ it_behaves_like 'an RDF::Queryable'
39
+ end
40
+
41
+ describe '#isolation_level' do
42
+ it 'is an allowable isolation level' do
43
+ expect(described_class::ISOLATION_LEVELS)
44
+ .to include(dataset.isolation_level)
45
+ end
46
+ end
47
+ end
@@ -6,8 +6,7 @@ require 'rdf/spec'
6
6
  #describe RDF::DataObjects::Repository do
7
7
  # context "The SQLite adapter" do
8
8
  # before :each do
9
- # @repository = RDF::DataObjects::Repository.new "sqlite3://:memory:"
10
- # @load_durable = lambda { RDF::DataObjects::Repository.new "sqlite3:test.db" }
9
+ # @load_durable = lambda { RDF::DataObjects::Repository.new uri: "sqlite3:test.db" }
11
10
  # end
12
11
  #
13
12
  # after :each do
@@ -29,38 +28,24 @@ RSpec.shared_examples 'an RDF::Durable' do
29
28
 
30
29
  it { is_expected.to respond_to(:durable?) }
31
30
 
32
- it "is_expected.to support #durable?" do
31
+ it "supports #durable?" do
33
32
  expect([true,false]).to be_member(subject.durable?)
34
33
  end
35
34
 
36
35
  it {is_expected.to respond_to(:nondurable?)}
37
36
 
38
- it "is_expected.to support #nondurable?" do
37
+ it "supports #nondurable?" do
39
38
  expect([true,false]).to be_member(@load_durable.call.nondurable?)
40
39
  end
41
40
 
42
41
  its(:nondurable?) {is_expected.to_not eq subject.durable?}
43
42
 
44
- it "is_expected.to save contents between instantiations" do
43
+ it "saves contents between instantiations" do
45
44
  if subject.durable?
46
- subject.load(RDF::Spec::TRIPLES_FILE)
47
- expect(subject.count).to eq File.readlines(RDF::Spec::TRIPLES_FILE).size
45
+ subject.insert RDF::Statement(RDF::RDFS.Resource, RDF.value, "string") if subject.empty?
46
+ subject.close if subject.respond_to?(:close)
47
+ new_instance = @load_durable.call
48
+ expect(new_instance).not_to be_empty
48
49
  end
49
50
  end
50
51
  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
@@ -24,7 +24,8 @@ RSpec.shared_examples 'an RDF::Enumerable' do
24
24
 
25
25
  let(:subject_count) {@statements.map(&:subject).uniq.length}
26
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?}}
27
+ let(:non_bnode_statements) {@statements.reject(&:node?)}
28
+ let(:non_bnode_terms) {@statements.map(&:to_quad).flatten.compact.reject(&:node?).uniq}
28
29
 
29
30
  subject { enumerable }
30
31
  it {is_expected.to respond_to(:supports?)}
@@ -70,10 +71,10 @@ RSpec.shared_examples 'an RDF::Enumerable' do
70
71
 
71
72
  context "when enumerating statements" do
72
73
  it {is_expected.to respond_to(:statements)}
73
- #its(:statements) {is_expected.to be_an_enumerator}
74
+ its(:statements) {is_expected.to be_a(Array)}
74
75
 
75
76
  context "#statements" do
76
- specify {expect(subject.statements.to_a.size).to eq @statements.size}
77
+ specify {expect(subject.statements.size).to eq @statements.size}
77
78
  specify {expect(subject.statements).to all(be_a_statement)}
78
79
  end
79
80
 
@@ -129,9 +130,9 @@ RSpec.shared_examples 'an RDF::Enumerable' do
129
130
  it {is_expected.to respond_to(:each_triple)}
130
131
  it {is_expected.to respond_to(:enum_triple)}
131
132
 
132
- #its(:triples) {is_expected.to be_an_enumerator}
133
+ its(:triples) {is_expected.to be_a(Array)}
133
134
  context "#triples" do
134
- specify {expect(subject.triples.to_a.size).to eq @statements.size}
135
+ specify {expect(subject.triples.size).to eq @statements.size}
135
136
  specify {expect(subject.triples).to all(be_a_triple)}
136
137
  end
137
138
 
@@ -173,9 +174,9 @@ RSpec.shared_examples 'an RDF::Enumerable' do
173
174
  it {is_expected.to respond_to(:each_quad)}
174
175
  it {is_expected.to respond_to(:enum_quad)}
175
176
 
176
- #its(:quads) {is_expected.to be_an_enumerator}
177
+ its(:quads) {is_expected.to be_a(Array)}
177
178
  context "#quads" do
178
- specify {expect(subject.quads.to_a.size).to eq @statements.size}
179
+ specify {expect(subject.quads.size).to eq @statements.size}
179
180
  specify {expect(subject.quads).to all(be_a_quad)}
180
181
  end
181
182
 
@@ -220,14 +221,13 @@ RSpec.shared_examples 'an RDF::Enumerable' do
220
221
  it {is_expected.to respond_to(:each_subject)}
221
222
  it {is_expected.to respond_to(:enum_subject)}
222
223
 
223
- #its(:subjects) {is_expected.to be_an_enumerator}
224
224
  context "#subjects" do
225
225
  subject { enumerable.subjects }
226
- specify {is_expected.to be_an_enumerator}
226
+ specify {is_expected.to be_a(Array)}
227
227
  specify {is_expected.to all(be_a_resource)}
228
228
  context "unique: false" do
229
229
  subject { enumerable.subjects(unique: false) }
230
- specify {is_expected.to be_an_enumerator}
230
+ specify {is_expected.to be_a(Array)}
231
231
  specify {is_expected.to all(be_a_resource)}
232
232
  end
233
233
  end
@@ -271,14 +271,13 @@ RSpec.shared_examples 'an RDF::Enumerable' do
271
271
  it {is_expected.to respond_to(:each_predicate)}
272
272
  it {is_expected.to respond_to(:enum_predicate)}
273
273
 
274
- #its(:predicates) {is_expected.to be_an_enumerator}
275
274
  context "#predicates" do
276
275
  subject { enumerable.predicates }
277
- specify {is_expected.to be_an_enumerator}
276
+ specify {is_expected.to be_a(Array)}
278
277
  specify {is_expected.to all(be_a_uri)}
279
278
  context "unique: false" do
280
279
  subject { enumerable.predicates(unique: false) }
281
- specify {is_expected.to be_an_enumerator}
280
+ specify {is_expected.to be_a(Array)}
282
281
  specify {is_expected.to all(be_a_uri)}
283
282
  end
284
283
  end
@@ -318,14 +317,13 @@ RSpec.shared_examples 'an RDF::Enumerable' do
318
317
  it {is_expected.to respond_to(:each_object)}
319
318
  it {is_expected.to respond_to(:enum_object)}
320
319
 
321
- #its(:objects) {is_expected.to be_an_enumerator}
322
320
  context "#objects" do
323
321
  subject { enumerable.objects }
324
- specify {is_expected.to be_an_enumerator}
322
+ specify {is_expected.to be_a(Array)}
325
323
  specify {is_expected.to all(be_a_term)}
326
324
  context "unique: false" do
327
325
  subject { enumerable.objects(unique: false) }
328
- specify {is_expected.to be_an_enumerator}
326
+ specify {is_expected.to be_a(Array)}
329
327
  specify {is_expected.to all(be_a_term)}
330
328
  end
331
329
  end
@@ -361,89 +359,64 @@ RSpec.shared_examples 'an RDF::Enumerable' do
361
359
  end
362
360
  end
363
361
 
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)}
362
+ context "when enumerating terms" do
363
+ let(:terms) {subject.map(&:to_quad).flatten.compact.reject(&:node?).uniq}
364
+ it {is_expected.to respond_to(:terms)}
365
+ it {is_expected.to respond_to(:has_term?)}
366
+ it {is_expected.to respond_to(:each_term)}
367
+ it {is_expected.to respond_to(:enum_term)}
369
368
 
370
- its(:contexts) {is_expected.to be_an_enumerator}
371
- describe "#contexts" do
372
- subject { enumerable.contexts }
373
- specify {is_expected.to be_an_enumerator}
374
- specify {is_expected.to all(be_a_resource)}
369
+ context "#terms" do
370
+ subject { enumerable.terms }
371
+ specify {is_expected.to be_a(Array)}
372
+ specify {is_expected.to all(be_a_term)}
375
373
  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)}
374
+ subject { enumerable.terms(unique: false) }
375
+ specify {is_expected.to be_a(Array)}
376
+ specify {is_expected.to all(be_a_term)}
379
377
  end
380
378
  end
381
379
 
382
- it "is_expected.to implement #has_context?" do
383
- if @supports_named_graphs
384
- @statements.each do |statement|
385
- if statement.has_context?
386
- expect(enumerable).to have_context(statement.context)
387
- end
380
+ context "#has_term?" do
381
+ specify do
382
+ checked = {}
383
+ non_bnode_terms.each do |term|
384
+ expect(enumerable).to have_term(term) unless checked.has_key?(term.hash)
385
+ checked[term.hash] = true
388
386
  end
389
387
  uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
390
- expect(enumerable).not_to have_context(uri)
388
+ expect(enumerable).not_to have_term(uri)
391
389
  end
392
390
  end
393
391
 
394
- its(:each_context) {is_expected.to be_an_enumerator}
395
- context "#each_context" do
396
- let(:contexts) {@statements.map { |s| s.context }.uniq.compact}
397
- it "has appropriate number of contexts" do
398
- if @supports_named_graphs
399
- expect(subject.each_context.to_a.size).to eq contexts.size
400
- end
401
- end
402
- specify {expect(subject.each_context).to all(be_a_resource)}
403
- it "is_expected.to have all contexts" do
404
- subject.each_context {|value| expect(contexts).to include(value)}
405
- end
392
+ its(:each_term) {is_expected.to be_an_enumerator}
393
+ context "#each_term" do
394
+ specify {
395
+ expect(subject.each_term.reject(&:node?).size).to eq non_bnode_terms.length
396
+ }
397
+ specify {expect(subject.each_term).to all(be_a_term)}
398
+ specify {subject.each_term {|value| expect(non_bnode_terms).to include(value) unless value.node?}}
406
399
  end
407
400
 
408
- its(:enum_context) {is_expected.to be_an_enumerator}
409
- its(:enum_context) {is_expected.to be_countable}
410
- context "#enum_context" do
411
- it "should enumerate all contexts" do
412
- expect(subject.enum_context.to_a).to include(*enumerable.each_context.to_a)
401
+ its(:enum_term) {is_expected.to be_an_enumerator}
402
+ its(:enum_term) {is_expected.to be_countable}
403
+ context "#enum_term" do
404
+ it "should enumerate all terms" do
405
+ subject.enum_term.each do |o|
406
+ expect(o).to be_a_term
407
+ expect(non_bnode_terms.to_a).to include(o) unless o.node?
408
+ end
413
409
  end
414
410
  end
415
411
  end
416
412
 
417
413
  context "when enumerating graphs" do
418
- it {is_expected.to respond_to(:each_graph)}
419
- it {is_expected.to respond_to(:enum_graph)}
420
-
421
- describe "#each_graph" do
422
- subject { enumerable.each_graph }
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
431
- end
432
-
433
- describe "#enum_graph" do
434
- subject { enumerable.enum_graph }
435
- it {is_expected.to be_an_enumerator}
436
- it {is_expected.to be_countable}
437
- it "enumerates the same as #each_graph" do
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
414
  it {is_expected.to respond_to(:graph_names)}
445
415
  it {is_expected.to respond_to(:has_graph?)}
416
+ it {is_expected.to respond_to(:each_graph)}
417
+ it {is_expected.to respond_to(:enum_graph)}
446
418
 
419
+ its(:graph_names) {is_expected.to be_a(Array)}
447
420
  describe "#graph_names" do
448
421
  subject { enumerable.graph_names }
449
422
  specify {is_expected.to be_a(Array)}
@@ -455,7 +428,7 @@ RSpec.shared_examples 'an RDF::Enumerable' do
455
428
  end
456
429
  end
457
430
 
458
- describe "#has_graph?" do
431
+ it "should implement #has_graph?" do
459
432
  if @supports_named_graphs
460
433
  @statements.each do |statement|
461
434
  if statement.has_graph?
@@ -466,8 +439,73 @@ RSpec.shared_examples 'an RDF::Enumerable' do
466
439
  expect(enumerable).not_to have_graph(uri)
467
440
  end
468
441
  end
442
+
443
+ describe "#project_graph" do
444
+ it {is_expected.to respond_to(:project_graph)}
445
+
446
+ context "default graph" do
447
+ let(:graph_name) {nil}
448
+ specify {expect(subject.project_graph(graph_name)).to all(be_a_statement)}
449
+
450
+ it "should return default triples" do
451
+ expect(subject.project_graph(graph_name).count).to eql(subject.reject(&:graph_name).count)
452
+ end
453
+
454
+ it "should iterate over default triples" do
455
+ subject.project_graph(graph_name) do |statement|
456
+ expect(statement.graph_name).to be_nil
457
+ end
458
+ end
459
+ end
460
+
461
+ context "named graph" do
462
+ let(:graph_name) {enumerable.graph_names.first}
463
+ specify {expect(subject.project_graph(graph_name)).to all(be_a_statement)}
464
+
465
+ it "should return named triples" do
466
+ expect(subject.project_graph(graph_name).count).to eql(subject.select {|s| s.graph_name == graph_name}.count)
467
+ end
468
+
469
+ it "should iterate over named triples" do
470
+ subject.project_graph(graph_name) do |statement|
471
+ expect(statement.graph_name).to eql graph_name
472
+ end
473
+ end
474
+ end
475
+
476
+ context "non-existing graph" do
477
+ let(:graph_name) {RDF::URI.new('http://example.org/does/not/have/this/uri')}
478
+ specify {expect(subject.project_graph(graph_name)).to be_empty if @supports_named_graphs}
479
+ end
480
+ end
481
+
482
+ its(:each_graph) {is_expected.to be_an_enumerator}
483
+
484
+ describe "#each_graph" do
485
+ let(:graph_names) {@statements.map { |s| s.graph_name }.uniq.compact}
486
+ subject { enumerable.each_graph }
487
+ it {is_expected.to be_an_enumerator}
488
+ specify {is_expected.to all(be_a_graph) if @supports_named_graphs}
489
+
490
+ it "has appropriate number of graphs" do
491
+ if @supports_named_graphs
492
+ graph_names = @statements.map { |s| s.graph_name }.uniq.compact
493
+ expect(subject.to_a.size).to eq (graph_names.size + 1)
494
+ end
495
+ end
496
+ end
497
+
498
+ describe "#enum_graph" do
499
+ subject { enumerable.enum_graph }
500
+ it {is_expected.to be_an_enumerator}
501
+ it {is_expected.to be_countable}
502
+ it "enumerates the same as #each_graph" do
503
+ expect(subject.to_a).to include(*enumerable.each_graph.to_a) if @supports_named_graphs # expect with match problematic
504
+ end
505
+ end
469
506
  end
470
507
 
508
+
471
509
  context "when converting" do
472
510
  it {is_expected.to respond_to(:to_hash)}
473
511
  its(:to_hash) {is_expected.to be_instance_of(Hash)}
@@ -490,25 +528,3 @@ RSpec.shared_examples 'an RDF::Enumerable' do
490
528
  end
491
529
  end
492
530
  end
493
-
494
- ##
495
- # @deprecated use `it_behaves_like "an RDF::Enumerable"` instead
496
- module RDF_Enumerable
497
- extend RSpec::SharedContext
498
- include RDF::Spec::Matchers
499
-
500
- def self.included(mod)
501
- warn "[DEPRECATION] `RDF_Enumerable` is deprecated. "\
502
- "Please use `it_behaves_like 'an RDF::Enumerable'`"
503
- end
504
-
505
- describe 'examples for' do
506
- include_examples 'an RDF::Enumerable' do
507
- let(:enumerable) { @enumerable }
508
-
509
- before do
510
- raise '@enumerable must be defined' unless defined?(enumerable)
511
- end
512
- end
513
- end
514
- end