rdf-spec 1.1.0.p1 → 1.1.0.p2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rdf/spec.rb CHANGED
@@ -46,5 +46,25 @@ module RDF
46
46
  module Spec
47
47
  autoload :Matchers, 'rdf/spec/matchers'
48
48
  autoload :VERSION, 'rdf/spec/version'
49
+ TRIPLES_FILE = File.expand_path("../../../etc/triples.nt", __FILE__)
50
+ QUADS_FILE = File.expand_path("../../../etc/quads.nq", __FILE__)
51
+
52
+ ##
53
+ # Return quads for tests
54
+ #
55
+ # @return [Array<RDF::Statement>]
56
+ def self.quads
57
+ require 'rdf/nquads'
58
+ (@quads ||= RDF::NQuads::Reader.new(File.open(QUADS_FILE)).to_a).dup
59
+ end
60
+
61
+ ##
62
+ # Return triples for tests
63
+ #
64
+ # @return [Array<RDF::Statement>]
65
+ def self.triples
66
+ require 'rdf/ntriples'
67
+ (@triples ||= RDF::NTriples::Reader.new(File.open(TRIPLES_FILE)).to_a).dup
68
+ end
49
69
  end # Spec
50
70
  end # RDF
@@ -7,43 +7,38 @@ module RDF_Countable
7
7
  before :each do
8
8
  raise '+@countable+ must be defined in a before(:each) block' unless instance_variable_get('@countable')
9
9
 
10
- @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
11
- @statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
10
+ @statements = RDF::Spec.quads
12
11
 
13
12
  if @countable.empty?
14
- if @countable.respond_to?(:<<)
13
+ if @countable.respond_to?(:<<) && (@countable.writable? rescue true)
15
14
  @statements.each { |statement| @countable << statement }
16
15
  else
17
- raise "+@countable+ must respond to #<< or be pre-populated with the statements in #{@filename} in a before(:each) block"
16
+ raise "+@countable+ must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
18
17
  end
19
18
  end
20
19
  end
21
20
 
22
21
  describe RDF::Countable do
23
- it "responds to #empty?" do
24
- @countable.should respond_to(:empty?)
22
+ subject {@countable}
23
+
24
+ it {should respond_to(:empty?)}
25
+ it {should_not be_empty}
26
+ it {should respond_to(:count)}
27
+ its(:count) {should == @statements.size}
28
+ it {should respond_to(:size)}
29
+ its(:size) {should == @statements.size}
30
+
31
+ context "when empty" do
32
+ subject {[].extend(RDF::Countable)}
33
+ it {should be_empty}
34
+ its(:count) {should == 0}
35
+ its(:size) {should == 0}
25
36
  end
26
37
 
27
- it "responds to #count and #size" do
28
- @countable.should respond_to(:count, :size)
29
- end
30
-
31
- it "implements #empty?" do
32
- ([].extend(RDF::Countable)).empty?.should be_true
33
- ([42].extend(RDF::Countable)).empty?.should be_false
34
- @countable.empty?.should be_false
35
- end
36
-
37
- it "implements #count and #size" do
38
- %w(count size).each do |method|
39
- @countable.send(method).should >= @statements.size
40
- end
41
- end
42
-
43
- it "returns countable enumerators" do
44
- @countable.to_enum.should be_countable
45
- @countable.enum_for.should be_countable
46
- @countable.enum_for(:each).should be_countable
38
+ its(:to_enum) {should be_countable}
39
+ its(:enum_for) {should be_countable}
40
+ it "#enum_for(:each)" do
41
+ subject.enum_for(:each).should be_countable
47
42
  end
48
43
  end
49
44
  end
@@ -23,29 +23,25 @@ module RDF_Durable
23
23
 
24
24
  before :each do
25
25
  raise '+@load_durable+ must be defined in a before(:each) block' unless instance_variable_get('@load_durable')
26
- # RDF::Queryable cares about the contents of this file too much to let someone set it
27
- @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
28
26
  end
29
27
 
30
28
  describe RDF::Durable do
29
+ subject {@load_durable.call}
30
+ it {should respond_to(:durable?)}
31
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
32
+ [true,false].member?(subject.durable?).should be_true
34
33
  end
35
34
 
35
+ it {should respond_to(:nondurable?)}
36
36
  it "should support #nondurable?" do
37
- @load_durable.call.should respond_to(:nondurable?)
38
37
  [true,false].member?(@load_durable.call.nondurable?).should be_true
39
38
  end
40
-
41
- it "should not be both durable and nondurable" do
42
- @load_durable.call.nondurable?.should_not == @load_durable.call.durable?
43
- end
39
+ its(:nondurable?) {should_not == subject.durable?}
44
40
 
45
41
  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
42
+ if subject.durable?
43
+ subject.load(RDF::Spec::TRIPLES_FILE)
44
+ subject.count.should == File.readlines(RDF::Spec::TRIPLES_FILE).size
49
45
  end
50
46
  end
51
47
  end
@@ -7,38 +7,32 @@ module RDF_Enumerable
7
7
  before :each do
8
8
  raise '+@enumerable+ must be defined in a before(:each) block' unless instance_variable_get('@enumerable')
9
9
 
10
- @filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
11
- @statements ||= RDF::NTriples::Reader.new(File.open(@filename)).to_a
10
+ @statements ||= RDF::Spec.quads
12
11
 
13
12
  if @enumerable.empty?
14
- if @enumerable.respond_to?(:<<)
13
+ if @enumerable.respond_to?(:<<) && (@enumerable.writable? rescue true)
15
14
  @statements.each { |statement| @enumerable << statement }
16
15
  else
17
- raise "@enumerable must respond to #<< or be pre-populated with the statements in #{@filename} in a before(:each) block"
16
+ raise "@enumerable must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
18
17
  end
19
18
  end
20
19
 
21
- @supports_context = @enumerable.respond_to?(:supports?) && @enumerable.supports?(:context)
20
+ @supports_context = @enumerable.supports?(:context) rescue true
22
21
  end
23
22
 
24
23
  describe RDF::Enumerable do
25
- describe "#supports?" do
26
- it "responds to #supports?" do
27
- @enumerable.respond_to?(:support?)
28
- end
29
- end
24
+ subject {@enumerable}
25
+ it {should respond_to(:supports?)}
30
26
 
31
27
  describe "valid?" do
32
- it "returns true if all statements are valid" do
33
- @enumerable.should be_valid
34
- end
28
+ it {should be_valid}
35
29
 
36
30
  it "returns false if any statement is invalid" do
37
- if @enumerable.respond_to?(:<<)
31
+ if subject.respond_to?(:<<) && (subject.writable? rescue true)
38
32
  s = RDF::Statement.from([nil, nil, nil])
39
33
  s.should_not be_valid
40
- @enumerable << s
41
- @enumerable.should_not be_valid
34
+ subject << s
35
+ subject.should_not be_valid
42
36
  else
43
37
  pending("can't add statement to immutable enumerable")
44
38
  end
@@ -46,181 +40,152 @@ module RDF_Enumerable
46
40
  end
47
41
 
48
42
  context "when counting statements" do
49
- it "should respond to #empty?" do
50
- @enumerable.should respond_to(:empty?)
51
- end
52
-
53
- it "should respond to #count and #size" do
54
- @enumerable.should respond_to(*%w(count size))
55
- end
56
-
57
- it "should implement #empty?" do
58
- ([].extend(RDF::Enumerable)).empty?.should be_true
59
- @enumerable.empty?.should be_false
60
- end
61
-
62
- it "should implement #count and #size" do
63
- %w(count size).each do |method|
64
- @enumerable.send(method).should == @statements.size
65
- end
43
+ it {should respond_to(:empty?)}
44
+ it {should_not be_empty}
45
+ it {should respond_to(:count)}
46
+ its(:count) {should == @statements.size}
47
+ it {should respond_to(:size)}
48
+ its(:size) {should == @statements.size}
49
+
50
+ context "and empty" do
51
+ subject {[].extend(RDF::Enumerable)}
52
+ it {should be_empty}
53
+ its(:count) {should == 0}
54
+ its(:size) {should == 0}
66
55
  end
67
56
  end
68
57
 
69
58
  context "when enumerating statements" do
70
- it "should respond to #statements" do
71
- @enumerable.should respond_to(:statements)
72
- end
59
+ it {should respond_to(:statements)}
60
+ its(:statements) {should be_an_enumerator}
73
61
 
74
- it "should respond to #has_statement?" do
75
- @enumerable.should respond_to(:has_statement?)
62
+ context "#statements" do
63
+ specify {subject.statements.to_a.size.should == @statements.size}
64
+ specify {subject.statements.each { |statement| statement.should be_a_statement }}
76
65
  end
77
66
 
78
- it "should respond to #each_statement" do
79
- @enumerable.should respond_to(:each_statement)
80
- end
81
-
82
- it "should respond to #enum_statement" do
83
- @enumerable.should respond_to(:enum_statement)
84
- end
85
-
86
- it "should implement #statements" do
87
- @enumerable.statements.should be_an_enumerator
88
- @enumerable.statements.to_a.size.should == @statements.size
89
- @enumerable.statements.each { |statement| statement.should be_a_statement }
90
- end
91
-
92
- it "should implement #has_statement?" do
93
- @statements.each do |statement|
94
- @enumerable.has_statement?(statement).should be_true
67
+ it {should respond_to(:has_statement?)}
68
+ context "#has_statement?" do
69
+ let(:unknown_statement) {RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)}
70
+ it "should have all statements" do
71
+ # Don't check for BNodes, as equivalence depends on their being exactly the same, not just the same identifier. If subject is loaded separately, these won't match.
72
+ @statements.reject {|s| s.to_a.any?(&:node?)}.each do |statement|
73
+ subject.has_statement?(statement).should be_true
74
+ end
95
75
  end
96
76
 
97
- if @supports_context
98
- context = RDF::URI.new("urn:context:1")
99
- @statements.each do |statement|
100
- s = statement.dup
101
- s.context = context
102
- @enumerable.has_statement?(s).should be_false
77
+ it "does not have statement in different context" do
78
+ if @supports_context
79
+ context = RDF::URI.new("urn:context:1")
80
+ @statements.each do |statement|
81
+ s = statement.dup
82
+ s.context = context
83
+ subject.has_statement?(s).should be_false
84
+ end
103
85
  end
104
86
  end
105
87
 
106
- unknown_statement = RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)
107
- @enumerable.has_statement?(unknown_statement).should be_false
88
+ it "does not have an unknown statement" do
89
+ subject.has_statement?(unknown_statement).should be_false
90
+ end
108
91
  end
109
92
 
93
+ it {should respond_to(:each_statement)}
94
+ its(:each_statement) {should be_an_enumerator}
110
95
  it "should implement #each_statement" do
111
- @enumerable.each_statement.should be_an_enumerator
112
- @enumerable.each_statement { |statement| statement.should be_a_statement }
96
+ subject.each_statement { |statement| statement.should be_a_statement }
113
97
  end
114
98
 
115
- it "should implement #enum_statement" do
116
- @enumerable.enum_statement.should be_an_enumerator
117
- @enumerable.enum_statement.should be_countable
118
- @enumerable.enum_statement.should be_enumerable
119
- @enumerable.enum_statement.should be_queryable
120
- @enumerable.enum_statement.to_a.should == @enumerable.each_statement.to_a
99
+ it {should respond_to(:enum_statement)}
100
+ its(:enum_statement) {should be_an_enumerator}
101
+ its(:enum_statement) {should be_countable}
102
+ its(:enum_statement) {should be_enumerable}
103
+ its(:enum_statement) {should be_queryable}
104
+ context "#enum_statement" do
105
+ it "should enumerate all statements" do
106
+ subject.enum_statement.to_a.should == @enumerable.each_statement.to_a
107
+ end
121
108
  end
122
109
  end
123
110
 
124
111
  context "when enumerating triples" do
125
- it "should respond to #triples" do
126
- @enumerable.should respond_to(:triples)
127
- end
128
-
129
- it "should respond to #has_triple?" do
130
- @enumerable.should respond_to(:has_triple?)
131
- end
132
-
133
- it "should respond to #each_triple" do
134
- @enumerable.should respond_to(:each_triple)
135
- end
112
+ it {should respond_to(:triples)}
113
+ it {should respond_to(:has_triple?)}
114
+ it {should respond_to(:each_triple)}
115
+ it {should respond_to(:enum_triple)}
136
116
 
137
- it "should respond to #enum_triple" do
138
- @enumerable.should respond_to(:enum_triple)
117
+ its(:triples) {should be_an_enumerator}
118
+ context "#triples" do
119
+ specify {subject.triples.to_a.size.should == @statements.size}
120
+ specify {subject.triples.each { |triple| triple.should be_a_triple }}
139
121
  end
140
122
 
141
- it "should implement #triples" do
142
- @enumerable.triples.should be_an_enumerator
143
- @enumerable.triples.to_a.size.should == @statements.size
144
- @enumerable.triples.each { |triple| triple.should be_a_triple }
145
- end
146
-
147
- it "should implement #has_triple?" do
148
- @statements.each do |statement|
149
- @enumerable.has_triple?(statement.to_triple).should be_true
123
+ context "#has_triple?" do
124
+ specify do
125
+ @statements.each do |statement|
126
+ subject.has_triple?(statement.to_triple).should be_true
127
+ end
150
128
  end
151
129
  end
152
130
 
153
- it "should implement #each_triple" do
154
- @enumerable.each_triple.should be_an_enumerator
155
- @enumerable.each_triple { |*triple| triple.should be_a_triple }
131
+ its(:each_triple) {should be_an_enumerator}
132
+ context "#each_triple" do
133
+ specify {subject.each_triple { |*triple| triple.should be_a_triple }}
156
134
  end
157
135
 
158
- it "should implement #enum_triple" do
159
- @enumerable.enum_triple.should be_an_enumerator
160
- @enumerable.enum_triple.should be_countable
161
- @enumerable.enum_triple.to_a.should == @enumerable.each_triple.to_a
136
+ its(:enum_triple) {should be_an_enumerator}
137
+ its(:enum_triple) {should be_countable}
138
+ context "#enum_triple" do
139
+ it "should enumerate all triples" do
140
+ subject.enum_triple.to_a.should == @enumerable.each_triple.to_a
141
+ end
162
142
  end
163
143
  end
164
144
 
165
145
  context "when enumerating quads" do
166
- it "should respond to #quads" do
167
- @enumerable.should respond_to(:quads)
168
- end
169
-
170
- it "should respond to #has_quad?" do
171
- @enumerable.should respond_to(:has_quad?)
172
- end
173
-
174
- it "should respond to #each_quad" do
175
- @enumerable.should respond_to(:each_quad)
176
- end
177
-
178
- it "should respond to #enum_quad" do
179
- @enumerable.should respond_to(:enum_quad)
180
- end
181
-
182
- it "should implement #quads" do
183
- @enumerable.quads.should be_an_enumerator
184
- @enumerable.quads.to_a.size.should == @statements.size
185
- @enumerable.quads.each { |quad| quad.should be_a_quad }
186
- end
187
-
188
- it "should implement #has_quad?" do
189
- @statements.each do |statement|
190
- @enumerable.has_quad?(statement.to_quad).should be_true
146
+ it {should respond_to(:quads)}
147
+ it {should respond_to(:has_quad?)}
148
+ it {should respond_to(:each_quad)}
149
+ it {should respond_to(:enum_quad)}
150
+
151
+ its(:quads) {should be_an_enumerator}
152
+ context "#quads" do
153
+ specify {subject.quads.to_a.size.should == @statements.size}
154
+ specify {subject.quads.each { |quad| quad.should be_a_quad }}
155
+ end
156
+
157
+ context "#has_quad?" do
158
+ specify do
159
+ if @supports_context
160
+ @statements.each do |statement|
161
+ subject.has_quad?(statement.to_quad).should be_true
162
+ end
163
+ end
191
164
  end
192
165
  end
193
166
 
194
- it "should implement #each_quad" do
195
- @enumerable.each_quad.should be_an_enumerator
196
- @enumerable.each_quad { |*quad| quad.should be_a_quad }
167
+ its(:each_quad) {should be_an_enumerator}
168
+ context "#each_quad" do
169
+ specify {subject.each_quad {|*quad| quad.should be_a_quad }}
197
170
  end
198
171
 
199
- it "should implement #enum_quad" do
200
- @enumerable.enum_quad.should be_an_enumerator
201
- @enumerable.enum_quad.should be_countable
202
- @enumerable.enum_quad.to_a.should == @enumerable.each_quad.to_a
172
+ its(:enum_quad) {should be_an_enumerator}
173
+ its(:enum_quad) {should be_countable}
174
+ context "#enum_quad" do
175
+ it "should enumerate all quads" do
176
+ subject.enum_quad.to_a.should == @enumerable.each_quad.to_a
177
+ end
203
178
  end
204
179
  end
205
180
 
206
181
  context "when enumerating subjects" do
207
- it "should respond to #subjects" do
208
- @enumerable.should respond_to(:subjects)
209
- end
210
-
211
- it "should respond to #has_subject?" do
212
- @enumerable.should respond_to(:has_subject?)
213
- end
182
+ it {should respond_to(:subjects)}
183
+ it {should respond_to(:has_subject?)}
184
+ it {should respond_to(:each_subject)}
185
+ it {should respond_to(:enum_subject)}
214
186
 
215
- it "should respond to #each_subject" do
216
- @enumerable.should respond_to(:each_subject)
217
- end
218
-
219
- it "should respond to #enum_subject" do
220
- @enumerable.should respond_to(:enum_subject)
221
- end
222
-
223
- describe "#subjects" do
187
+ its(:subjects) {should be_an_enumerator}
188
+ context "#subjects" do
224
189
  subject {@enumerable.subjects}
225
190
  specify {subject.should be_an_enumerator}
226
191
  specify {subject.each { |value| value.should be_a_resource }}
@@ -231,212 +196,198 @@ module RDF_Enumerable
231
196
  end
232
197
  end
233
198
 
234
- it "should implement #has_subject?" do
235
- checked = []
236
- @statements.each do |statement|
237
- @enumerable.has_subject?(statement.subject).should be_true unless checked.include?(statement.subject)
238
- checked << statement.subject
199
+ context "#has_subject?" do
200
+ specify do
201
+ checked = []
202
+ @statements.each do |statement|
203
+ @enumerable.has_subject?(statement.subject).should be_true unless checked.include?(statement.subject)
204
+ checked << statement.subject
205
+ end
206
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
207
+ @enumerable.has_subject?(uri).should be_false
239
208
  end
240
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
241
- @enumerable.has_predicate?(uri).should be_false
242
209
  end
243
210
 
244
- it "should implement #each_subject" do
245
- @enumerable.each_subject.should be_an_enumerator
246
- subjects = @statements.map { |s| s.subject }.uniq
247
- @enumerable.each_subject.to_a.size.should == subjects.size
248
- @enumerable.each_subject do |value|
249
- value.should be_a_value
250
- subjects.should include(value)
251
- end
211
+ its(:each_subject) {should be_an_enumerator}
212
+ context "#each_subject" do
213
+ let(:subjects) {@statements.map { |s| s.subject }.uniq}
214
+ specify {subject.each_subject.to_a.size.should == subjects.size}
215
+ specify {subject.each_subject {|value| value.should be_a_resource}}
216
+ specify {subject.each_subject {|value| subjects.should include(value)}}
252
217
  end
253
218
 
254
- it "should implement #enum_subject" do
255
- @enumerable.enum_subject.should be_an_enumerator
256
- @enumerable.enum_subject.should be_countable
257
- @enumerable.enum_subject.to_a.should == @enumerable.each_subject.to_a
219
+ its(:enum_subject) {should be_an_enumerator}
220
+ its(:enum_subject) {should be_countable}
221
+ context "#enum_subject" do
222
+ it "should enumerate all subjects" do
223
+ subject.enum_subject.to_a.should == @enumerable.each_subject.to_a
224
+ end
258
225
  end
259
226
  end
260
227
 
261
228
  context "when enumerating predicates" do
262
- it "should respond to #predicates" do
263
- @enumerable.should respond_to(:predicates)
264
- end
265
-
266
- it "should respond to #has_predicate?" do
267
- @enumerable.should respond_to(:has_predicate?)
268
- end
269
-
270
- it "should respond to #each_predicate" do
271
- @enumerable.should respond_to(:each_predicate)
272
- end
229
+ it {should respond_to(:predicates)}
230
+ it {should respond_to(:has_predicate?)}
231
+ it {should respond_to(:each_predicate)}
232
+ it {should respond_to(:enum_predicate)}
273
233
 
274
- it "should respond to #enum_predicate" do
275
- @enumerable.should respond_to(:enum_predicate)
276
- end
277
-
278
- describe "#predicates" do
234
+ its(:predicates) {should be_an_enumerator}
235
+ context "#predicates" do
279
236
  subject {@enumerable.predicates}
280
237
  specify {subject.should be_an_enumerator}
281
238
  specify {subject.each { |value| value.should be_a_uri }}
282
239
  context ":unique => false" do
283
240
  subject {@enumerable.predicates(:unique => false)}
284
241
  specify {subject.should be_an_enumerator}
285
- specify {subject.each { |value| value.should be_a_resource }}
242
+ specify {subject.each { |value| value.should be_a_uri }}
286
243
  end
287
244
  end
288
245
 
289
- it "should implement #has_predicate?" do
290
- checked = []
291
- @statements.each do |statement|
292
- @enumerable.has_predicate?(statement.predicate).should be_true unless checked.include?(statement.object)
293
- checked << statement.predicate
246
+ context "#has_predicate?" do
247
+ specify do
248
+ checked = []
249
+ @statements.each do |statement|
250
+ @enumerable.has_predicate?(statement.predicate).should be_true unless checked.include?(statement.predicate)
251
+ checked << statement.predicate
252
+ end
253
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
254
+ @enumerable.has_predicate?(uri).should be_false
294
255
  end
295
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
296
- @enumerable.has_predicate?(uri).should be_false
297
256
  end
298
257
 
299
- it "should implement #each_predicate" do
300
- predicates = @statements.map { |s| s.predicate }.uniq
301
- @enumerable.each_predicate.should be_an_enumerator
302
- @enumerable.each_predicate.to_a.size.should == predicates.size
303
- @enumerable.each_predicate do |value|
304
- value.should be_a_uri
305
- predicates.should include(value)
306
- end
258
+ its(:each_predicate) {should be_an_enumerator}
259
+ context "#each_predicate" do
260
+ let(:predicates) {@statements.map { |s| s.predicate }.uniq}
261
+ specify {subject.each_predicate.to_a.size.should == predicates.size}
262
+ specify {subject.each_predicate {|value| value.should be_a_uri}}
263
+ specify {subject.each_predicate {|value| predicates.should include(value)}}
307
264
  end
308
265
 
309
- it "should implement #enum_predicate" do
310
- @enumerable.enum_predicate.should be_an_enumerator
311
- @enumerable.enum_predicate.should be_countable
312
- @enumerable.enum_predicate.to_a.should == @enumerable.each_predicate.to_a
266
+ its(:enum_predicate) {should be_an_enumerator}
267
+ its(:enum_predicate) {should be_countable}
268
+ context "#enum_predicate" do
269
+ it "should enumerate all predicates" do
270
+ subject.enum_predicate.to_a.should == @enumerable.each_predicate.to_a
271
+ end
313
272
  end
314
273
  end
315
274
 
316
275
  context "when enumerating objects" do
317
- it "should respond to #objects" do
318
- @enumerable.should respond_to(:objects)
319
- end
320
-
321
- it "should respond to #has_object?" do
322
- @enumerable.should respond_to(:has_object?)
323
- end
276
+ it {should respond_to(:objects)}
277
+ it {should respond_to(:has_object?)}
278
+ it {should respond_to(:each_object)}
279
+ it {should respond_to(:enum_object)}
324
280
 
325
- it "should respond to #each_object" do
326
- @enumerable.should respond_to(:each_object)
327
- end
328
-
329
- it "should respond to #enum_object" do
330
- @enumerable.should respond_to(:enum_object)
331
- end
332
-
333
- describe "#objects" do
281
+ its(:objects) {should be_an_enumerator}
282
+ context "#objects" do
334
283
  subject {@enumerable.objects}
335
284
  specify {subject.should be_an_enumerator}
336
- specify {subject.each { |value| value.should be_a_value }}
285
+ specify {subject.each { |value| value.should be_a_term }}
337
286
  context ":unique => false" do
338
287
  subject {@enumerable.objects(:unique => false)}
339
288
  specify {subject.should be_an_enumerator}
340
- specify {subject.each { |value| value.should be_a_value }}
289
+ specify {subject.each { |value| value.should be_a_term }}
341
290
  end
342
291
  end
343
292
 
344
- it "should implement #has_object?" do
345
- checked = []
346
- @statements.each do |statement|
347
- @enumerable.has_object?(statement.object).should be_true unless checked.include?(statement.object)
348
- checked << statement.object
293
+ context "#has_object?" do
294
+ specify do
295
+ checked = []
296
+ @statements.each do |statement|
297
+ @enumerable.has_object?(statement.object).should be_true unless checked.include?(statement.object)
298
+ checked << statement.object
299
+ end
300
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
301
+ @enumerable.has_object?(uri).should be_false
349
302
  end
350
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
351
- @enumerable.has_object?(uri).should be_false
352
303
  end
353
304
 
354
- it "should implement #each_object" do
355
- objects = @statements.map { |s| s.object }.uniq
356
- @enumerable.each_object.should be_an_enumerator
357
- @enumerable.each_object.to_a.size.should == objects.size
358
- @enumerable.each_object do |value|
359
- value.should be_a_value
360
- objects.should include(value)
361
- end
305
+ its(:each_object) {should be_an_enumerator}
306
+ context "#each_object" do
307
+ let(:objects) {@statements.map { |s| s.object }.uniq}
308
+ specify {subject.each_object.to_a.size.should == objects.size}
309
+ specify {subject.each_object {|value| value.should be_a_term}}
310
+ specify {subject.each_object {|value| objects.should include(value)}}
362
311
  end
363
312
 
364
- it "should implement #enum_object" do
365
- @enumerable.enum_object.should be_an_enumerator
366
- @enumerable.enum_object.should be_countable
367
- @enumerable.enum_object.to_a.should == @enumerable.each_object.to_a
313
+ its(:enum_object) {should be_an_enumerator}
314
+ its(:enum_object) {should be_countable}
315
+ context "#enum_object" do
316
+ it "should enumerate all objects" do
317
+ subject.enum_object.to_a.should == @enumerable.each_object.to_a
318
+ end
368
319
  end
369
320
  end
370
321
 
371
322
  context "when enumerating contexts" do
372
- it "should respond to #contexts" do
373
- @enumerable.should respond_to(:contexts)
374
- end
375
-
376
- it "should respond to #has_context?" do
377
- @enumerable.should respond_to(:has_context?)
378
- end
379
-
380
- it "should respond to #each_context" do
381
- @enumerable.should respond_to(:each_context)
382
- end
383
-
384
- it "should respond to #enum_context" do
385
- @enumerable.should respond_to(:enum_context)
386
- end
323
+ it {should respond_to(:contexts)}
324
+ it {should respond_to(:has_context?)}
325
+ it {should respond_to(:each_context)}
326
+ it {should respond_to(:enum_context)}
387
327
 
328
+ its(:contexts) {should be_an_enumerator}
388
329
  describe "#contexts" do
389
330
  subject {@enumerable.contexts}
390
331
  specify {subject.should be_an_enumerator}
391
- specify {subject.each { |value| value.should be_a_resource }}
332
+ it "values should be resources" do
333
+ subject.each { |value| value.should be_a_resource }
334
+ end
392
335
  context ":unique => false" do
393
336
  subject {@enumerable.contexts(:unique => false)}
394
337
  specify {subject.should be_an_enumerator}
395
- specify {subject.each { |value| value.should be_a_resource }}
338
+ it "values should be resources" do
339
+ subject.each { |value| value.should be_a_resource }
340
+ end
396
341
  end
397
342
  end
398
343
 
399
344
  it "should implement #has_context?" do
400
- @statements.each do |statement|
401
- if statement.has_context?
402
- @enumerable.has_context?(statement.context).should be_true
345
+ if @supports_context
346
+ @statements.each do |statement|
347
+ if statement.has_context?
348
+ @enumerable.has_context?(statement.context).should be_true
349
+ end
350
+ end
351
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
352
+ @enumerable.has_context?(uri).should be_false
353
+ end
354
+ end
355
+
356
+ its(:each_context) {should be_an_enumerator}
357
+ context "#each_context" do
358
+ let(:contexts) {@statements.map { |s| s.context }.uniq.compact}
359
+ it "has appropriate number of contexts" do
360
+ if @supports_context
361
+ subject.each_context.to_a.size.should == contexts.size
403
362
  end
404
363
  end
405
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
406
- @enumerable.has_context?(uri).should be_false
407
- end
408
-
409
- it "should implement #each_context" do
410
- contexts = @statements.map { |s| s.context }.uniq
411
- contexts.delete nil
412
- @enumerable.each_context.should be_an_enumerator
413
- @enumerable.each_context.to_a.size.should == contexts.size
414
- @enumerable.each_context do |value|
415
- value.should be_a_resource
416
- contexts.should include(value)
364
+ it "values should be resources" do
365
+ subject.each_context {|value| value.should be_a_resource}
366
+ end
367
+ it "should have all contexts" do
368
+ subject.each_context {|value| contexts.should include(value)}
417
369
  end
418
370
  end
419
371
 
420
- it "should implement #enum_context" do
421
- @enumerable.enum_context.should be_an_enumerator
422
- @enumerable.enum_context.should be_countable
423
- @enumerable.enum_context.to_a.should == @enumerable.each_context.to_a
372
+ its(:enum_context) {should be_an_enumerator}
373
+ its(:enum_context) {should be_countable}
374
+ context "#enum_context" do
375
+ it "should enumerate all contexts" do
376
+ subject.enum_context.to_a.should == @enumerable.each_context.to_a
377
+ end
424
378
  end
425
379
  end
426
380
 
427
381
  context "when enumerating graphs" do
428
- it "should respond to #each_graph" do
429
- @enumerable.should respond_to(:enum_graph)
430
- end
431
-
432
- it "should respond to #enum_graph" do
433
- @enumerable.should respond_to(:enum_graph)
434
- end
382
+ it {should respond_to(:each_graph)}
383
+ it {should respond_to(:enum_graph)}
435
384
 
436
385
  describe "#each_graph" do
437
386
  subject {@enumerable.each_graph}
438
387
  it {should be_an_enumerator}
439
- specify {subject.each { |value| value.should be_a_graph }}
388
+ it "are all graphs" do
389
+ subject.each { |value| value.should be_a_graph } if @supports_context
390
+ end
440
391
  end
441
392
 
442
393
  describe "#enum_graph" do
@@ -444,33 +395,30 @@ module RDF_Enumerable
444
395
  it {subject.should be_an_enumerator}
445
396
  it {subject.should be_countable}
446
397
  it "enumerates the same as #each_graph" do
447
- subject.to_a.should == @enumerable.each_graph.to_a
398
+ subject.to_a.should == @enumerable.each_graph.to_a if @supports_context
448
399
  end
449
400
  end
450
401
  end
451
402
 
452
403
  context "when converting" do
453
- it "should respond to #to_hash" do
454
- @enumerable.should respond_to(:to_hash)
455
- end
456
-
457
- it "should implement #to_hash" do
458
- @enumerable.to_hash.should be_instance_of(Hash)
459
- @enumerable.to_hash.keys.size.should == @enumerable.subjects.to_a.size
404
+ it {should respond_to(:to_hash)}
405
+ its(:to_hash) {should be_instance_of(Hash)}
406
+ context "#to_hash" do
407
+ it "should have as many keys as subjects" do
408
+ subject.to_hash.keys.size.should == @enumerable.subjects.to_a.size
409
+ end
460
410
  end
461
411
  end
462
412
 
463
413
  context "when dumping" do
464
- it "should respond to #dump" do
465
- @enumerable.should respond_to(:dump)
466
- end
414
+ it {should respond_to(:dump)}
467
415
 
468
416
  it "should implement #dump" do
469
- @enumerable.dump(:ntriples).should == RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
417
+ subject.dump(:ntriples).should == RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
470
418
  end
471
419
 
472
420
  it "raises error on unknown format" do
473
- lambda {@enumerable.dump(:foobar)}.should raise_error(RDF::WriterError, /No writer found/)
421
+ lambda {subject.dump(:foobar)}.should raise_error(RDF::WriterError, /No writer found/)
474
422
  end
475
423
  end
476
424
  end