rdf-spec 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
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,444 +7,417 @@ 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
24
  subject {@enumerable}
26
25
  it {should respond_to(:supports?)}
27
- it {should respond_to(:count)}
28
- it {should respond_to(:size)}
29
-
30
- it {should respond_to(:statements)}
31
- it {should respond_to(:has_statement?)}
32
- it {should respond_to(:each_statement)}
33
- it {should respond_to(:enum_statement)}
34
-
35
- it {should respond_to(:triples)}
36
- it {should respond_to(:has_triple?)}
37
- it {should respond_to(:each_triple)}
38
- it {should respond_to(:enum_triple)}
39
-
40
- it {should respond_to(:quads)}
41
- it {should respond_to(:has_quad?)}
42
- it {should respond_to(:each_quad)}
43
- it {should respond_to(:enum_quad)}
44
-
45
- it {should respond_to(:subjects)}
46
- it {should respond_to(:has_subject?)}
47
- it {should respond_to(:each_subject)}
48
- it {should respond_to(:enum_subject)}
49
-
50
- it {should respond_to(:predicates)}
51
- it {should respond_to(:has_predicate?)}
52
- it {should respond_to(:each_predicate)}
53
- it {should respond_to(:enum_predicate)}
54
-
55
- it {should respond_to(:objects)}
56
- it {should respond_to(:has_object?)}
57
- it {should respond_to(:each_object)}
58
- it {should respond_to(:enum_object)}
59
-
60
- it {should respond_to(:contexts)}
61
- it {should respond_to(:has_context?)}
62
- it {should respond_to(:each_context)}
63
- it {should respond_to(:enum_context)}
64
-
65
- it {should respond_to(:each_graph)}
66
- it {should respond_to(:enum_graph)}
67
-
68
- it {should respond_to(:to_hash)}
69
- it {should respond_to(:dump)}
70
-
71
- it {should be_valid}
72
- it {should_not be_empty}
73
- its(:size) {should == @statements.size}
74
- its(:count) {should == @statements.size}
75
-
76
- it "returns is_invalid if any statement is invalid" do
77
- if subject.respond_to?(:<<)
78
- s = RDF::Statement.from([nil, nil, nil])
79
- s.should_not be_valid
80
- subject << s
81
- subject.should_not be_valid
26
+
27
+ describe "valid?" do
28
+ it {should be_valid}
29
+
30
+ it "returns false if any statement is invalid" do
31
+ if subject.respond_to?(:<<) && (subject.writable? rescue true)
32
+ s = RDF::Statement.from([nil, nil, nil])
33
+ s.should_not be_valid
34
+ subject << s
35
+ subject.should_not be_valid
36
+ else
37
+ pending("can't add statement to immutable enumerable")
38
+ end
82
39
  end
83
40
  end
84
41
 
85
- context "when extending an empty array" do
86
- subject {[].extend(RDF::Enumerable)}
87
- it {should be_empty}
88
- its(:size) {should == 0}
89
- its(:count) {should == 0}
42
+ context "when counting statements" do
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}
55
+ end
90
56
  end
91
57
 
92
- describe "#statements" do
93
- subject {@enumerable.statements}
94
- it {should be_an_enumerator}
95
- its(:size) {should == @statements.size}
96
- it "should iterrate statements" do
97
- subject.statements.each { |statement| statement.should be_a_statement }
58
+ context "when enumerating statements" do
59
+ it {should respond_to(:statements)}
60
+ its(:statements) {should be_an_enumerator}
61
+
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 }}
98
65
  end
99
- it "should have all statements" do
100
- @statements.each do |statement|
101
- subject.should have_statement(statement)
66
+
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
102
75
  end
103
- end
104
76
 
105
- it "should not have statements in a different context" do
106
- if @supports_context
107
- context = RDF::URI.new("urn:context:1")
108
- @statements.each do |statement|
109
- s = statement.dup
110
- s.context = context
111
- subject.should_not have_statement(s)
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
112
85
  end
113
86
  end
87
+
88
+ it "does not have an unknown statement" do
89
+ subject.has_statement?(unknown_statement).should be_false
90
+ end
114
91
  end
115
92
 
116
- it "should not have an unknown statement" do
117
- unknown_statement = RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)
118
- subject.has_statement?(unknown_statement).should be_false
93
+ it {should respond_to(:each_statement)}
94
+ its(:each_statement) {should be_an_enumerator}
95
+ it "should implement #each_statement" do
96
+ subject.each_statement { |statement| statement.should be_a_statement }
119
97
  end
120
- end
121
98
 
122
- describe "#has_statement?" do
123
- it "has all statements" do
124
- @statements.each do |statement|
125
- subject.should have_statement(statement)
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
126
107
  end
127
108
  end
128
109
  end
129
110
 
130
- describe "#each_statement" do
131
- subject {@enumerable.each_statement}
132
- it {should be_an_enumerator}
133
- it "should all be statements" do
134
- subject { |statement| statement.should be_a_statement }
135
- end
136
- end
111
+ context "when enumerating triples" do
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)}
137
116
 
138
- describe "#enum_statement" do
139
- subject {@enumerable.enum_statement}
140
- it {should be_an_enumerator}
141
- it {should be_countable}
142
- it {should be_enumerable}
143
- it {should be_queryable}
144
- it "should all be statements" do
145
- subject { |statement| statement.should be_a_statement }
146
- end
147
- it "should have all statements" do
148
- subject.to_a.should =~ @statements.to_a
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 }}
149
121
  end
150
- end
151
122
 
152
- describe "#triples" do
153
- subject {@enumerable.triples}
154
- it {should be_an_enumerator}
155
- it {subject.to_a.size.should == @statements.size}
156
- it "should all be triples" do
157
- subject.each {|triple| triple.should be_a_triple}
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
128
+ end
158
129
  end
159
- end
160
130
 
161
- describe "#has_triple?" do
162
- it "has all triples" do
163
- @statements.each do |statement|
164
- subject.should have_triple(statement.to_triple)
165
- end
131
+ its(:each_triple) {should be_an_enumerator}
132
+ context "#each_triple" do
133
+ specify {subject.each_triple { |*triple| triple.should be_a_triple }}
166
134
  end
167
- end
168
135
 
169
- describe "#each_triple" do
170
- subject {@enumerable.each_triple}
171
- it {should be_an_enumerator}
172
- it "has all triples" do
173
- subject do |*triple|
174
- triple.should be_a_triple
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
175
141
  end
176
142
  end
177
143
  end
178
144
 
179
- describe "#enum_triple" do
180
- subject {@enumerable.enum_triple}
181
- it {should be_an_enumerator}
182
- it {should be_countable}
183
- it "should have all triples" do
184
- subject.to_a.should =~ @enumerable.each_triple.to_a
185
- end
186
- end
145
+ context "when enumerating quads" do
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)}
187
150
 
188
- describe "#quads" do
189
- subject {@enumerable.quads}
190
- it {should be_an_enumerator}
191
- it {subject.to_a.size.should == @statements.size}
192
- it "should all be quads" do
193
- subject.each {|quad| quad.should be_a_quad}
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 }}
194
155
  end
195
- end
196
156
 
197
- describe "#has_quad?" do
198
- it "has all quads" do
199
- @statements.each do |statement|
200
- subject.should have_quad(statement.to_quad)
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
201
164
  end
202
165
  end
203
- end
204
166
 
205
- describe "#each_quad" do
206
- subject {@enumerable.each_quad}
207
- it {should be_an_enumerator}
208
- it "has all quads" do
209
- subject do |*quad|
210
- quad.should be_a_quad
211
- end
167
+ its(:each_quad) {should be_an_enumerator}
168
+ context "#each_quad" do
169
+ specify {subject.each_quad {|*quad| quad.should be_a_quad }}
212
170
  end
213
- end
214
171
 
215
- describe "#enum_quad" do
216
- subject {@enumerable.enum_quad}
217
- it {should be_an_enumerator}
218
- it {should be_countable}
219
- it "should have all triples" do
220
- subject.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
221
178
  end
222
179
  end
223
180
 
224
- describe "#subjects" do
225
- subject {@enumerable.subjects}
226
- specify {subject.should be_an_enumerator}
227
- specify {subject.each { |value| value.should be_a_resource }}
228
- context ":unique => false" do
229
- subject {@enumerable.subjects(:unique => false)}
181
+ context "when enumerating subjects" do
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)}
186
+
187
+ its(:subjects) {should be_an_enumerator}
188
+ context "#subjects" do
189
+ subject {@enumerable.subjects}
230
190
  specify {subject.should be_an_enumerator}
231
191
  specify {subject.each { |value| value.should be_a_resource }}
192
+ context ":unique => false" do
193
+ subject {@enumerable.subjects(:unique => false)}
194
+ specify {subject.should be_an_enumerator}
195
+ specify {subject.each { |value| value.should be_a_resource }}
196
+ end
232
197
  end
233
- end
234
198
 
235
- describe "#has_subject?" do
236
- it "has all subjects" do
237
- checked = []
238
- @statements.each do |statement|
239
- subject.should have_subject(statement.subject) unless checked.include?(statement.subject)
240
- 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
241
208
  end
242
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
243
- subject.should_not have_subject(uri)
244
209
  end
245
- end
246
210
 
247
- describe "#each_subject" do
248
- subject {@enumerable.each_subject}
249
- it {should be_an_enumerator}
250
- it "has all subjects" do
251
- subjects = @statements.map { |s| s.subject }.uniq
252
- subject.to_a.size.should == subjects.size
253
- subject do |term|
254
- term.should be_a_term
255
- subjects.should include(term)
256
- 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)}}
257
217
  end
258
- end
259
218
 
260
- describe "#enum_subject" do
261
- subject {@enumerable.enum_subject}
262
- it {should be_an_enumerator}
263
- it {should be_countable}
264
- it "should have all subjects" do
265
- 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
266
225
  end
267
226
  end
268
227
 
269
- describe "#predicates" do
270
- subject {@enumerable.predicates}
271
- specify {subject.should be_an_enumerator}
272
- specify {subject.each { |value| value.should be_a_resource }}
273
- context ":unique => false" do
274
- subject {@enumerable.predicates(:unique => false)}
228
+ context "when enumerating predicates" do
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)}
233
+
234
+ its(:predicates) {should be_an_enumerator}
235
+ context "#predicates" do
236
+ subject {@enumerable.predicates}
275
237
  specify {subject.should be_an_enumerator}
276
- specify {subject.each { |value| value.should be_a_resource }}
238
+ specify {subject.each { |value| value.should be_a_uri }}
239
+ context ":unique => false" do
240
+ subject {@enumerable.predicates(:unique => false)}
241
+ specify {subject.should be_an_enumerator}
242
+ specify {subject.each { |value| value.should be_a_uri }}
243
+ end
277
244
  end
278
- end
279
245
 
280
- describe "#has_predicate?" do
281
- it "has all predicates" do
282
- checked = []
283
- @statements.each do |statement|
284
- subject.should have_predicate(statement.predicate) unless checked.include?(statement.predicate)
285
- 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
286
255
  end
287
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
288
- subject.should_not have_predicate(uri)
289
256
  end
290
- end
291
257
 
292
- describe "#each_predicate" do
293
- subject {@enumerable.each_predicate}
294
- it {should be_an_enumerator}
295
- it "has all predicates" do
296
- predicates = @statements.map { |s| s.predicate }.uniq
297
- subject.to_a.size.should == predicates.size
298
- subject do |term|
299
- term.should be_a_term
300
- predicates.should include(term)
301
- 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)}}
302
264
  end
303
- end
304
265
 
305
- describe "#enum_predicate" do
306
- subject {@enumerable.enum_predicate}
307
- it {should be_an_enumerator}
308
- it {should be_countable}
309
- it "should have all predicates" do
310
- subject.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
311
272
  end
312
273
  end
313
274
 
314
- describe "#objects" do
315
- subject {@enumerable.objects}
316
- specify {subject.should be_an_enumerator}
317
- specify {subject.each { |value| value.should be_a_term }}
318
- context ":unique => false" do
319
- subject {@enumerable.objects(:unique => false)}
275
+ context "when enumerating objects" do
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)}
280
+
281
+ its(:objects) {should be_an_enumerator}
282
+ context "#objects" do
283
+ subject {@enumerable.objects}
320
284
  specify {subject.should be_an_enumerator}
321
285
  specify {subject.each { |value| value.should be_a_term }}
286
+ context ":unique => false" do
287
+ subject {@enumerable.objects(:unique => false)}
288
+ specify {subject.should be_an_enumerator}
289
+ specify {subject.each { |value| value.should be_a_term }}
290
+ end
322
291
  end
323
- end
324
292
 
325
- describe "#has_object?" do
326
- it "has all objects" do
327
- checked = []
328
- @statements.each do |statement|
329
- subject.should have_object(statement.object) unless checked.include?(statement.object)
330
- 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
331
302
  end
332
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
333
- subject.should_not have_object(uri)
334
303
  end
335
- end
336
304
 
337
- describe "#each_object" do
338
- subject {@enumerable.each_object}
339
- it {should be_an_enumerator}
340
- it "has all objects" do
341
- objects = @statements.map { |s| s.object }.uniq
342
- subject.to_a.size.should == objects.size
343
- subject do |term|
344
- term.should be_a_term
345
- objects.should include(term)
346
- 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)}}
347
311
  end
348
- end
349
312
 
350
- describe "#enum_object" do
351
- subject {@enumerable.enum_object}
352
- it {should be_an_enumerator}
353
- it {should be_countable}
354
- it "should have all objects" do
355
- subject.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
356
319
  end
357
320
  end
358
321
 
359
- describe "#contexts" do
360
- subject {@enumerable.contexts}
361
- specify {subject.should be_an_enumerator}
362
- specify {subject.each { |value| value.should be_a_resource }}
363
- context ":unique => false" do
364
- subject {@enumerable.contexts(:unique => false)}
322
+ context "when enumerating contexts" do
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)}
327
+
328
+ its(:contexts) {should be_an_enumerator}
329
+ describe "#contexts" do
330
+ subject {@enumerable.contexts}
365
331
  specify {subject.should be_an_enumerator}
366
- 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
335
+ context ":unique => false" do
336
+ subject {@enumerable.contexts(:unique => false)}
337
+ specify {subject.should be_an_enumerator}
338
+ it "values should be resources" do
339
+ subject.each { |value| value.should be_a_resource }
340
+ end
341
+ end
367
342
  end
368
- end
369
343
 
370
- describe "#has_context?" do
371
- it "has all contexts" do
372
- checked = []
373
- @statements.each do |statement|
374
- subject.should have_context(statement.context) if statement.has_context?
344
+ it "should implement #has_context?" do
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
375
353
  end
376
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
377
- subject.should_not have_context(uri)
378
354
  end
379
- end
380
355
 
381
- describe "#each_context" do
382
- subject {@enumerable.each_context}
383
- it {should be_an_enumerator}
384
- it "has all contexts" do
385
- contexts = @statements.map { |s| s.context }.uniq
386
- contexts.delete nil
387
- subject.to_a.size.should == contexts.size
388
- subject do |term|
389
- term.should be_a_resource
390
- contexts.should include(term)
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
362
+ end
363
+ end
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)}
391
369
  end
392
370
  end
393
- end
394
371
 
395
- describe "#enum_context" do
396
- subject {@enumerable.enum_context}
397
- it {should be_an_enumerator}
398
- it {should be_countable}
399
- it "should have all contexts" do
400
- subject.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
401
378
  end
402
379
  end
403
380
 
404
- describe "#each_graph" do
405
- subject {@enumerable.each_graph}
406
- it {should be_an_enumerator}
407
- it "has all graphs" do
408
- subject {|value| value.should be_a_graph}
381
+ context "when enumerating graphs" do
382
+ it {should respond_to(:each_graph)}
383
+ it {should respond_to(:enum_graph)}
384
+
385
+ describe "#each_graph" do
386
+ subject {@enumerable.each_graph}
387
+ it {should be_an_enumerator}
388
+ specify {subject.each { |value| value.should be_a_graph }}
409
389
  end
410
- end
411
390
 
412
- describe "#enum_graph" do
413
- subject {@enumerable.enum_graph}
414
- it {should be_an_enumerator}
415
- it {should be_countable}
416
- it "should have all graphs" do
417
- subject.to_a.should =~ @enumerable.each_graph.to_a
391
+ describe "#enum_graph" do
392
+ subject {@enumerable.enum_graph}
393
+ it {subject.should be_an_enumerator}
394
+ it {subject.should be_countable}
395
+ it "enumerates the same as #each_graph" do
396
+ subject.to_a.should == @enumerable.each_graph.to_a
397
+ end
418
398
  end
419
399
  end
420
400
 
421
- describe "#to_hash" do
422
- subject {@enumerable.to_hash}
423
- it {should be_a(Hash)}
424
- it "should have keys for each subject" do
425
- subject.keys.size.should == @enumerable.subjects.to_a.size
401
+ context "when converting" do
402
+ it {should respond_to(:to_hash)}
403
+ its(:to_hash) {should be_instance_of(Hash)}
404
+ context "#to_hash" do
405
+ it "should have as many keys as subjects" do
406
+ subject.to_hash.keys.size.should == @enumerable.subjects.to_a.size
407
+ end
426
408
  end
427
409
  end
428
410
 
429
- describe "#dump" do
430
- subject {@enumerable.dump(:ntriples)}
431
- it "has N-Triples representation" do
432
- subject.should == RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
411
+ context "when dumping" do
412
+ it {should respond_to(:dump)}
413
+
414
+ it "should implement #dump" do
415
+ subject.dump(:ntriples).should == RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
433
416
  end
434
-
417
+
435
418
  it "raises error on unknown format" do
436
- lambda {@enumerable.dump(:foobar)}.should raise_error(RDF::WriterError, /No writer found/)
419
+ lambda {subject.dump(:foobar)}.should raise_error(RDF::WriterError, /No writer found/)
437
420
  end
438
421
  end
439
-
440
- context "#to_{writer}" do
441
- it "should write to a writer" do
442
- writer = mock("writer")
443
- writer.should_receive(:buffer)
444
- RDF::Writer.should_receive(:for).with(:a_writer).and_return(writer)
445
- subject.send(:to_a_writer)
446
- end
447
- end
448
-
449
422
  end
450
423
  end