rdf-spec 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.1.9
@@ -6,7 +6,7 @@ share_as :RDF_Queryable do
6
6
 
7
7
  before :each do
8
8
  # RDF::Queryable cares about the contents of this file too much to let someone set it
9
- @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
9
+ @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
10
10
  raise '+@queryable+ must be defined in a before(:each) block' unless instance_variable_get('@queryable')
11
11
  raise '+@subject+ must be defined in a before(:each) block' unless instance_variable_get('@subject')
12
12
  if @queryable.empty?
@@ -18,6 +18,9 @@ share_as :RDF_Queryable do
18
18
  end
19
19
  end
20
20
 
21
+ ##
22
+ # @see RDF::Queryable#query
23
+
21
24
  it "should support #query" do
22
25
  @queryable.respond_to?(:query).should be_true
23
26
  end
@@ -71,10 +74,233 @@ share_as :RDF_Queryable do
71
74
  end
72
75
 
73
76
  it "should not alter a given hash argument" do
74
- query = { :subject => @subject, :predicate => RDF::DOAP.name, :object => RDF::FOAF.Person }
77
+ query = {:subject => @subject, :predicate => RDF::DOAP.name, :object => RDF::FOAF.Person}
75
78
  original_query = query.dup
76
79
  result = @queryable.query(query)
77
80
  query.should == original_query
78
81
  end
79
82
  end
83
+
84
+ ##
85
+ # @see RDF::Queryable#first
86
+
87
+ it "should support #first" do
88
+ @queryable.respond_to?(:first).should be_true
89
+ end
90
+
91
+ context "#first" do
92
+ before :all do
93
+ @failing_pattern = [RDF::Node.new] * 3
94
+ end
95
+
96
+ it "should be callable without a pattern" do
97
+ lambda { @queryable.first }.should_not raise_error(ArgumentError)
98
+ @queryable.first.should == @queryable.each.first # uses an Enumerator
99
+ end
100
+
101
+ it "should return the correct value when the pattern matches" do
102
+ matching_patterns = [[nil, nil, nil], @queryable.each.first]
103
+ matching_patterns.each do |matching_pattern|
104
+ @queryable.first(matching_pattern).should == @queryable.query(matching_pattern).each.first
105
+ end
106
+ end
107
+
108
+ it "should return nil when the pattern fails to match anything" do
109
+ @queryable.first(@failing_pattern).should be_nil
110
+ end
111
+
112
+ it "should return nil when self is empty" do
113
+ queryable = [].extend(RDF::Queryable)
114
+ queryable.first.should be_nil
115
+ queryable.first(@failing_pattern).should be_nil
116
+ end
117
+ end
118
+
119
+ ##
120
+ # @see RDF::Queryable#first_subject
121
+
122
+ it "should support #first_subject" do
123
+ @queryable.respond_to?(:first_subject).should be_true
124
+ end
125
+
126
+ context "#first_subject" do
127
+ before :all do
128
+ @failing_pattern = [RDF::Node.new, nil, nil]
129
+ end
130
+
131
+ it "should be callable without a pattern" do
132
+ lambda { @queryable.first_subject }.should_not raise_error(ArgumentError)
133
+ @queryable.first_subject.should == @queryable.first.subject
134
+ end
135
+
136
+ it "should return the correct value when the pattern matches" do
137
+ matching_patterns = [[nil, nil, nil], [@queryable.first.subject, nil, nil]]
138
+ matching_patterns.each do |matching_pattern|
139
+ @queryable.first_subject(matching_pattern).should == @queryable.query(matching_pattern).first.subject
140
+ end
141
+ end
142
+
143
+ it "should return nil when the pattern fails to match anything" do
144
+ @queryable.first_subject(@failing_pattern).should be_nil
145
+ end
146
+
147
+ it "should return nil when self is empty" do
148
+ queryable = [].extend(RDF::Queryable)
149
+ queryable.first_subject.should be_nil
150
+ queryable.first_subject(@failing_pattern).should be_nil
151
+ end
152
+ end
153
+
154
+ ##
155
+ # @see RDF::Queryable#first_predicate
156
+
157
+ it "should support #first_predicate" do
158
+ @queryable.respond_to?(:first_predicate).should be_true
159
+ end
160
+
161
+ context "#first_predicate" do
162
+ before :all do
163
+ @failing_pattern = [nil, RDF::Node.new, nil]
164
+ end
165
+
166
+ it "should be callable without a pattern" do
167
+ lambda { @queryable.first_predicate }.should_not raise_error(ArgumentError)
168
+ @queryable.first_predicate.should == @queryable.first.predicate
169
+ end
170
+
171
+ it "should return the correct value when the pattern matches" do
172
+ matching_patterns = [[nil, nil, nil], [nil, @queryable.first.predicate, nil]]
173
+ matching_patterns.each do |matching_pattern|
174
+ @queryable.first_predicate(matching_pattern).should == @queryable.query(matching_pattern).first.predicate
175
+ end
176
+ end
177
+
178
+ it "should return nil when the pattern fails to match anything" do
179
+ @queryable.first_predicate(@failing_pattern).should be_nil
180
+ end
181
+
182
+ it "should return nil when self is empty" do
183
+ queryable = [].extend(RDF::Queryable)
184
+ queryable.first_predicate.should be_nil
185
+ queryable.first_predicate(@failing_pattern).should be_nil
186
+ end
187
+ end
188
+
189
+ ##
190
+ # @see RDF::Queryable#first_object
191
+
192
+ it "should support #first_object" do
193
+ @queryable.respond_to?(:first_object).should be_true
194
+ end
195
+
196
+ context "#first_object" do
197
+ before :all do
198
+ @failing_pattern = [nil, nil, RDF::Node.new]
199
+ end
200
+
201
+ it "should be callable without a pattern" do
202
+ lambda { @queryable.first_object }.should_not raise_error(ArgumentError)
203
+ @queryable.first_object.should == @queryable.first.object
204
+ end
205
+
206
+ it "should return the correct value when the pattern matches" do
207
+ matching_patterns = [[nil, nil, nil], [nil, nil, @queryable.first.object]]
208
+ matching_patterns.each do |matching_pattern|
209
+ @queryable.first_object(matching_pattern).should == @queryable.query(matching_pattern).first.object
210
+ end
211
+ end
212
+
213
+ it "should return nil when the pattern fails to match anything" do
214
+ @queryable.first_object(@failing_pattern).should be_nil
215
+ end
216
+
217
+ it "should return nil when self is empty" do
218
+ queryable = [].extend(RDF::Queryable)
219
+ queryable.first_object.should be_nil
220
+ queryable.first_object(@failing_pattern).should be_nil
221
+ end
222
+ end
223
+
224
+ ##
225
+ # @see RDF::Queryable#first_literal
226
+
227
+ it "should support #first_literal" do
228
+ @queryable.respond_to?(:first_literal).should be_true
229
+ end
230
+
231
+ context "#first_literal" do
232
+ before :each do
233
+ # FIXME: these tests should be using the provided @queryable, if possible.
234
+ @queryable = RDF::Graph.new do |graph|
235
+ @subject = RDF::Node.new
236
+ graph << [subject, RDF.type, RDF::DOAP.Project]
237
+ graph << [subject, RDF::DC.creator, RDF::URI.new('http://example.org/#jhacker')]
238
+ graph << [subject, RDF::DC.creator, @literal = RDF::Literal.new('J. Random Hacker')]
239
+ end
240
+ @failing_pattern = [nil, nil, RDF::Node.new]
241
+ end
242
+
243
+ it "should be callable without a pattern" do
244
+ lambda { @queryable.first_literal }.should_not raise_error(ArgumentError)
245
+ @queryable.first_literal.should == @literal
246
+ end
247
+
248
+ it "should return the correct value when the pattern matches" do
249
+ matching_patterns = [[nil, nil, nil], [@subject, nil, nil], [nil, RDF::DC.creator, nil], [nil, nil, @literal]]
250
+ matching_patterns.each do |matching_pattern|
251
+ @queryable.first_literal(matching_pattern).should == @literal
252
+ end
253
+ end
254
+
255
+ it "should return nil when the pattern fails to match anything" do
256
+ @queryable.first_literal(@failing_pattern).should be_nil
257
+ end
258
+
259
+ it "should return nil when self is empty" do
260
+ queryable = [].extend(RDF::Queryable)
261
+ queryable.first_literal.should be_nil
262
+ queryable.first_literal(@failing_pattern).should be_nil
263
+ end
264
+ end
265
+
266
+ ##
267
+ # @see RDF::Queryable#first_value
268
+
269
+ it "should support #first_value" do
270
+ @queryable.respond_to?(:first_value).should be_true
271
+ end
272
+
273
+ context "#first_value" do
274
+ before :all do
275
+ @failing_pattern = [nil, nil, RDF::Node.new]
276
+ end
277
+
278
+ it "should be callable without a pattern" do
279
+ lambda { @queryable.first_value }.should_not raise_error(ArgumentError)
280
+ @queryable.first_value.should == @queryable.first_literal.value
281
+ end
282
+
283
+ it "should return the correct value when the pattern matches" do
284
+ matching_patterns = []
285
+ @queryable.each do |statement|
286
+ if statement.object.is_a?(RDF::Literal)
287
+ matching_pattern = [statement.subject, statement.predicate, nil]
288
+ unless matching_patterns.include?(matching_pattern)
289
+ matching_patterns << matching_pattern
290
+ @queryable.first_value(matching_pattern).should == @queryable.first_literal(matching_pattern).value
291
+ end
292
+ end
293
+ end
294
+ end
295
+
296
+ it "should return nil when the pattern fails to match anything" do
297
+ @queryable.first_value(@failing_pattern).should be_nil
298
+ end
299
+
300
+ it "should return nil when self is empty" do
301
+ queryable = [].extend(RDF::Queryable)
302
+ queryable.first_value.should be_nil
303
+ queryable.first_value(@failing_pattern).should be_nil
304
+ end
305
+ end
80
306
  end
@@ -2,7 +2,7 @@ module RDF; module Spec
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 8
5
+ TINY = 9
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 8
9
- version: 0.1.8
8
+ - 9
9
+ version: 0.1.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Arto Bendiken
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-18 00:00:00 +02:00
18
+ date: 2010-04-21 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency