rdf-spec 1.0.9 → 1.1.0.p1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,184 +7,154 @@ module RDF_Queryable
7
7
  before :each do
8
8
  raise '+@queryable+ must be defined in a before(:each) block' unless instance_variable_get('@queryable')
9
9
 
10
- @doap = RDF::Spec::QUADS_FILE
11
- @statements = RDF::Spec.quads
10
+ @doap = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nq'))
11
+ @doaps = RDF::NQuads::Reader.new(File.open(@doap)).to_a
12
+ @statements = @doaps
12
13
 
13
14
  if @queryable.empty?
14
- if @queryable.respond_to?(:<<) && (@queryable.writable? rescue true)
15
- @statements.each { |statement| @queryable << statement }
15
+ if @queryable.respond_to?(:<<)
16
+ @doaps.each { |statement| @queryable << statement }
16
17
  else
17
18
  raise "@queryable must respond to #<< or be pre-populated with the statements in #{@doap} in a before(:each) block"
18
19
  end
19
20
  end
21
+
22
+ @subject = RDF::URI('http://rubygems.org/gems/rdf')
20
23
  end
21
- let(:resource) {RDF::URI('http://rubygems.org/gems/rdf')}
22
- let(:literal) {RDF::Literal.new('J. Random Hacker')}
23
24
 
24
25
  describe RDF::Queryable do
25
- subject {@queryable}
26
- let(:query) {RDF::Query.new {pattern [:s, :p, :o]}}
27
-
28
26
  ##
29
27
  # @see RDF::Queryable#query
30
28
  describe "#query" do
31
- it {should respond_to(:query)}
29
+ it "should respond to #query" do
30
+ @queryable.should respond_to(:query)
31
+ end
32
32
 
33
33
  context "when called" do
34
34
  it "requires an argument" do
35
- expect { subject.query }.to raise_error(ArgumentError)
35
+ lambda { @queryable.query }.should raise_error(ArgumentError)
36
36
  end
37
37
 
38
38
  it "accepts a pattern argument" do
39
- expect { subject.query(RDF::Query::Pattern.new(nil, nil, nil)) }.not_to raise_error
40
- expect { subject.query(RDF::Query::Pattern.new(:s, :p, :o)) }.not_to raise_error
39
+ lambda { @queryable.query(RDF::Query::Pattern.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
40
+ lambda { @queryable.query(RDF::Query::Pattern.new(:s, :p, :o)) }.should_not raise_error(ArgumentError)
41
41
  end
42
42
 
43
43
  it "accepts a statement argument" do
44
- expect { subject.query(RDF::Statement.new(nil, nil, nil)) }.not_to raise_error
44
+ lambda { @queryable.query(RDF::Statement.new(nil, nil, nil)) }.should_not raise_error(ArgumentError)
45
45
  end
46
46
 
47
47
  it "accepts a triple argument" do
48
- expect { subject.query([nil, nil, nil]) }.not_to raise_error
48
+ lambda { @queryable.query([nil, nil, nil]) }.should_not raise_error(ArgumentError)
49
49
  end
50
50
 
51
51
  it "accepts a quad argument" do
52
- expect { subject.query([nil, nil, nil, nil]) }.not_to raise_error
52
+ lambda { @queryable.query([nil, nil, nil, nil]) }.should_not raise_error(ArgumentError)
53
53
  end
54
54
 
55
55
  it "accepts a hash argument" do
56
- expect { subject.query({}) }.not_to raise_error
57
- end
58
-
59
- it "accepts an RDF::Query argument" do
60
- expect { subject.query(RDF::Query.new) }.not_to raise_error
56
+ lambda { @queryable.query({}) }.should_not raise_error(ArgumentError)
61
57
  end
62
58
 
63
59
  it "does not alter a given hash argument" do
64
- query = {:subject => resource, :predicate => RDF::DOAP.name, :object => RDF::FOAF.Person}
60
+ query = {:subject => @subject, :predicate => RDF::DOAP.name, :object => RDF::FOAF.Person}
65
61
  original_query = query.dup
66
- subject.query(query)
67
- expect(query).to eq original_query
62
+ @queryable.query(query)
63
+ query.should == original_query
68
64
  end
69
65
 
70
66
  it "rejects other kinds of arguments" do
71
- expect { subject.query(nil) }.to raise_error(ArgumentError)
67
+ lambda { @queryable.query(nil) }.should raise_error(ArgumentError)
72
68
  end
73
69
 
74
70
  context "with a block" do
75
- context "with a triple argument" do
76
- it "yields statements" do
77
- subject.query([nil, nil, nil]) do |statement|
78
- expect(statement).to be_a_statement
79
- expect(statement).not_to be_a RDF::Query::Solution
80
- end
81
- end
82
-
83
- it "calls #query_pattern" do
84
- expect(subject).to receive(:query_pattern)
85
- expect(subject).not_to receive(:query_execute)
86
- subject.query([:s, :p, :o]) {}
87
- end
88
- end
89
- context "with a Query argument" do
90
- it "yields statements" do
91
- subject.query(query) do |solution|
92
- expect(solution).not_to be_a_statement
93
- expect(solution).to be_a RDF::Query::Solution
94
- end
95
- end
96
-
97
- it "calls #query_execute" do
98
- expect(subject).to receive(:query_execute)
99
- expect(subject).not_to receive(:query_pattern)
100
- subject.query(query) {}
71
+ it "yields statements" do
72
+ @queryable.query([nil, nil, nil]) do |statement|
73
+ statement.should be_a_statement
101
74
  end
102
75
  end
103
76
  end
104
77
 
105
78
  context "without a block" do
106
79
  it "returns an enumerator" do
107
- expect(subject.query([nil, nil, nil])).to be_an_enumerator
80
+ @queryable.query([nil, nil, nil]).should be_an_enumerator
108
81
  end
109
82
 
110
83
  it "returns an enumerable enumerator" do
111
- expect(subject.query([nil, nil, nil])).to be_enumerable
84
+ @queryable.query([nil, nil, nil]).should be_enumerable
112
85
  end
113
86
 
114
87
  it "returns a queryable enumerator" do
115
- expect(subject.query([nil, nil, nil])).to be_queryable
88
+ @queryable.query([nil, nil, nil]).should be_queryable
116
89
  end
117
90
 
118
- it "returns statements given a triple" do
119
- subject.query([nil, nil, nil]).each do |statement|
120
- expect(statement).to be_a_statement
121
- expect(statement).not_to be_a RDF::Query::Solution
122
- end
123
- end
124
-
125
- it "returns solutions given a query" do
126
- subject.query(query).each do |solution|
127
- expect(solution).not_to be_a_statement
128
- expect(solution).to be_a RDF::Query::Solution
91
+ it "returns statements" do
92
+ @queryable.query([nil, nil, nil]).each do |statement|
93
+ statement.should be_a_statement
129
94
  end
130
95
  end
131
96
 
132
97
  it "returns the correct number of results for array queries" do
133
- expect(subject.query([nil, nil, nil]).size).to eq @statements.size
134
- expect(subject.query([resource, nil, nil]).size).to eq File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
135
- expect(subject.query([RDF::URI("http://ar.to/#self"), nil, nil]).size).to eq File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
136
- expect(subject.query([resource, RDF::DOAP.name, nil]).size).to eq 1
137
- expect(subject.query([nil, nil, RDF::DOAP.Project]).size).to eq 1
98
+ @queryable.query([nil, nil, nil]).size.should == @statements.size
99
+ @queryable.query([@subject, nil, nil]).size.should == File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
100
+ @queryable.query([RDF::URI("http://ar.to/#self"), nil, nil]).size.should == File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
101
+ @queryable.query([@subject, RDF::DOAP.name, nil]).size.should == 1
102
+ @queryable.query([nil, nil, RDF::DOAP.Project]).size.should == 1
138
103
  end
139
104
 
140
105
  it "returns the correct number of results for hash queries" do
141
- expect(subject.query({}).size).to eq @statements.size
142
- expect(subject.query(:subject => resource).size).to eq File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
143
- expect(subject.query(:subject => resource, :predicate => RDF::DOAP.name).size).to eq 1
144
- expect(subject.query(:object => RDF::DOAP.Project).size).to eq 1
145
- end
146
-
147
- it "returns the correct number of results for query queries" do
148
- expect(subject.query(query).size).to eq @statements.size
106
+ @queryable.query({}).size.should == @statements.size
107
+ @queryable.query(:subject => @subject) .size.should == File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
108
+ @queryable.query(:subject => @subject, :predicate => RDF::DOAP.name).size.should == 1
109
+ @queryable.query(:object => RDF::DOAP.Project).size.should == 1
149
110
  end
150
111
  end
151
112
 
152
113
  context "with specific patterns from SPARQL" do
153
114
  context "triple pattern combinations" do
154
115
  it "?s p o" do
155
- expect(subject.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal.new(1)).to_a).to(
156
- include *[RDF::Statement.new(RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1), RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
157
- )
116
+ @queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal.new(1)).to_a.should ==
117
+ [RDF::Statement.new(RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1), RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
158
118
  end
159
119
 
160
120
  it "s ?p o" do
161
- expect(subject.query(:subject => RDF::URI("http://example.org/xi2"), :object => RDF::Literal.new(1)).to_a).to(
162
- include *[RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
163
- )
121
+ @queryable.query(:subject => RDF::URI("http://example.org/xi2"), :object => RDF::Literal.new(1)).to_a.should ==
122
+ [RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
164
123
  end
165
124
  end
166
125
 
167
126
  # From data-r2/expr-equals
168
127
  context "data/r2/expr-equals" do
169
128
  context "graph-1" do
170
- subject {@queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Integer.new(1)).to_a}
171
- its(:count) {should == 2}
129
+ before(:each) do
130
+ @solutions = @queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Integer.new(1)).to_a
131
+ end
172
132
 
173
133
  it "has two solutions" do
174
- expect(subject.any? {|s| s.subject == RDF::URI("http://example.org/xi1")}).to be_true
134
+ @solutions.count.should == 2
135
+ end
136
+
137
+ it "has xi1 as a solution" do
138
+ @solutions.any? {|s| s.subject == RDF::URI("http://example.org/xi1")}.should be_true
175
139
  end
176
140
 
177
141
  it "has xi2 as a solution" do
178
- expect(subject.any? {|s| s.subject == RDF::URI("http://example.org/xi2")}).to be_true
142
+ @solutions.any? {|s| s.subject == RDF::URI("http://example.org/xi2")}.should be_true
179
143
  end
180
144
  end
181
145
 
146
+
182
147
  context "graph-2" do
183
- subject {@queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Double.new("1.0e0")).to_a}
184
- its(:count) {should == 1}
148
+ before(:each) do
149
+ @solutions = @queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Double.new("1.0e0")).to_a
150
+ end
151
+
152
+ it "has one solution" do
153
+ @solutions.count.should == 1
154
+ end
185
155
 
186
156
  it "has xd1 as a solution" do
187
- expect(subject.any? {|s| s.subject == RDF::URI("http://example.org/xd1")}).to be_true
157
+ @solutions.any? {|s| s.subject == RDF::URI("http://example.org/xd1")}.should be_true
188
158
  end
189
159
  end
190
160
  end
@@ -192,49 +162,30 @@ module RDF_Queryable
192
162
  end
193
163
  end
194
164
 
195
- ##
196
- # @see RDF::Queryable#query_execute
197
- describe "#query_execute" do
198
- it "defines a protected #query_execute method" do
199
- expect(subject.class.protected_method_defined?(:query_execute)).to be_true
200
- end
201
-
202
- context "when called" do
203
- it "requires an argument" do
204
- expect { subject.send(:query_execute) }.to raise_error(ArgumentError)
205
- end
206
-
207
- it "yields to the given block" do
208
- expect {|b| subject.send(:query_execute, query, &b)}.to yield_control.exactly(@queryable.count).times
209
- end
210
-
211
- it "yields solutions" do
212
- subject.send(:query_execute, query) do |solution|
213
- expect(solution).to be_a RDF::Query::Solution
214
- end
215
- end
216
- end
217
- end
218
-
219
165
  ##
220
166
  # @see RDF::Queryable#query_pattern
221
167
  describe "#query_pattern" do
222
168
  it "defines a protected #query_pattern method" do
223
- expect(subject.class.protected_method_defined?(:query_pattern)).to be_true
169
+ @queryable.class.protected_method_defined?(:query_pattern).should be_true
224
170
  end
225
171
 
226
172
  context "when called" do
227
173
  it "requires an argument" do
228
- expect { subject.send(:query_pattern) }.to raise_error(ArgumentError)
174
+ lambda { @queryable.send(:query_pattern) }.should raise_error(ArgumentError)
229
175
  end
230
176
 
231
177
  it "yields to the given block" do
232
- expect {|b| subject.send(:query_pattern, RDF::Query::Pattern.new, &b)}.to yield_control.exactly(@queryable.count).times
178
+ called = false
179
+ @queryable.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
180
+ called = true
181
+ break
182
+ end
183
+ called.should be_true
233
184
  end
234
185
 
235
186
  it "yields statements" do
236
- subject.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
237
- expect(statement).to be_a_statement
187
+ @queryable.send(:query_pattern, RDF::Query::Pattern.new) do |statement|
188
+ statement.should be_a_statement
238
189
  end
239
190
  end
240
191
 
@@ -251,8 +202,8 @@ module RDF_Queryable
251
202
  pattern = RDF::Query::Pattern.from(pattern)
252
203
  it "returns #{result.inspect} given #{pattern.inspect}" do
253
204
  solutions = []
254
- subject.send(:query_pattern, pattern) {|s| solutions << s}
255
- expect(solutions).to eq result
205
+ @queryable.send(:query_pattern, pattern) {|s| solutions << s}
206
+ solutions.should == result
256
207
  end
257
208
  end
258
209
  end
@@ -261,34 +212,34 @@ module RDF_Queryable
261
212
  it "returns statements from all contexts with no context" do
262
213
  pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => nil)
263
214
  solutions = []
264
- subject.send(:query_pattern, pattern) {|s| solutions << s}
265
- expect(solutions.size).to eq @statements.size
215
+ @queryable.send(:query_pattern, pattern) {|s| solutions << s}
216
+ solutions.size.should == @statements.size
266
217
  end
267
218
 
268
219
  it "returns statements from unnamed contexts with false context" do
269
220
  pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => false)
270
221
  solutions = []
271
- subject.send(:query_pattern, pattern) {|s| solutions << s}
272
- context_statements = subject.statements.reject {|st| st.has_context?}.length
273
- expect(solutions.size).to eq context_statements
222
+ @queryable.send(:query_pattern, pattern) {|s| solutions << s}
223
+ context_statements = @queryable.statements.reject {|st| st.has_context?}.length
224
+ solutions.size.should == context_statements
274
225
  end
275
226
 
276
227
  it "returns statements from named contexts with variable context" do
277
- unless subject.contexts.to_a.empty?
228
+ unless @queryable.contexts.to_a.empty?
278
229
  pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => :c)
279
230
  solutions = []
280
- subject.send(:query_pattern, pattern) {|s| solutions << s}
281
- context_statements = subject.statements.select {|st| st.has_context?}.length
282
- expect(solutions.size).to eq context_statements
231
+ @queryable.send(:query_pattern, pattern) {|s| solutions << s}
232
+ context_statements = @queryable.statements.select {|st| st.has_context?}.length
233
+ solutions.size.should == context_statements
283
234
  end
284
235
  end
285
236
 
286
237
  it "returns statements from specific context with URI context" do
287
- unless subject.contexts.to_a.empty?
238
+ unless @queryable.contexts.to_a.empty?
288
239
  pattern = RDF::Query::Pattern.new(nil, nil, nil, :context => RDF::URI("http://ar.to/#self"))
289
240
  solutions = []
290
- subject.send(:query_pattern, pattern) {|s| solutions << s}
291
- expect(solutions.size).to eq File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
241
+ @queryable.send(:query_pattern, pattern) {|s| solutions << s}
242
+ solutions.size.should == File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
292
243
  end
293
244
  end
294
245
  end
@@ -298,64 +249,68 @@ module RDF_Queryable
298
249
  ##
299
250
  # @see RDF::Queryable#first
300
251
  describe "#first" do
301
- let(:failing_pattern) {[RDF::Node.new] * 3}
252
+ before :all do
253
+ @failing_pattern = [RDF::Node.new] * 3
254
+ end
302
255
 
303
256
  it "should respond to #first" do
304
- expect(subject).to respond_to(:first)
257
+ @queryable.should respond_to(:first)
305
258
  end
306
259
 
307
260
  it "returns enumerator without a pattern" do
308
- expect { subject.first }.not_to raise_error
309
- expect(subject.first).to eq subject.each.first # uses an Enumerator
261
+ lambda { @queryable.first }.should_not raise_error(ArgumentError)
262
+ @queryable.first.should == @queryable.each.first # uses an Enumerator
310
263
  end
311
264
 
312
265
  it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
313
- matching_patterns = [[nil, nil, nil], subject.each.first]
266
+ matching_patterns = [[nil, nil, nil], @queryable.each.first]
314
267
  matching_patterns.each do |matching_pattern|
315
- expect(subject.first(matching_pattern)).to eq subject.query(matching_pattern).each.first
268
+ @queryable.first(matching_pattern).should == @queryable.query(matching_pattern).each.first
316
269
  end
317
270
  end
318
271
 
319
272
  it "returns nil when the pattern fails to match anything" do
320
- expect(subject.first(failing_pattern)).to be_nil
273
+ @queryable.first(@failing_pattern).should be_nil
321
274
  end
322
275
 
323
276
  it "returns nil when self is empty" do
324
277
  queryable = [].extend(RDF::Queryable)
325
- expect(queryable.first).to be_nil
326
- expect(queryable.first(failing_pattern)).to be_nil
278
+ queryable.first.should be_nil
279
+ queryable.first(@failing_pattern).should be_nil
327
280
  end
328
281
  end
329
282
 
330
283
  ##
331
284
  # @see RDF::Queryable#first_subject
332
285
  describe "#first_subject" do
333
- let(:failing_pattern) {[RDF::Node.new, nil, nil]}
286
+ before :all do
287
+ @failing_pattern = [RDF::Node.new, nil, nil]
288
+ end
334
289
 
335
290
  it "should respond to #first_subject" do
336
- expect(subject).to respond_to(:first_subject)
291
+ @queryable.should respond_to(:first_subject)
337
292
  end
338
293
 
339
294
  it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
340
- expect { subject.first_subject }.not_to raise_error
341
- expect(subject.first_subject).to eq subject.first.subject
295
+ lambda { @queryable.first_subject }.should_not raise_error(ArgumentError)
296
+ @queryable.first_subject.should == @queryable.first.subject
342
297
  end
343
298
 
344
299
  it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
345
- matching_patterns = [[nil, nil, nil], [subject.first.subject, nil, nil]]
300
+ matching_patterns = [[nil, nil, nil], [@queryable.first.subject, nil, nil]]
346
301
  matching_patterns.each do |matching_pattern|
347
- expect(subject.first_subject(matching_pattern)).to eq subject.query(matching_pattern).first.subject
302
+ @queryable.first_subject(matching_pattern).should == @queryable.query(matching_pattern).first.subject
348
303
  end
349
304
  end
350
305
 
351
306
  it "returns nil when the pattern fails to match anything" do
352
- expect(subject.first_subject(failing_pattern)).to be_nil
307
+ @queryable.first_subject(@failing_pattern).should be_nil
353
308
  end
354
309
 
355
310
  it "returns nil when self is empty" do
356
311
  queryable = [].extend(RDF::Queryable)
357
- expect(queryable.first_subject).to be_nil
358
- expect(queryable.first_subject(failing_pattern)).to be_nil
312
+ queryable.first_subject.should be_nil
313
+ queryable.first_subject(@failing_pattern).should be_nil
359
314
  end
360
315
  end
361
316
 
@@ -363,30 +318,34 @@ module RDF_Queryable
363
318
  # @see RDF::Queryable#first_predicate
364
319
 
365
320
  describe "#first_predicate" do
366
- let(:failing_pattern) {[nil, RDF::Node.new, nil]}
321
+ before :all do
322
+ @failing_pattern = [nil, RDF::Node.new, nil]
323
+ end
367
324
 
368
- it {should respond_to(:first_predicate)}
325
+ it "should respond to #first_predicate" do
326
+ @queryable.should respond_to(:first_predicate)
327
+ end
369
328
 
370
329
  it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
371
- expect { subject.first_predicate }.not_to raise_error
372
- expect(subject.first_predicate).to eq subject.first.predicate
330
+ lambda { @queryable.first_predicate }.should_not raise_error(ArgumentError)
331
+ @queryable.first_predicate.should == @queryable.first.predicate
373
332
  end
374
333
 
375
334
  it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
376
- matching_patterns = [[nil, nil, nil], [nil, subject.first.predicate, nil]]
335
+ matching_patterns = [[nil, nil, nil], [nil, @queryable.first.predicate, nil]]
377
336
  matching_patterns.each do |matching_pattern|
378
- expect(subject.first_predicate(matching_pattern)).to eq subject.query(matching_pattern).first.predicate
337
+ @queryable.first_predicate(matching_pattern).should == @queryable.query(matching_pattern).first.predicate
379
338
  end
380
339
  end
381
340
 
382
341
  it "returns nil when the pattern fails to match anything" do
383
- expect(subject.first_predicate(failing_pattern)).to be_nil
342
+ @queryable.first_predicate(@failing_pattern).should be_nil
384
343
  end
385
344
 
386
345
  it "returns nil when self is empty" do
387
346
  queryable = [].extend(RDF::Queryable)
388
- expect(queryable.first_predicate).to be_nil
389
- expect(queryable.first_predicate(failing_pattern)).to be_nil
347
+ queryable.first_predicate.should be_nil
348
+ queryable.first_predicate(@failing_pattern).should be_nil
390
349
  end
391
350
  end
392
351
 
@@ -394,67 +353,76 @@ module RDF_Queryable
394
353
  # @see RDF::Queryable#first_object
395
354
 
396
355
  describe "#first_object" do
397
- let(:failing_pattern) {[nil, nil, RDF::Node.new]}
398
- it {should respond_to(:first_object)}
356
+ before :all do
357
+ @failing_pattern = [nil, nil, RDF::Node.new]
358
+ end
359
+
360
+ it "should respond to #first_object" do
361
+ @queryable.should respond_to(:first_object)
362
+ end
399
363
 
400
364
  it "returns enurator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
401
- expect { subject.first_object }.not_to raise_error
402
- expect(subject.first_object).to eq subject.first.object
365
+ lambda { @queryable.first_object }.should_not raise_error(ArgumentError)
366
+ @queryable.first_object.should == @queryable.first.object
403
367
  end
404
368
 
405
369
  it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
406
- matching_patterns = [[nil, nil, nil], [nil, nil, subject.first.object]]
370
+ matching_patterns = [[nil, nil, nil], [nil, nil, @queryable.first.object]]
407
371
  matching_patterns.each do |matching_pattern|
408
- expect(subject.first_object(matching_pattern)).to eq subject.query(matching_pattern).first.object
372
+ @queryable.first_object(matching_pattern).should == @queryable.query(matching_pattern).first.object
409
373
  end
410
374
  end
411
375
 
412
376
  it "returns nil when the pattern fails to match anything" do
413
- expect(subject.first_object(failing_pattern)).to be_nil
377
+ @queryable.first_object(@failing_pattern).should be_nil
414
378
  end
415
379
 
416
380
  it "returns nil when self is empty" do
417
381
  queryable = [].extend(RDF::Queryable)
418
- expect(queryable.first_object).to be_nil
419
- expect(queryable.first_object(failing_pattern)).to be_nil
382
+ queryable.first_object.should be_nil
383
+ queryable.first_object(@failing_pattern).should be_nil
420
384
  end
421
385
  end
422
386
 
423
387
  ##
424
388
  # @see RDF::Queryable#first_literal
425
389
 
390
+ it "returns to #first_literal" do
391
+ @queryable.should respond_to(:first_literal)
392
+ end
393
+
426
394
  describe "#first_literal" do
427
- let(:failing_pattern) {[nil, nil, RDF::Node.new]}
428
- let(:resource) {RDF::Node.new}
429
- subject {
430
- RDF::Graph.new do |graph|
431
- graph << [resource, RDF.type, RDF::DOAP.Project]
432
- graph << [resource, RDF::DC.creator, RDF::URI.new('http://example.org/#jhacker')]
433
- graph << [resource, RDF::DC.creator, literal]
395
+ before :each do
396
+ # FIXME: these tests should be using the provided @queryable, if possible.
397
+ @queryable = RDF::Graph.new do |graph|
398
+ @subject = RDF::Node.new
399
+ graph << [@subject, RDF.type, RDF::DOAP.Project]
400
+ graph << [@subject, RDF::DC.creator, RDF::URI.new('http://example.org/#jhacker')]
401
+ graph << [@subject, RDF::DC.creator, @literal = RDF::Literal.new('J. Random Hacker')]
434
402
  end
435
- }
436
- it {should respond_to(:first_literal)}
403
+ @failing_pattern = [nil, nil, RDF::Node.new]
404
+ end
437
405
 
438
406
  it "returns a literal without a pattern" do
439
- expect { subject.first_literal }.not_to raise_error
440
- expect(subject.first_literal).to eq literal
407
+ lambda { @queryable.first_literal }.should_not raise_error(ArgumentError)
408
+ @queryable.first_literal.should == @literal
441
409
  end
442
410
 
443
411
  it "returns the correct value when the pattern matches" do
444
- matching_patterns = [[nil, nil, nil], [resource, nil, nil], [nil, RDF::DC.creator, nil], [nil, nil, literal]]
412
+ matching_patterns = [[nil, nil, nil], [@subject, nil, nil], [nil, RDF::DC.creator, nil], [nil, nil, @literal]]
445
413
  matching_patterns.each do |matching_pattern|
446
- expect(subject.first_literal(matching_pattern)).to eq literal
414
+ @queryable.first_literal(matching_pattern).should == @literal
447
415
  end
448
416
  end
449
417
 
450
418
  it "returns nil when the pattern fails to match anything" do
451
- expect(subject.first_literal(failing_pattern)).to be_nil
419
+ @queryable.first_literal(@failing_pattern).should be_nil
452
420
  end
453
421
 
454
422
  it "returns nil when self is empty" do
455
423
  queryable = [].extend(RDF::Queryable)
456
- expect(queryable.first_literal).to be_nil
457
- expect(queryable.first_literal(failing_pattern)).to be_nil
424
+ queryable.first_literal.should be_nil
425
+ queryable.first_literal(@failing_pattern).should be_nil
458
426
  end
459
427
  end
460
428
 
@@ -462,35 +430,40 @@ module RDF_Queryable
462
430
  # @see RDF::Queryable#first_value
463
431
 
464
432
  describe "#first_value" do
465
- let(:failing_pattern) {[nil, nil, RDF::Node.new]}
466
- it {should respond_to(:first_value)}
433
+ before :all do
434
+ @failing_pattern = [nil, nil, RDF::Node.new]
435
+ end
436
+
437
+ it "should respond to #first_value" do
438
+ @queryable.should respond_to(:first_value)
439
+ end
467
440
 
468
441
  it "returns first literal without a pattern" do
469
- expect { subject.first_value }.not_to raise_error
470
- expect(subject.first_value).to eq subject.first_literal.value
442
+ lambda { @queryable.first_value }.should_not raise_error(ArgumentError)
443
+ @queryable.first_value.should == @queryable.first_literal.value
471
444
  end
472
445
 
473
446
  it "returns the correct value when the pattern matches" do
474
447
  matching_patterns = []
475
- subject.each do |statement|
448
+ @queryable.each do |statement|
476
449
  if statement.object.is_a?(RDF::Literal)
477
450
  matching_pattern = [statement.subject, statement.predicate, nil]
478
451
  unless matching_patterns.include?(matching_pattern)
479
452
  matching_patterns << matching_pattern
480
- expect(subject.first_value(matching_pattern)).to eq subject.first_literal(matching_pattern).value
453
+ @queryable.first_value(matching_pattern).should == @queryable.first_literal(matching_pattern).value
481
454
  end
482
455
  end
483
456
  end
484
457
  end
485
458
 
486
459
  it "returns nil when the pattern fails to match anything" do
487
- expect(subject.first_value(failing_pattern)).to be_nil
460
+ @queryable.first_value(@failing_pattern).should be_nil
488
461
  end
489
462
 
490
463
  it "returns nil when self is empty" do
491
464
  queryable = [].extend(RDF::Queryable)
492
- expect(queryable.first_value).to be_nil
493
- expect(queryable.first_value(failing_pattern)).to be_nil
465
+ queryable.first_value.should be_nil
466
+ queryable.first_value(@failing_pattern).should be_nil
494
467
  end
495
468
  end
496
469
  end