|
7 | 7 | raise 'enumerable must be set with `let(:enumerable)' unless |
8 | 8 | defined? enumerable |
9 | 9 |
|
10 | | - @statements ||= RDF::Spec.quads |
| 10 | + @rdf_enumerable_iv_statements ||= RDF::Spec.quads |
11 | 11 |
|
12 | 12 | if enumerable.empty? |
13 | 13 | if (enumerable.writable? rescue false) |
14 | | - enumerable.insert(*@statements) |
| 14 | + enumerable.insert(*@rdf_enumerable_iv_statements) |
15 | 15 | elsif enumerable.respond_to?(:<<) |
16 | | - @statements.each { |statement| enumerable << statement } |
| 16 | + @rdf_enumerable_iv_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 | | - |
22 | | - @supports_named_graphs = enumerable.supports?(:graph_name) rescue true |
23 | 21 | end |
24 | 22 |
|
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(&:node?)} |
28 | | - let(:non_bnode_terms) {@statements.map(&:to_quad).flatten.compact.reject(&:node?).uniq} |
| 23 | + let(:supports_named_graphs) {enumerable.supports?(:graph_name) rescue true} |
| 24 | + let(:subject_count) {@rdf_enumerable_iv_statements.map(&:subject).uniq.length} |
| 25 | + let(:bnode_subject_count) {@rdf_enumerable_iv_statements.map(&:subject).uniq.select(&:node?).length} |
| 26 | + let(:non_bnode_statements) {@rdf_enumerable_iv_statements.reject(&:node?)} |
| 27 | + let(:non_bnode_terms) {@rdf_enumerable_iv_statements.map(&:to_quad).flatten.compact.reject(&:node?).uniq} |
29 | 28 |
|
30 | 29 | subject { enumerable } |
31 | 30 | it {is_expected.to respond_to(:supports?)} |
|
57 | 56 | it {is_expected.to respond_to(:empty?)} |
58 | 57 | it {is_expected.to_not be_empty} |
59 | 58 | it {is_expected.to respond_to(:count)} |
60 | | - its(:count) {is_expected.to eq @statements.size} |
| 59 | + its(:count) {is_expected.to eq @rdf_enumerable_iv_statements.size} |
61 | 60 | it {is_expected.to respond_to(:size)} |
62 | | - its(:size) {is_expected.to eq @statements.size} |
| 61 | + its(:size) {is_expected.to eq @rdf_enumerable_iv_statements.size} |
63 | 62 |
|
64 | 63 | context "and empty" do |
65 | 64 | subject {[].extend(RDF::Enumerable)} |
|
74 | 73 | its(:statements) {is_expected.to be_a(Array)} |
75 | 74 |
|
76 | 75 | context "#statements" do |
77 | | - specify {expect(subject.statements.size).to eq @statements.size} |
| 76 | + specify {expect(subject.statements.size).to eq @rdf_enumerable_iv_statements.size} |
78 | 77 | specify {expect(subject.statements).to all(be_a_statement)} |
79 | 78 | end |
80 | 79 |
|
|
89 | 88 | end |
90 | 89 |
|
91 | 90 | it "does not have statement in different named graph" do |
92 | | - if @supports_named_graphs |
| 91 | + if supports_named_graphs |
93 | 92 | graph_name = RDF::URI.new("urn:graph_name:1") |
94 | 93 | non_bnode_statements.each do |statement| |
95 | 94 | s = statement.dup |
|
132 | 131 |
|
133 | 132 | its(:triples) {is_expected.to be_a(Array)} |
134 | 133 | context "#triples" do |
135 | | - specify {expect(subject.triples.size).to eq @statements.size} |
| 134 | + specify {expect(subject.triples.size).to eq @rdf_enumerable_iv_statements.size} |
136 | 135 | specify {expect(subject.triples).to all(be_a_triple)} |
137 | 136 | end |
138 | 137 |
|
|
176 | 175 |
|
177 | 176 | its(:quads) {is_expected.to be_a(Array)} |
178 | 177 | context "#quads" do |
179 | | - specify {expect(subject.quads.size).to eq @statements.size} |
| 178 | + specify {expect(subject.quads.size).to eq @rdf_enumerable_iv_statements.size} |
180 | 179 | specify {expect(subject.quads).to all(be_a_quad)} |
181 | 180 | end |
182 | 181 |
|
183 | 182 | context "#has_quad?" do |
184 | 183 | specify do |
185 | | - if @supports_named_graphs |
| 184 | + if supports_named_graphs |
186 | 185 | non_bnode_statements.each do |statement| |
187 | 186 | is_expected.to have_quad(statement.to_quad) |
188 | 187 | end |
|
265 | 264 | end |
266 | 265 |
|
267 | 266 | context "when enumerating predicates" do |
268 | | - let(:predicates) {@statements.map { |s| s.predicate }.uniq} |
| 267 | + let(:predicates) {@rdf_enumerable_iv_statements.map { |s| s.predicate }.uniq} |
269 | 268 | it {is_expected.to respond_to(:predicates)} |
270 | 269 | it {is_expected.to respond_to(:has_predicate?)} |
271 | 270 | it {is_expected.to respond_to(:each_predicate)} |
|
285 | 284 | context "#has_predicate?" do |
286 | 285 | specify do |
287 | 286 | checked = [] |
288 | | - @statements.each do |statement| |
| 287 | + @rdf_enumerable_iv_statements.each do |statement| |
289 | 288 | expect(enumerable).to have_predicate(statement.predicate) unless checked.include?(statement.predicate) |
290 | 289 | checked << statement.predicate |
291 | 290 | end |
|
434 | 433 | end |
435 | 434 |
|
436 | 435 | it "should implement #has_graph?" do |
437 | | - if @supports_named_graphs |
438 | | - @statements.each do |statement| |
| 436 | + if supports_named_graphs |
| 437 | + @rdf_enumerable_iv_statements.each do |statement| |
439 | 438 | if statement.has_graph? |
440 | 439 | expect(enumerable).to have_graph(statement.graph_name) |
441 | 440 | end |
|
480 | 479 |
|
481 | 480 | context "non-existing graph" do |
482 | 481 | let(:graph_name) {RDF::URI.new('http://example.org/does/not/have/this/uri')} |
483 | | - specify {expect(subject.project_graph(graph_name)).to be_empty if @supports_named_graphs} |
| 482 | + specify {expect(subject.project_graph(graph_name)).to be_empty if supports_named_graphs} |
484 | 483 | end |
485 | 484 | end |
486 | 485 |
|
487 | 486 | its(:each_graph) {is_expected.to be_an_enumerator} |
488 | 487 |
|
489 | 488 | describe "#each_graph" do |
490 | | - let(:graph_names) {@statements.map { |s| s.graph_name }.uniq.compact} |
| 489 | + let(:graph_names) {@rdf_enumerable_iv_statements.map { |s| s.graph_name }.uniq.compact} |
491 | 490 | subject { enumerable.each_graph } |
492 | 491 | it {is_expected.to be_an_enumerator} |
493 | | - specify {is_expected.to all(be_a_graph) if @supports_named_graphs} |
| 492 | + specify {is_expected.to all(be_a_graph) if supports_named_graphs} |
494 | 493 |
|
495 | 494 | it "has appropriate number of graphs" do |
496 | | - if @supports_named_graphs |
497 | | - graph_names = @statements.map { |s| s.graph_name }.uniq.compact |
| 495 | + if supports_named_graphs |
| 496 | + graph_names = @rdf_enumerable_iv_statements.map { |s| s.graph_name }.uniq.compact |
498 | 497 | expect(subject.to_a.size).to eq (graph_names.size + 1) |
499 | 498 | end |
500 | 499 | end |
|
505 | 504 | it {is_expected.to be_an_enumerator} |
506 | 505 | it {is_expected.to be_countable} |
507 | 506 | it "enumerates the same as #each_graph" do |
508 | | - expect(subject.to_a).to include(*enumerable.each_graph.to_a) if @supports_named_graphs # expect with match problematic |
| 507 | + expect(subject.to_a).to include(*enumerable.each_graph.to_a) if supports_named_graphs # expect with match problematic |
509 | 508 | end |
510 | 509 | end |
511 | 510 | end |
|
0 commit comments