|
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} |
|
82 | 82 | it {is_expected.to respond_to(:has_statement?)} |
83 | 83 | context "#has_statement?" do |
84 | 84 | let(:unknown_statement) {RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)} |
85 | | - it "is_expected.to have all statements" do |
| 85 | + it "should have all statements" do |
86 | 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 | 87 | non_bnode_statements.each do |statement| |
88 | 88 | is_expected.to have_statement(statement) |
89 | 89 | end |
90 | 90 | end |
91 | 91 |
|
92 | | - it "does not have statement in different context" do |
93 | | - if @supports_context |
94 | | - context = RDF::URI.new("urn:context:1") |
| 92 | + it "does not have statement in different named graph" do |
| 93 | + if @supports_named_graphs |
| 94 | + graph_name = RDF::URI.new("urn:graph_name:1") |
95 | 95 | non_bnode_statements.each do |statement| |
96 | 96 | s = statement.dup |
97 | | - s.context = context |
| 97 | + s.graph_name = graph_name |
98 | 98 | is_expected.not_to have_statement(s) |
99 | 99 | end |
100 | 100 | end |
|
115 | 115 | its(:enum_statement) {is_expected.to be_enumerable} |
116 | 116 | its(:enum_statement) {is_expected.to be_queryable} |
117 | 117 | context "#enum_statement" do |
118 | | - it "is_expected.to enumerate all statements" do |
| 118 | + it "should enumerate all statements" do |
119 | 119 | expect(subject.enum_statement.count).to eq enumerable.each_statement.count |
120 | 120 | subject.enum_statement.each do |s| |
121 | 121 | expect(s).to be_a_statement |
|
148 | 148 | its(:each_triple) {is_expected.to be_an_enumerator} |
149 | 149 | context "#each_triple" do |
150 | 150 | specify {expect(subject.each_triple).to all(be_a_triple)} |
151 | | - it "is_expected.to iterate over all triples" do |
| 151 | + it "should iterate over all triples" do |
152 | 152 | subject.each_triple do |*triple| |
153 | 153 | expect(triple.each).to all(be_a_term) |
154 | 154 | expect(enumerable).to have_triple(triple) unless triple.any?(&:node?) |
|
159 | 159 | its(:enum_triple) {is_expected.to be_an_enumerator} |
160 | 160 | its(:enum_triple) {is_expected.to be_countable} |
161 | 161 | context "#enum_triple" do |
162 | | - it "is_expected.to enumerate all triples" do |
| 162 | + it "should enumerate all triples" do |
163 | 163 | expect(subject.enum_triple.count).to eq enumerable.each_triple.count |
164 | 164 | subject.enum_triple.each do |s, p, o| |
165 | 165 | expect([s, p, o]).to all(be_a_term) |
|
183 | 183 |
|
184 | 184 | context "#has_quad?" do |
185 | 185 | specify do |
186 | | - if @supports_context |
| 186 | + if @supports_named_graphs |
187 | 187 | non_bnode_statements.each do |statement| |
188 | 188 | is_expected.to have_quad(statement.to_quad) |
189 | 189 | end |
|
194 | 194 | its(:each_quad) {is_expected.to be_an_enumerator} |
195 | 195 | context "#each_quad" do |
196 | 196 | specify {expect(subject.each_quad).to all(be_a_quad)} |
197 | | - it "is_expected.to iterate over all quads" do |
| 197 | + it "should iterate over all quads" do |
198 | 198 | subject.each_quad do |*quad| |
199 | 199 | expect(quad.compact).to all(be_a_term) |
200 | 200 | expect(enumerable).to have_quad(quad) unless quad.compact.any?(&:node?) |
|
205 | 205 | its(:enum_quad) {is_expected.to be_an_enumerator} |
206 | 206 | its(:enum_quad) {is_expected.to be_countable} |
207 | 207 | context "#enum_quad" do |
208 | | - it "is_expected.to enumerate all quads" do |
| 208 | + it "should enumerate all quads" do |
209 | 209 | expect(subject.enum_quad.count).to eq enumerable.each_quad.count |
210 | 210 | subject.enum_quad.each do |s, p, o, c| |
211 | 211 | expect([s, p, o, c].compact).to all(be_a_term) |
|
257 | 257 | its(:enum_subject) {is_expected.to be_countable} |
258 | 258 | context "#enum_subject" do |
259 | 259 | specify {expect(subject.enum_subject.to_a.reject(&:node?).size).to eq subjects.reject(&:node?).size} |
260 | | - it "is_expected.to enumerate all subjects" do |
| 260 | + it "should enumerate all subjects" do |
261 | 261 | subject.enum_subject.each do |s| |
262 | 262 | expect(s).to be_a_resource |
263 | 263 | expect(subjects.to_a).to include(s) unless s.node? |
|
307 | 307 | its(:enum_predicate) {is_expected.to be_an_enumerator} |
308 | 308 | its(:enum_predicate) {is_expected.to be_countable} |
309 | 309 | context "#enum_predicate" do |
310 | | - it "is_expected.to enumerate all predicates" do |
| 310 | + it "should enumerate all predicates" do |
311 | 311 | expect(subject.enum_predicate.to_a).to include(*predicates) |
312 | 312 | end |
313 | 313 | end |
|
354 | 354 | its(:enum_object) {is_expected.to be_an_enumerator} |
355 | 355 | its(:enum_object) {is_expected.to be_countable} |
356 | 356 | context "#enum_object" do |
357 | | - it "is_expected.to enumerate all objects" do |
| 357 | + it "should enumerate all objects" do |
358 | 358 | subject.enum_object.each do |o| |
359 | 359 | expect(o).to be_a_term |
360 | 360 | expect(objects.to_a).to include(o) unless o.node? |
|
374 | 374 | subject { enumerable.contexts } |
375 | 375 | specify {is_expected.to be_an_enumerator} |
376 | 376 | specify {is_expected.to all(be_a_resource)} |
377 | | - context ":unique => false" do |
| 377 | + context "unique: false" do |
378 | 378 | subject { enumerable.contexts(:unique => false) } |
379 | 379 | specify {is_expected.to be_an_enumerator} |
380 | 380 | specify {is_expected.to all(be_a_resource)} |
381 | 381 | end |
382 | 382 | end |
383 | 383 |
|
384 | 384 | it "is_expected.to implement #has_context?" do |
385 | | - if @supports_context |
| 385 | + if @supports_named_graphs |
386 | 386 | @statements.each do |statement| |
387 | 387 | if statement.has_context? |
388 | 388 | expect(enumerable).to have_context(statement.context) |
|
397 | 397 | context "#each_context" do |
398 | 398 | let(:contexts) {@statements.map { |s| s.context }.uniq.compact} |
399 | 399 | it "has appropriate number of contexts" do |
400 | | - if @supports_context |
| 400 | + if @supports_named_graphs |
401 | 401 | expect(subject.each_context.to_a.size).to eq contexts.size |
402 | 402 | end |
403 | 403 | end |
|
410 | 410 | its(:enum_context) {is_expected.to be_an_enumerator} |
411 | 411 | its(:enum_context) {is_expected.to be_countable} |
412 | 412 | context "#enum_context" do |
413 | | - it "is_expected.to enumerate all contexts" do |
| 413 | + it "should enumerate all contexts" do |
414 | 414 | expect(subject.enum_context.to_a).to include(*enumerable.each_context.to_a) |
415 | 415 | end |
416 | 416 | end |
|
436 | 436 | end |
437 | 437 | end |
438 | 438 |
|
| 439 | + context "when enumerating graphs" do |
| 440 | + it {is_expected.to respond_to(:graph_names)} |
| 441 | + it {is_expected.to respond_to(:has_graph?)} |
| 442 | + it {is_expected.to respond_to(:each_graph)} |
| 443 | + it {is_expected.to respond_to(:enum_graph)} |
| 444 | + |
| 445 | + its(:graph_names) {is_expected.to be_a(Array)} |
| 446 | + describe "#graph_names" do |
| 447 | + subject { enumerable.graph_names } |
| 448 | + specify {is_expected.to be_a(Array)} |
| 449 | + specify {is_expected.to all(be_a_resource)} |
| 450 | + context ":unique => false" do |
| 451 | + subject { enumerable.graph_names(:unique => false) } |
| 452 | + specify {is_expected.to be_a(Array)} |
| 453 | + specify {is_expected.to all(be_a_resource)} |
| 454 | + end |
| 455 | + end |
| 456 | + |
| 457 | + it "should implement #has_graph?" do |
| 458 | + if @supports_named_graphs |
| 459 | + @statements.each do |statement| |
| 460 | + if statement.has_graph? |
| 461 | + expect(enumerable).to have_graph(statement.graph_name) |
| 462 | + end |
| 463 | + end |
| 464 | + uri = RDF::URI.new('http://example.org/does/not/have/this/uri') |
| 465 | + expect(enumerable).not_to have_graph(uri) |
| 466 | + end |
| 467 | + end |
| 468 | + |
| 469 | + its(:each_graph) {is_expected.to be_an_enumerator} |
| 470 | + |
| 471 | + describe "#each_graph" do |
| 472 | + let(:graph_names) {@statements.map { |s| s.graph_name }.uniq.compact} |
| 473 | + subject { enumerable.each_graph } |
| 474 | + it {is_expected.to be_an_enumerator} |
| 475 | + specify {expect(subject.each_graph).to all(be_a_graph)} |
| 476 | + it "has appropriate number of graphs" do |
| 477 | + expect(subject.each_graph.to_a.size).to eq (graph_names.size + 1) |
| 478 | + end if @supports_named_graphs |
| 479 | + end |
| 480 | + |
| 481 | + describe "#enum_graph" do |
| 482 | + subject { enumerable.enum_graph } |
| 483 | + it {is_expected.to be_an_enumerator} |
| 484 | + it {is_expected.to be_countable} |
| 485 | + it "enumerates the same as #each_graph" do |
| 486 | + expect(subject.to_a).to include(*enumerable.each_graph.to_a) |
| 487 | + end if @supports_named_graphs # expect with match problematic |
| 488 | + end |
| 489 | + end |
| 490 | + |
439 | 491 | context "when converting" do |
440 | 492 | it {is_expected.to respond_to(:to_hash)} |
441 | 493 | its(:to_hash) {is_expected.to be_instance_of(Hash)} |
442 | 494 | context "#to_hash" do |
443 | | - it "is_expected.to have as many keys as subjects" do |
| 495 | + it "should have as many keys as subjects" do |
444 | 496 | expect(subject.to_hash.keys.size).to eq enumerable.subjects.to_a.size |
445 | 497 | end |
446 | 498 | end |
|
449 | 501 | context "when dumping" do |
450 | 502 | it {is_expected.to respond_to(:dump)} |
451 | 503 |
|
452 | | - it "is_expected.to implement #dump" do |
| 504 | + it "should implement #dump" do |
453 | 505 | expect(subject.dump(:ntriples)).to eq RDF::NTriples::Writer.buffer() {|w| w << enumerable} |
454 | 506 | end |
455 | 507 |
|
|
0 commit comments