rdf-spec 0.3.8 → 0.3.9

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