Skip to content

Commit 2661781

Browse files
committed
Rename instance variables used in specs to be localized so as not to confuse with the same variable that could be named in the surrounding context.
1 parent 6d45c36 commit 2661781

7 files changed

Lines changed: 63 additions & 65 deletions

File tree

lib/rdf/spec/enumerable.rb

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,24 @@
77
raise 'enumerable must be set with `let(:enumerable)' unless
88
defined? enumerable
99

10-
@statements ||= RDF::Spec.quads
10+
@rdf_enumerable_iv_statements ||= RDF::Spec.quads
1111

1212
if enumerable.empty?
1313
if (enumerable.writable? rescue false)
14-
enumerable.insert(*@statements)
14+
enumerable.insert(*@rdf_enumerable_iv_statements)
1515
elsif enumerable.respond_to?(:<<)
16-
@statements.each { |statement| enumerable << statement }
16+
@rdf_enumerable_iv_statements.each { |statement| enumerable << statement }
1717
else
1818
raise "@enumerable must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
1919
end
2020
end
21-
22-
@supports_named_graphs = enumerable.supports?(:graph_name) rescue true
2321
end
2422

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}
2928

3029
subject { enumerable }
3130
it {is_expected.to respond_to(:supports?)}
@@ -57,9 +56,9 @@
5756
it {is_expected.to respond_to(:empty?)}
5857
it {is_expected.to_not be_empty}
5958
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}
6160
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}
6362

6463
context "and empty" do
6564
subject {[].extend(RDF::Enumerable)}
@@ -74,7 +73,7 @@
7473
its(:statements) {is_expected.to be_a(Array)}
7574

7675
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}
7877
specify {expect(subject.statements).to all(be_a_statement)}
7978
end
8079

@@ -89,7 +88,7 @@
8988
end
9089

9190
it "does not have statement in different named graph" do
92-
if @supports_named_graphs
91+
if supports_named_graphs
9392
graph_name = RDF::URI.new("urn:graph_name:1")
9493
non_bnode_statements.each do |statement|
9594
s = statement.dup
@@ -132,7 +131,7 @@
132131

133132
its(:triples) {is_expected.to be_a(Array)}
134133
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}
136135
specify {expect(subject.triples).to all(be_a_triple)}
137136
end
138137

@@ -176,13 +175,13 @@
176175

177176
its(:quads) {is_expected.to be_a(Array)}
178177
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}
180179
specify {expect(subject.quads).to all(be_a_quad)}
181180
end
182181

183182
context "#has_quad?" do
184183
specify do
185-
if @supports_named_graphs
184+
if supports_named_graphs
186185
non_bnode_statements.each do |statement|
187186
is_expected.to have_quad(statement.to_quad)
188187
end
@@ -265,7 +264,7 @@
265264
end
266265

267266
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}
269268
it {is_expected.to respond_to(:predicates)}
270269
it {is_expected.to respond_to(:has_predicate?)}
271270
it {is_expected.to respond_to(:each_predicate)}
@@ -285,7 +284,7 @@
285284
context "#has_predicate?" do
286285
specify do
287286
checked = []
288-
@statements.each do |statement|
287+
@rdf_enumerable_iv_statements.each do |statement|
289288
expect(enumerable).to have_predicate(statement.predicate) unless checked.include?(statement.predicate)
290289
checked << statement.predicate
291290
end
@@ -434,8 +433,8 @@
434433
end
435434

436435
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|
439438
if statement.has_graph?
440439
expect(enumerable).to have_graph(statement.graph_name)
441440
end
@@ -480,21 +479,21 @@
480479

481480
context "non-existing graph" do
482481
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}
484483
end
485484
end
486485

487486
its(:each_graph) {is_expected.to be_an_enumerator}
488487

489488
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}
491490
subject { enumerable.each_graph }
492491
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}
494493

495494
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
498497
expect(subject.to_a.size).to eq (graph_names.size + 1)
499498
end
500499
end
@@ -505,7 +504,7 @@
505504
it {is_expected.to be_an_enumerator}
506505
it {is_expected.to be_countable}
507506
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
509508
end
510509
end
511510
end

lib/rdf/spec/matchers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ module Matchers
193193
end
194194

195195
RSpec::Matchers.define :write do |message|
196-
chain(:to) { |io| @io = io }
196+
chain(:to) { |io| @rdf_matcher_iv_io = io }
197197

198198
supports_block_expectations { true }
199199

@@ -256,7 +256,7 @@ def fake_stdout
256256

257257
# default IO is standard output
258258
def io
259-
@io ||= :output
259+
@rdf_matcher_iv_io ||= :output
260260
end
261261

262262
# IO name is used for description message

lib/rdf/spec/mutable.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
defined? mutable
1010

1111
skip "Immutable resource" unless mutable.mutable?
12-
@statements = RDF::Spec.triples
12+
@rdf_mutable_iv_statements = RDF::Spec.triples
1313
@supports_named_graphs = mutable.respond_to?(:supports?) && mutable.supports?(:graph_name)
1414
@supports_literal_equality = mutable.respond_to?(:supports?) && mutable.supports?(:literal_equality)
1515
end
1616

1717
let(:resource) { RDF::URI('http://rubygems.org/gems/rdf') }
1818
let(:graph_name) { RDF::URI('http://example.org/graph_name') }
19-
let(:non_bnode_statements) {@statements.reject(&:node?)}
19+
let(:non_bnode_statements) {@rdf_mutable_iv_statements.reject(&:node?)}
2020

2121
describe RDF::Mutable do
2222
subject { mutable }
@@ -139,7 +139,7 @@
139139

140140
context "when deleting statements" do
141141
before :each do
142-
subject.insert(*@statements)
142+
subject.insert(*@rdf_mutable_iv_statements)
143143
end
144144

145145
it "should not raise errors" do
@@ -152,7 +152,7 @@
152152
end
153153

154154
it "should support deleting multiple statements at a time" do
155-
subject.delete(*@statements)
155+
subject.delete(*@rdf_mutable_iv_statements)
156156
expect(subject.find { |s| subject.has_statement?(s) }).to be_nil
157157
end
158158

@@ -234,13 +234,13 @@
234234
end
235235

236236
it 'deletes and inserts' do
237-
subject.delete_insert(@statements, [statement])
237+
subject.delete_insert(@rdf_mutable_iv_statements, [statement])
238238
is_expected.to contain_exactly statement
239239
end
240240

241241
it 'deletes before inserting' do
242-
subject.delete_insert(@statements, [@statements.first])
243-
is_expected.to contain_exactly @statements.first
242+
subject.delete_insert(@rdf_mutable_iv_statements, [@rdf_mutable_iv_statements.first])
243+
is_expected.to contain_exactly @rdf_mutable_iv_statements.first
244244
end
245245

246246
it 'deletes patterns' do
@@ -276,7 +276,7 @@
276276
if subject.mutable? && subject.supports?(:atomic_write)
277277
contents = subject.statements.to_a
278278

279-
expect { subject.delete_insert(@statements, [nil]) }
279+
expect { subject.delete_insert(@rdf_mutable_iv_statements, [nil]) }
280280
.to raise_error ArgumentError
281281
expect(subject.statements).to contain_exactly(*contents)
282282
end

lib/rdf/spec/queryable.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
raise 'querable must be set with `let(:queryable)' unless
88
defined? queryable
99

10-
@doap = RDF::Spec::QUADS_FILE
11-
@statements = RDF::Spec.quads
10+
@rdf_queryable_iv_doap = RDF::Spec::QUADS_FILE
11+
@rdf_queryable_iv_statements = RDF::Spec.quads
1212

1313
if queryable.empty?
1414
if (queryable.writable? rescue false)
15-
queryable.insert(*@statements)
15+
queryable.insert(*@rdf_queryable_iv_statements)
1616
elsif queryable.respond_to?(:<<)
17-
@statements.each { |statement| queryable << statement }
17+
@rdf_queryable_iv_statements.each { |statement| queryable << statement }
1818
else
19-
raise "queryable must respond to #<< or be pre-populated with the statements in #{@doap} in a before(:each) block"
19+
raise "queryable must respond to #<< or be pre-populated with the statements in #{@rdf_queryable_iv_doap} in a before(:each) block"
2020
end
2121
end
2222
end
@@ -95,7 +95,7 @@
9595
pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: nil)
9696
solutions = []
9797
subject.send(method, pattern) {|s| solutions << s}
98-
expect(solutions.size).to eq @statements.size
98+
expect(solutions.size).to eq @rdf_queryable_iv_statements.size
9999
end
100100

101101
it "returns statements from named graphs with variable graph_name" do
@@ -114,7 +114,7 @@
114114
pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: RDF::URI("http://ar.to/#self"))
115115
solutions = []
116116
subject.send(method, pattern) {|s| solutions << s}
117-
expect(solutions.size).to eq File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
117+
expect(solutions.size).to eq File.readlines(@rdf_queryable_iv_doap).grep(/^<http:\/\/ar.to\/\#self>/).size
118118
end
119119
end
120120
end
@@ -233,22 +233,22 @@
233233
end
234234

235235
it "returns the correct number of results for array queries" do
236-
expect(subject.query([nil, nil, nil]).size).to eq @statements.size
237-
expect(subject.query([resource, nil, nil]).size).to eq File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
238-
expect(subject.query([RDF::URI("http://ar.to/#self"), nil, nil]).size).to eq File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
236+
expect(subject.query([nil, nil, nil]).size).to eq @rdf_queryable_iv_statements.size
237+
expect(subject.query([resource, nil, nil]).size).to eq File.readlines(@rdf_queryable_iv_doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
238+
expect(subject.query([RDF::URI("http://ar.to/#self"), nil, nil]).size).to eq File.readlines(@rdf_queryable_iv_doap).grep(/^<http:\/\/ar.to\/\#self>/).size
239239
expect(subject.query([resource, RDF::URI("http://usefulinc.com/ns/doap#name"), nil]).size).to eq 1
240240
expect(subject.query([nil, nil, RDF::URI("http://usefulinc.com/ns/doap#Project")]).size).to eq 1
241241
end
242242

243243
it "returns the correct number of results for hash queries" do
244-
expect(subject.query({}).size).to eq @statements.size
245-
expect(subject.query(subject: resource).size).to eq File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
244+
expect(subject.query({}).size).to eq @rdf_queryable_iv_statements.size
245+
expect(subject.query(subject: resource).size).to eq File.readlines(@rdf_queryable_iv_doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
246246
expect(subject.query(subject: resource, predicate: RDF::URI("http://usefulinc.com/ns/doap#name")).size).to eq 1
247247
expect(subject.query(object: RDF::URI("http://usefulinc.com/ns/doap#Project")).size).to eq 1
248248
end
249249

250250
it "returns the correct number of results for query queries" do
251-
expect(subject.query(query).size).to eq @statements.size
251+
expect(subject.query(query).size).to eq @rdf_queryable_iv_statements.size
252252
end
253253
end
254254
end

lib/rdf/spec/repository.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
raise 'repository must be set with `let(:repository)' unless
88
defined? repository
99

10-
@statements = RDF::Spec.quads
1110
if repository.empty? && repository.writable?
12-
repository.insert(*@statements)
11+
repository.insert(*RDF::Spec.quads)
1312
elsif repository.empty?
1413
raise "+@repository+ must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
1514
end

lib/rdf/spec/transactable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RSpec.shared_examples 'an RDF::Transactable' do
44
include RDF::Spec::Matchers
55

6-
let(:statements) { RDF::Spec.quads }
6+
let(:statements) { @rdf_transactable_iv_statements = RDF::Spec.quads }
77

88
before do
99
raise '`transactable` must be set with `let(:transactable)`' unless
@@ -34,7 +34,7 @@
3434

3535
expect do
3636
subject.transaction(mutable: true) do
37-
delete(*@statements)
37+
delete(*statements)
3838
raise 'my error'
3939
end
4040
end.to raise_error RuntimeError

0 commit comments

Comments
 (0)