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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.8
1
+ 0.3.9
data/lib/rdf/spec.rb CHANGED
@@ -24,7 +24,7 @@ module RDF
24
24
  # @enumerable = @statements.dup.extend(RDF::Enumerable)
25
25
  # end
26
26
  #
27
- # it_should_behave_like RDF_Enumerable
27
+ # include RDF_Enumerable
28
28
  # end
29
29
  #
30
30
  # @example Using the shared examples for `RDF::Repository`
@@ -35,7 +35,7 @@ module RDF
35
35
  # @repository = RDF::Repository.new
36
36
  # end
37
37
  #
38
- # it_should_behave_like RDF_Repository
38
+ # include RDF_Repository
39
39
  # end
40
40
  #
41
41
  # @see http://rubygems.org/gems/rdf
@@ -1,6 +1,7 @@
1
1
  require 'rdf/spec'
2
2
 
3
- share_as :RDF_Countable do
3
+ module RDF_Countable
4
+ extend RSpec::SharedContext
4
5
  include RDF::Spec::Matchers
5
6
 
6
7
  before :each do
@@ -18,7 +19,7 @@ share_as :RDF_Countable do
18
19
  end
19
20
  end
20
21
 
21
- describe "when counting items" do
22
+ describe RDF::Countable do
22
23
  it "responds to #empty?" do
23
24
  @countable.should respond_to(:empty?)
24
25
  end
@@ -14,10 +14,11 @@ require 'rdf/spec'
14
14
  # File.delete('test.db') if File.exists?('test.db')
15
15
  # end
16
16
  #
17
- # it_should_behave_like RDF_Repository
17
+ # include RDF_Repository
18
18
  # end
19
19
  #end
20
- share_as :RDF_Durable do
20
+ module RDF_Durable
21
+ extend RSpec::SharedContext
21
22
  include RDF::Spec::Matchers
22
23
 
23
24
  before :each do
@@ -26,25 +27,26 @@ share_as :RDF_Durable do
26
27
  @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
27
28
  end
28
29
 
30
+ describe RDF::Durable do
31
+ it "should support #durable?" do
32
+ @load_durable.call.should respond_to(:durable?)
33
+ [true,false].member?(@load_durable.call.durable?).should be_true
34
+ end
29
35
 
30
- it "should support #durable?" do
31
- @load_durable.call.should respond_to(:durable?)
32
- [true,false].member?(@load_durable.call.durable?).should be_true
33
- end
34
-
35
- it "should support #nondurable?" do
36
- @load_durable.call.should respond_to(:nondurable?)
37
- [true,false].member?(@load_durable.call.nondurable?).should be_true
38
- end
36
+ it "should support #nondurable?" do
37
+ @load_durable.call.should respond_to(:nondurable?)
38
+ [true,false].member?(@load_durable.call.nondurable?).should be_true
39
+ end
39
40
 
40
- it "should not be both durable and nondurable" do
41
- @load_durable.call.nondurable?.should_not == @load_durable.call.durable?
42
- end
41
+ it "should not be both durable and nondurable" do
42
+ @load_durable.call.nondurable?.should_not == @load_durable.call.durable?
43
+ end
43
44
 
44
- it "should save contents between instantiations" do
45
- if @load_durable.call.durable?
46
- @load_durable.call.load(@filename)
47
- @load_durable.call.count.should == File.readlines(@filename).size
45
+ it "should save contents between instantiations" do
46
+ if @load_durable.call.durable?
47
+ @load_durable.call.load(@filename)
48
+ @load_durable.call.count.should == File.readlines(@filename).size
49
+ end
48
50
  end
49
51
  end
50
52
  end
@@ -1,6 +1,7 @@
1
1
  require 'rdf/spec'
2
2
 
3
- share_as :RDF_Enumerable do
3
+ module RDF_Enumerable
4
+ extend RSpec::SharedContext
4
5
  include RDF::Spec::Matchers
5
6
 
6
7
  before :each do
@@ -20,415 +21,437 @@ share_as :RDF_Enumerable do
20
21
  @supports_context = @enumerable.respond_to?(:supports?) && @enumerable.supports?(:context)
21
22
  end
22
23
 
23
- describe "#supports?" do
24
- it "responds to #supports?" do
25
- @enumerable.respond_to?(:support?)
26
- end
27
- end
28
-
29
- context "when counting statements" do
30
- it "should respond to #empty?" do
31
- @enumerable.should respond_to(:empty?)
24
+ describe RDF::Enumerable do
25
+ describe "#supports?" do
26
+ it "responds to #supports?" do
27
+ @enumerable.respond_to?(:support?)
28
+ end
32
29
  end
33
30
 
34
- it "should respond to #count and #size" do
35
- @enumerable.should respond_to(*%w(count size))
36
- end
31
+ context "when counting statements" do
32
+ it "should respond to #empty?" do
33
+ @enumerable.should respond_to(:empty?)
34
+ end
37
35
 
38
- it "should implement #empty?" do
39
- ([].extend(RDF::Enumerable)).empty?.should be_true
40
- @enumerable.empty?.should be_false
41
- end
36
+ it "should respond to #count and #size" do
37
+ @enumerable.should respond_to(*%w(count size))
38
+ end
42
39
 
43
- it "should implement #count and #size" do
44
- %w(count size).each do |method|
45
- @enumerable.send(method).should == @statements.size
40
+ it "should implement #empty?" do
41
+ ([].extend(RDF::Enumerable)).empty?.should be_true
42
+ @enumerable.empty?.should be_false
46
43
  end
47
- end
48
- end
49
44
 
50
- context "when enumerating statements" do
51
- it "should respond to #statements" do
52
- @enumerable.should respond_to(:statements)
45
+ it "should implement #count and #size" do
46
+ %w(count size).each do |method|
47
+ @enumerable.send(method).should == @statements.size
48
+ end
49
+ end
53
50
  end
54
51
 
55
- it "should respond to #has_statement?" do
56
- @enumerable.should respond_to(:has_statement?)
57
- end
52
+ context "when enumerating statements" do
53
+ it "should respond to #statements" do
54
+ @enumerable.should respond_to(:statements)
55
+ end
58
56
 
59
- it "should respond to #each_statement" do
60
- @enumerable.should respond_to(:each_statement)
61
- end
57
+ it "should respond to #has_statement?" do
58
+ @enumerable.should respond_to(:has_statement?)
59
+ end
62
60
 
63
- it "should respond to #enum_statement" do
64
- @enumerable.should respond_to(:enum_statement)
65
- end
61
+ it "should respond to #each_statement" do
62
+ @enumerable.should respond_to(:each_statement)
63
+ end
66
64
 
67
- it "should implement #statements" do
68
- @enumerable.statements.should be_an_enumerator
69
- @enumerable.statements.to_a.size.should == @statements.size
70
- @enumerable.statements.each { |statement| statement.should be_a_statement }
71
- end
65
+ it "should respond to #enum_statement" do
66
+ @enumerable.should respond_to(:enum_statement)
67
+ end
72
68
 
73
- it "should implement #has_statement?" do
74
- @statements.each do |statement|
75
- @enumerable.has_statement?(statement).should be_true
69
+ it "should implement #statements" do
70
+ @enumerable.statements.should be_an_enumerator
71
+ @enumerable.statements.to_a.size.should == @statements.size
72
+ @enumerable.statements.each { |statement| statement.should be_a_statement }
76
73
  end
77
74
 
78
- if @supports_context
79
- context = RDF::URI.new("urn:context:1")
75
+ it "should implement #has_statement?" do
80
76
  @statements.each do |statement|
81
- s = statement.dup
82
- s.context = context
83
- @enumerable.has_statement?(s).should be_false
77
+ @enumerable.has_statement?(statement).should be_true
84
78
  end
85
- end
86
79
 
87
- unknown_statement = RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)
88
- @enumerable.has_statement?(unknown_statement).should be_false
89
- end
80
+ if @supports_context
81
+ context = RDF::URI.new("urn:context:1")
82
+ @statements.each do |statement|
83
+ s = statement.dup
84
+ s.context = context
85
+ @enumerable.has_statement?(s).should be_false
86
+ end
87
+ end
90
88
 
91
- it "should implement #each_statement" do
92
- @enumerable.each_statement.should be_an_enumerator
93
- @enumerable.each_statement { |statement| statement.should be_a_statement }
94
- end
89
+ unknown_statement = RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)
90
+ @enumerable.has_statement?(unknown_statement).should be_false
91
+ end
95
92
 
96
- it "should implement #enum_statement" do
97
- @enumerable.enum_statement.should be_an_enumerator
98
- @enumerable.enum_statement.should be_countable
99
- @enumerable.enum_statement.should be_enumerable
100
- @enumerable.enum_statement.should be_queryable
101
- @enumerable.enum_statement.to_a.should == @enumerable.each_statement.to_a
102
- end
103
- end
93
+ it "should implement #each_statement" do
94
+ @enumerable.each_statement.should be_an_enumerator
95
+ @enumerable.each_statement { |statement| statement.should be_a_statement }
96
+ end
104
97
 
105
- context "when enumerating triples" do
106
- it "should respond to #triples" do
107
- @enumerable.should respond_to(:triples)
98
+ it "should implement #enum_statement" do
99
+ @enumerable.enum_statement.should be_an_enumerator
100
+ @enumerable.enum_statement.should be_countable
101
+ @enumerable.enum_statement.should be_enumerable
102
+ @enumerable.enum_statement.should be_queryable
103
+ @enumerable.enum_statement.to_a.should == @enumerable.each_statement.to_a
104
+ end
108
105
  end
109
106
 
110
- it "should respond to #has_triple?" do
111
- @enumerable.should respond_to(:has_triple?)
112
- end
107
+ context "when enumerating triples" do
108
+ it "should respond to #triples" do
109
+ @enumerable.should respond_to(:triples)
110
+ end
113
111
 
114
- it "should respond to #each_triple" do
115
- @enumerable.should respond_to(:each_triple)
116
- end
112
+ it "should respond to #has_triple?" do
113
+ @enumerable.should respond_to(:has_triple?)
114
+ end
117
115
 
118
- it "should respond to #enum_triple" do
119
- @enumerable.should respond_to(:enum_triple)
120
- end
116
+ it "should respond to #each_triple" do
117
+ @enumerable.should respond_to(:each_triple)
118
+ end
121
119
 
122
- it "should implement #triples" do
123
- @enumerable.triples.should be_an_enumerator
124
- @enumerable.triples.to_a.size.should == @statements.size
125
- @enumerable.triples.each { |triple| triple.should be_a_triple }
126
- end
120
+ it "should respond to #enum_triple" do
121
+ @enumerable.should respond_to(:enum_triple)
122
+ end
127
123
 
128
- it "should implement #has_triple?" do
129
- @statements.each do |statement|
130
- @enumerable.has_triple?(statement.to_triple).should be_true
124
+ it "should implement #triples" do
125
+ @enumerable.triples.should be_an_enumerator
126
+ @enumerable.triples.to_a.size.should == @statements.size
127
+ @enumerable.triples.each { |triple| triple.should be_a_triple }
131
128
  end
132
- end
133
129
 
134
- it "should implement #each_triple" do
135
- @enumerable.each_triple.should be_an_enumerator
136
- @enumerable.each_triple { |*triple| triple.should be_a_triple }
137
- end
130
+ it "should implement #has_triple?" do
131
+ @statements.each do |statement|
132
+ @enumerable.has_triple?(statement.to_triple).should be_true
133
+ end
134
+ end
138
135
 
139
- it "should implement #enum_triple" do
140
- @enumerable.enum_triple.should be_an_enumerator
141
- @enumerable.enum_triple.should be_countable
142
- @enumerable.enum_triple.to_a.should == @enumerable.each_triple.to_a
143
- end
144
- end
136
+ it "should implement #each_triple" do
137
+ @enumerable.each_triple.should be_an_enumerator
138
+ @enumerable.each_triple { |*triple| triple.should be_a_triple }
139
+ end
145
140
 
146
- context "when enumerating quads" do
147
- it "should respond to #quads" do
148
- @enumerable.should respond_to(:quads)
141
+ it "should implement #enum_triple" do
142
+ @enumerable.enum_triple.should be_an_enumerator
143
+ @enumerable.enum_triple.should be_countable
144
+ @enumerable.enum_triple.to_a.should == @enumerable.each_triple.to_a
145
+ end
149
146
  end
150
147
 
151
- it "should respond to #has_quad?" do
152
- @enumerable.should respond_to(:has_quad?)
153
- end
148
+ context "when enumerating quads" do
149
+ it "should respond to #quads" do
150
+ @enumerable.should respond_to(:quads)
151
+ end
154
152
 
155
- it "should respond to #each_quad" do
156
- @enumerable.should respond_to(:each_quad)
157
- end
153
+ it "should respond to #has_quad?" do
154
+ @enumerable.should respond_to(:has_quad?)
155
+ end
158
156
 
159
- it "should respond to #enum_quad" do
160
- @enumerable.should respond_to(:enum_quad)
161
- end
157
+ it "should respond to #each_quad" do
158
+ @enumerable.should respond_to(:each_quad)
159
+ end
162
160
 
163
- it "should implement #quads" do
164
- @enumerable.quads.should be_an_enumerator
165
- @enumerable.quads.to_a.size.should == @statements.size
166
- @enumerable.quads.each { |quad| quad.should be_a_quad }
167
- end
161
+ it "should respond to #enum_quad" do
162
+ @enumerable.should respond_to(:enum_quad)
163
+ end
168
164
 
169
- it "should implement #has_quad?" do
170
- @statements.each do |statement|
171
- @enumerable.has_quad?(statement.to_quad).should be_true
165
+ it "should implement #quads" do
166
+ @enumerable.quads.should be_an_enumerator
167
+ @enumerable.quads.to_a.size.should == @statements.size
168
+ @enumerable.quads.each { |quad| quad.should be_a_quad }
172
169
  end
173
- end
174
170
 
175
- it "should implement #each_quad" do
176
- @enumerable.each_quad.should be_an_enumerator
177
- @enumerable.each_quad { |*quad| quad.should be_a_quad }
178
- end
171
+ it "should implement #has_quad?" do
172
+ @statements.each do |statement|
173
+ @enumerable.has_quad?(statement.to_quad).should be_true
174
+ end
175
+ end
179
176
 
180
- it "should implement #enum_quad" do
181
- @enumerable.enum_quad.should be_an_enumerator
182
- @enumerable.enum_quad.should be_countable
183
- @enumerable.enum_quad.to_a.should == @enumerable.each_quad.to_a
184
- end
185
- end
177
+ it "should implement #each_quad" do
178
+ @enumerable.each_quad.should be_an_enumerator
179
+ @enumerable.each_quad { |*quad| quad.should be_a_quad }
180
+ end
186
181
 
187
- context "when enumerating subjects" do
188
- it "should respond to #subjects" do
189
- @enumerable.should respond_to(:subjects)
182
+ it "should implement #enum_quad" do
183
+ @enumerable.enum_quad.should be_an_enumerator
184
+ @enumerable.enum_quad.should be_countable
185
+ @enumerable.enum_quad.to_a.should == @enumerable.each_quad.to_a
186
+ end
190
187
  end
191
188
 
192
- it "should respond to #has_subject?" do
193
- @enumerable.should respond_to(:has_subject?)
194
- end
189
+ context "when enumerating subjects" do
190
+ it "should respond to #subjects" do
191
+ @enumerable.should respond_to(:subjects)
192
+ end
195
193
 
196
- it "should respond to #each_subject" do
197
- @enumerable.should respond_to(:each_subject)
198
- end
194
+ it "should respond to #has_subject?" do
195
+ @enumerable.should respond_to(:has_subject?)
196
+ end
199
197
 
200
- it "should respond to #enum_subject" do
201
- @enumerable.should respond_to(:enum_subject)
202
- end
198
+ it "should respond to #each_subject" do
199
+ @enumerable.should respond_to(:each_subject)
200
+ end
203
201
 
204
- it "should implement #subjects" do
205
- @enumerable.subjects.should be_an_enumerator
206
- @enumerable.subjects.each { |value| value.should be_a_resource }
207
- # TODO: subjects(:unique => false)
208
- end
202
+ it "should respond to #enum_subject" do
203
+ @enumerable.should respond_to(:enum_subject)
204
+ end
209
205
 
210
- it "should implement #has_subject?" do
211
- checked = []
212
- @statements.each do |statement|
213
- @enumerable.has_subject?(statement.subject).should be_true unless checked.include?(statement.subject)
214
- checked << statement.subject
206
+ describe "#subjects" do
207
+ subject {@enumerable.subjects}
208
+ specify {subject.should be_an_enumerator}
209
+ specify {subject.each { |value| value.should be_a_resource }}
210
+ context ":unique => false" do
211
+ subject {@enumerable.subjects(:unique => false)}
212
+ specify {subject.should be_an_enumerator}
213
+ specify {subject.each { |value| value.should be_a_resource }}
214
+ end
215
215
  end
216
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
217
- @enumerable.has_predicate?(uri).should be_false
218
- end
219
216
 
220
- it "should implement #each_subject" do
221
- @enumerable.each_subject.should be_an_enumerator
222
- subjects = @statements.map { |s| s.subject }.uniq
223
- @enumerable.each_subject.to_a.size.should == subjects.size
224
- @enumerable.each_subject do |value|
225
- value.should be_a_value
226
- subjects.should include(value)
217
+ it "should implement #has_subject?" do
218
+ checked = []
219
+ @statements.each do |statement|
220
+ @enumerable.has_subject?(statement.subject).should be_true unless checked.include?(statement.subject)
221
+ checked << statement.subject
222
+ end
223
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
224
+ @enumerable.has_predicate?(uri).should be_false
227
225
  end
228
- end
229
226
 
230
- it "should implement #enum_subject" do
231
- @enumerable.enum_subject.should be_an_enumerator
232
- @enumerable.enum_subject.should be_countable
233
- @enumerable.enum_subject.to_a.should == @enumerable.each_subject.to_a
234
- end
235
- end
227
+ it "should implement #each_subject" do
228
+ @enumerable.each_subject.should be_an_enumerator
229
+ subjects = @statements.map { |s| s.subject }.uniq
230
+ @enumerable.each_subject.to_a.size.should == subjects.size
231
+ @enumerable.each_subject do |value|
232
+ value.should be_a_value
233
+ subjects.should include(value)
234
+ end
235
+ end
236
236
 
237
- context "when enumerating predicates" do
238
- it "should respond to #predicates" do
239
- @enumerable.should respond_to(:predicates)
237
+ it "should implement #enum_subject" do
238
+ @enumerable.enum_subject.should be_an_enumerator
239
+ @enumerable.enum_subject.should be_countable
240
+ @enumerable.enum_subject.to_a.should == @enumerable.each_subject.to_a
241
+ end
240
242
  end
241
243
 
242
- it "should respond to #has_predicate?" do
243
- @enumerable.should respond_to(:has_predicate?)
244
- end
244
+ context "when enumerating predicates" do
245
+ it "should respond to #predicates" do
246
+ @enumerable.should respond_to(:predicates)
247
+ end
245
248
 
246
- it "should respond to #each_predicate" do
247
- @enumerable.should respond_to(:each_predicate)
248
- end
249
+ it "should respond to #has_predicate?" do
250
+ @enumerable.should respond_to(:has_predicate?)
251
+ end
249
252
 
250
- it "should respond to #enum_predicate" do
251
- @enumerable.should respond_to(:enum_predicate)
252
- end
253
+ it "should respond to #each_predicate" do
254
+ @enumerable.should respond_to(:each_predicate)
255
+ end
253
256
 
254
- it "should implement #predicates" do
255
- @enumerable.predicates.should be_an_enumerator
256
- @enumerable.predicates.each { |value| value.should be_a_uri }
257
- # TODO: predicates(:unique => false)
258
- end
257
+ it "should respond to #enum_predicate" do
258
+ @enumerable.should respond_to(:enum_predicate)
259
+ end
259
260
 
260
- it "should implement #has_predicate?" do
261
- checked = []
262
- @statements.each do |statement|
263
- @enumerable.has_predicate?(statement.predicate).should be_true unless checked.include?(statement.object)
264
- checked << statement.predicate
261
+ describe "#predicates" do
262
+ subject {@enumerable.predicates}
263
+ specify {subject.should be_an_enumerator}
264
+ specify {subject.each { |value| value.should be_a_uri }}
265
+ context ":unique => false" do
266
+ subject {@enumerable.predicates(:unique => false)}
267
+ specify {subject.should be_an_enumerator}
268
+ specify {subject.each { |value| value.should be_a_resource }}
269
+ end
265
270
  end
266
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
267
- @enumerable.has_predicate?(uri).should be_false
268
- end
269
271
 
270
- it "should implement #each_predicate" do
271
- predicates = @statements.map { |s| s.predicate }.uniq
272
- @enumerable.each_predicate.should be_an_enumerator
273
- @enumerable.each_predicate.to_a.size.should == predicates.size
274
- @enumerable.each_predicate do |value|
275
- value.should be_a_uri
276
- predicates.should include(value)
272
+ it "should implement #has_predicate?" do
273
+ checked = []
274
+ @statements.each do |statement|
275
+ @enumerable.has_predicate?(statement.predicate).should be_true unless checked.include?(statement.object)
276
+ checked << statement.predicate
277
+ end
278
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
279
+ @enumerable.has_predicate?(uri).should be_false
277
280
  end
278
- end
279
281
 
280
- it "should implement #enum_predicate" do
281
- @enumerable.enum_predicate.should be_an_enumerator
282
- @enumerable.enum_predicate.should be_countable
283
- @enumerable.enum_predicate.to_a.should == @enumerable.each_predicate.to_a
284
- end
285
- end
282
+ it "should implement #each_predicate" do
283
+ predicates = @statements.map { |s| s.predicate }.uniq
284
+ @enumerable.each_predicate.should be_an_enumerator
285
+ @enumerable.each_predicate.to_a.size.should == predicates.size
286
+ @enumerable.each_predicate do |value|
287
+ value.should be_a_uri
288
+ predicates.should include(value)
289
+ end
290
+ end
286
291
 
287
- context "when enumerating objects" do
288
- it "should respond to #objects" do
289
- @enumerable.should respond_to(:objects)
292
+ it "should implement #enum_predicate" do
293
+ @enumerable.enum_predicate.should be_an_enumerator
294
+ @enumerable.enum_predicate.should be_countable
295
+ @enumerable.enum_predicate.to_a.should == @enumerable.each_predicate.to_a
296
+ end
290
297
  end
291
298
 
292
- it "should respond to #has_object?" do
293
- @enumerable.should respond_to(:has_object?)
294
- end
299
+ context "when enumerating objects" do
300
+ it "should respond to #objects" do
301
+ @enumerable.should respond_to(:objects)
302
+ end
295
303
 
296
- it "should respond to #each_object" do
297
- @enumerable.should respond_to(:each_object)
298
- end
304
+ it "should respond to #has_object?" do
305
+ @enumerable.should respond_to(:has_object?)
306
+ end
299
307
 
300
- it "should respond to #enum_object" do
301
- @enumerable.should respond_to(:enum_object)
302
- end
308
+ it "should respond to #each_object" do
309
+ @enumerable.should respond_to(:each_object)
310
+ end
303
311
 
304
- it "should implement #objects" do
305
- @enumerable.objects.should be_an_enumerator
306
- @enumerable.objects.each { |value| value.should be_a_value }
307
- # TODO: objects(:unique => false)
308
- end
312
+ it "should respond to #enum_object" do
313
+ @enumerable.should respond_to(:enum_object)
314
+ end
309
315
 
310
- it "should implement #has_object?" do
311
- checked = []
312
- @statements.each do |statement|
313
- @enumerable.has_object?(statement.object).should be_true unless checked.include?(statement.object)
314
- checked << statement.object
316
+ describe "#objects" do
317
+ subject {@enumerable.objects}
318
+ specify {subject.should be_an_enumerator}
319
+ specify {subject.each { |value| value.should be_a_value }}
320
+ context ":unique => false" do
321
+ subject {@enumerable.objects(:unique => false)}
322
+ specify {subject.should be_an_enumerator}
323
+ specify {subject.each { |value| value.should be_a_value }}
324
+ end
315
325
  end
316
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
317
- @enumerable.has_object?(uri).should be_false
318
- end
319
326
 
320
- it "should implement #each_object" do
321
- objects = @statements.map { |s| s.object }.uniq
322
- @enumerable.each_object.should be_an_enumerator
323
- @enumerable.each_object.to_a.size.should == objects.size
324
- @enumerable.each_object do |value|
325
- value.should be_a_value
326
- objects.should include(value)
327
+ it "should implement #has_object?" do
328
+ checked = []
329
+ @statements.each do |statement|
330
+ @enumerable.has_object?(statement.object).should be_true unless checked.include?(statement.object)
331
+ checked << statement.object
332
+ end
333
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
334
+ @enumerable.has_object?(uri).should be_false
327
335
  end
328
- end
329
336
 
330
- it "should implement #enum_object" do
331
- @enumerable.enum_object.should be_an_enumerator
332
- @enumerable.enum_object.should be_countable
333
- @enumerable.enum_object.to_a.should == @enumerable.each_object.to_a
334
- end
335
- end
337
+ it "should implement #each_object" do
338
+ objects = @statements.map { |s| s.object }.uniq
339
+ @enumerable.each_object.should be_an_enumerator
340
+ @enumerable.each_object.to_a.size.should == objects.size
341
+ @enumerable.each_object do |value|
342
+ value.should be_a_value
343
+ objects.should include(value)
344
+ end
345
+ end
336
346
 
337
- context "when enumerating contexts" do
338
- it "should respond to #contexts" do
339
- @enumerable.should respond_to(:contexts)
347
+ it "should implement #enum_object" do
348
+ @enumerable.enum_object.should be_an_enumerator
349
+ @enumerable.enum_object.should be_countable
350
+ @enumerable.enum_object.to_a.should == @enumerable.each_object.to_a
351
+ end
340
352
  end
341
353
 
342
- it "should respond to #has_context?" do
343
- @enumerable.should respond_to(:has_context?)
344
- end
354
+ context "when enumerating contexts" do
355
+ it "should respond to #contexts" do
356
+ @enumerable.should respond_to(:contexts)
357
+ end
345
358
 
346
- it "should respond to #each_context" do
347
- @enumerable.should respond_to(:each_context)
348
- end
359
+ it "should respond to #has_context?" do
360
+ @enumerable.should respond_to(:has_context?)
361
+ end
349
362
 
350
- it "should respond to #enum_context" do
351
- @enumerable.should respond_to(:enum_context)
352
- end
363
+ it "should respond to #each_context" do
364
+ @enumerable.should respond_to(:each_context)
365
+ end
353
366
 
354
- it "should implement #contexts" do
355
- @enumerable.contexts.should be_an_enumerator
356
- @enumerable.contexts.each { |value| value.should be_a_resource }
357
- # TODO: contexts(:unique => false)
358
- end
367
+ it "should respond to #enum_context" do
368
+ @enumerable.should respond_to(:enum_context)
369
+ end
359
370
 
360
- it "should implement #has_context?" do
361
- @statements.each do |statement|
362
- if statement.has_context?
363
- @enumerable.has_context?(statement.context).should be_true
371
+ describe "#contexts" do
372
+ subject {@enumerable.contexts}
373
+ specify {subject.should be_an_enumerator}
374
+ specify {subject.each { |value| value.should be_a_resource }}
375
+ context ":unique => false" do
376
+ subject {@enumerable.contexts(:unique => false)}
377
+ specify {subject.should be_an_enumerator}
378
+ specify {subject.each { |value| value.should be_a_resource }}
364
379
  end
365
380
  end
366
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
367
- @enumerable.has_context?(uri).should be_false
368
- end
369
381
 
370
- it "should implement #each_context" do
371
- contexts = @statements.map { |s| s.context }.uniq
372
- contexts.delete nil
373
- @enumerable.each_context.should be_an_enumerator
374
- @enumerable.each_context.to_a.size.should == contexts.size
375
- @enumerable.each_context do |value|
376
- value.should be_a_resource
377
- contexts.should include(value)
382
+ it "should implement #has_context?" do
383
+ @statements.each do |statement|
384
+ if statement.has_context?
385
+ @enumerable.has_context?(statement.context).should be_true
386
+ end
387
+ end
388
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
389
+ @enumerable.has_context?(uri).should be_false
378
390
  end
379
- end
380
391
 
381
- it "should implement #enum_context" do
382
- @enumerable.enum_context.should be_an_enumerator
383
- @enumerable.enum_context.should be_countable
384
- @enumerable.enum_context.to_a.should == @enumerable.each_context.to_a
385
- end
386
- end
392
+ it "should implement #each_context" do
393
+ contexts = @statements.map { |s| s.context }.uniq
394
+ contexts.delete nil
395
+ @enumerable.each_context.should be_an_enumerator
396
+ @enumerable.each_context.to_a.size.should == contexts.size
397
+ @enumerable.each_context do |value|
398
+ value.should be_a_resource
399
+ contexts.should include(value)
400
+ end
401
+ end
387
402
 
388
- context "when enumerating graphs" do
389
- it "should respond to #each_graph" do
390
- @enumerable.should respond_to(:enum_graph)
403
+ it "should implement #enum_context" do
404
+ @enumerable.enum_context.should be_an_enumerator
405
+ @enumerable.enum_context.should be_countable
406
+ @enumerable.enum_context.to_a.should == @enumerable.each_context.to_a
407
+ end
391
408
  end
392
409
 
393
- it "should respond to #enum_graph" do
394
- @enumerable.should respond_to(:enum_graph)
395
- end
410
+ context "when enumerating graphs" do
411
+ it "should respond to #each_graph" do
412
+ @enumerable.should respond_to(:enum_graph)
413
+ end
396
414
 
397
- it "should implement #each_graph" do
398
- @enumerable.each_graph.should be_an_enumerator
399
- @enumerable.each_graph { |graph| graph.should be_a_graph }
400
- # TODO: relying on #contexts, check that the returned values are correct.
401
- end
415
+ it "should respond to #enum_graph" do
416
+ @enumerable.should respond_to(:enum_graph)
417
+ end
402
418
 
403
- it "should implement #enum_graph" do
404
- @enumerable.enum_graph.should be_an_enumerator
405
- @enumerable.enum_graph.should be_countable
406
- @enumerable.enum_graph.to_a.should == @enumerable.each_graph.to_a
407
- end
408
- end
419
+ describe "#each_graph" do
420
+ subject {@enumerable.each_graph}
421
+ specify {subject.should be_an_enumerator}
422
+ specify {subject.each { |value| value.should be_a_graph }}
423
+ end
409
424
 
410
- context "when converting" do
411
- it "should respond to #to_hash" do
412
- @enumerable.should respond_to(:to_hash)
425
+ it "should implement #enum_graph" do
426
+ @enumerable.enum_graph.should be_an_enumerator
427
+ @enumerable.enum_graph.should be_countable
428
+ @enumerable.enum_graph.to_a.should == @enumerable.each_graph.to_a
429
+ end
413
430
  end
414
431
 
415
- it "should implement #to_hash" do
416
- @enumerable.to_hash.should be_instance_of(Hash)
417
- @enumerable.to_hash.keys.size.should == @enumerable.subjects.to_a.size
432
+ context "when converting" do
433
+ it "should respond to #to_hash" do
434
+ @enumerable.should respond_to(:to_hash)
435
+ end
436
+
437
+ it "should implement #to_hash" do
438
+ @enumerable.to_hash.should be_instance_of(Hash)
439
+ @enumerable.to_hash.keys.size.should == @enumerable.subjects.to_a.size
440
+ end
418
441
  end
419
- end
420
442
 
421
- context "when dumping" do
422
- it "should respond to #dump" do
423
- @enumerable.should respond_to(:dump)
424
- end
443
+ context "when dumping" do
444
+ it "should respond to #dump" do
445
+ @enumerable.should respond_to(:dump)
446
+ end
425
447
 
426
- it "should implement #dump" do
427
- @enumerable.dump(:ntriples).should == RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
428
- end
448
+ it "should implement #dump" do
449
+ @enumerable.dump(:ntriples).should == RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
450
+ end
429
451
 
430
- it "raises error on unknown format" do
431
- lambda {@enumerable.dump(:foobar)}.should raise_error(RDF::WriterError, /No writer found/)
452
+ it "raises error on unknown format" do
453
+ lambda {@enumerable.dump(:foobar)}.should raise_error(RDF::WriterError, /No writer found/)
454
+ end
432
455
  end
433
456
  end
434
457
  end