rdf-spec 1.1.5 → 1.1.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd937b914454e1beb178c07aea7f67241ef6199a
4
- data.tar.gz: 5025462c4843c791c182d73f82e7901dacd8cb24
3
+ metadata.gz: 53805ce5de30f3b9a172c530b8085c6171b559f3
4
+ data.tar.gz: 18b110beea3b90a51a7bfb8054c3bdace1614ceb
5
5
  SHA512:
6
- metadata.gz: 673c8f7b7fa7e7666585833640e61787dcdb9f5edcdf98bc3947b54832aee0d58bc4bc60cfac23fae05ffb9e96a10cc343451cf823a2726d8481e0046f0f2ee0
7
- data.tar.gz: d6ccea63ee7aa054de864c8535287e84ddb6cbb791d878c7d5a10e6381addf1c6377ce5a9455bf1968dbda0933a8ff8fdf226fa78cbe8ac35921448ce5ea0635
6
+ metadata.gz: 227cb6a7a6073e11f4886d7997a61173f796dbbed68458b0a2a4d217fedfb5fb239a669dfb7900c53a2ca3dea7659d82a7ab6a6c3edea2f0df75887873f5599e
7
+ data.tar.gz: 64dfe87b381a0b023f37d83722ab852d892e543b0207e4a630f3e1f81b9fe5754525715ec23b6b9f6ec9faa1508e04d31479aef75e851564f6eb76d286f37e45
data/CREDITS CHANGED
@@ -1 +1,2 @@
1
1
  * John Fieber <jrf@ursamaris.org>
2
+ * Tom Johnson <johnson.tom@gmail.com>
data/README CHANGED
@@ -59,6 +59,7 @@ follows:
59
59
  ## Contributors
60
60
 
61
61
  * [John Fieber](http://github.com/jfieber) - <http://github.com/jfieber>
62
+ * [Tom Johnson](https://github.com/no-reply) - <https://github.com/no-reply>
62
63
 
63
64
  ## Contributing
64
65
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.5
1
+ 1.1.13
@@ -1,27 +1,28 @@
1
1
  require 'rdf/spec'
2
2
 
3
- module RDF_Countable
4
- extend RSpec::SharedContext
3
+ RSpec.shared_examples 'an RDF::Countable' do
5
4
  include RDF::Spec::Matchers
6
5
 
7
- before :each do
8
- raise '+@countable+ must be defined in a before(:each) block' unless instance_variable_get('@countable')
6
+ before do
7
+ raise 'countable must be set with `let(:countable)' unless
8
+ defined? countable
9
9
 
10
10
  @statements = RDF::Spec.quads
11
11
 
12
- if @countable.empty?
13
- if (@countable.writable? rescue false)
14
- @countable.insert_statements(@statements)
15
- elsif @countable.respond_to?(:<<)
16
- @statements.each { |statement| @countable << statement }
12
+ if countable.empty?
13
+ if (countable.writable? rescue false)
14
+ countable.send(:insert_statements, @statements)
15
+ elsif countable.respond_to?(:<<)
16
+ @statements.each { |statement| countable << statement }
17
17
  else
18
- raise "+@countable+ must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
18
+ raise "+countable+ must respond to #<< or be pre-populated with the" \
19
+ "statements in #{RDF::Spec::TRIPLES_FILE} in a before block"
19
20
  end
20
21
  end
21
22
  end
22
23
 
23
24
  describe RDF::Countable do
24
- subject {@countable}
25
+ subject {countable}
25
26
 
26
27
  it {should respond_to(:empty?)}
27
28
  it {should_not be_empty}
@@ -44,3 +45,25 @@ module RDF_Countable
44
45
  end
45
46
  end
46
47
  end
48
+
49
+ ##
50
+ # @deprecated use `it_behaves_like "an RDF::Countable"` instead
51
+ module RDF_Countable
52
+ extend RSpec::SharedContext
53
+ include RDF::Spec::Matchers
54
+
55
+ def self.included(mod)
56
+ warn "[DEPRECATION] `RDF_Countable` is deprecated. "\
57
+ "Please use `it_behaves_like 'an RDF::Countable'`"
58
+ end
59
+
60
+ describe 'examples for' do
61
+ include_examples 'an RDF::Countable' do
62
+ let(:countable) { @countable }
63
+
64
+ before do
65
+ raise '@countable must be defined' unless defined?(countable)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -14,35 +14,53 @@ require 'rdf/spec'
14
14
  # File.delete('test.db') if File.exists?('test.db')
15
15
  # end
16
16
  #
17
- # include RDF_Repository
17
+ # it_behaves_like 'an RDF::Repository'
18
18
  # end
19
19
  #end
20
- module RDF_Durable
21
- extend RSpec::SharedContext
20
+ RSpec.shared_examples 'an RDF::Durable' do
22
21
  include RDF::Spec::Matchers
23
22
 
24
23
  before :each do
25
- raise '+@load_durable+ must be defined in a before(:each) block' unless instance_variable_get('@load_durable')
24
+ raise '+@load_durable+ must be defined in a before(:each) block' unless
25
+ instance_variable_get('@load_durable')
26
26
  end
27
27
 
28
- describe RDF::Durable do
29
- subject {@load_durable.call}
30
- it {should respond_to(:durable?)}
31
- it "should support #durable?" do
32
- expect([true,false]).to be_member(subject.durable?)
33
- end
28
+ subject {@load_durable.call}
34
29
 
35
- it {should respond_to(:nondurable?)}
36
- it "should support #nondurable?" do
37
- expect([true,false]).to be_member(@load_durable.call.nondurable?)
38
- end
39
- its(:nondurable?) {should_not == subject.durable?}
30
+ it { should respond_to(:durable?) }
31
+
32
+ it "should support #durable?" do
33
+ expect([true,false]).to be_member(subject.durable?)
34
+ end
35
+
36
+ it {should respond_to(:nondurable?)}
37
+
38
+ it "should support #nondurable?" do
39
+ expect([true,false]).to be_member(@load_durable.call.nondurable?)
40
+ end
41
+
42
+ its(:nondurable?) {should_not == subject.durable?}
40
43
 
41
- it "should save contents between instantiations" do
42
- if subject.durable?
43
- subject.load(RDF::Spec::TRIPLES_FILE)
44
- expect(subject.count).to eq File.readlines(RDF::Spec::TRIPLES_FILE).size
45
- end
44
+ it "should save contents between instantiations" do
45
+ if subject.durable?
46
+ subject.load(RDF::Spec::TRIPLES_FILE)
47
+ expect(subject.count).to eq File.readlines(RDF::Spec::TRIPLES_FILE).size
46
48
  end
47
49
  end
48
50
  end
51
+
52
+ ##
53
+ # @deprecated use `it_behaves_like "an RDF::Durable"` instead
54
+ module RDF_Durable
55
+ extend RSpec::SharedContext
56
+ include RDF::Spec::Matchers
57
+
58
+ def self.included(mod)
59
+ warn "[DEPRECATION] `RDF_Durable` is deprecated. "\
60
+ "Please use `it_behaves_like 'an RDF::Durable'`"
61
+ end
62
+
63
+ describe 'examples for' do
64
+ include_examples 'an RDF::Durable'
65
+ end
66
+ end
@@ -1,471 +1,491 @@
1
1
  require 'rdf/spec'
2
2
 
3
- module RDF_Enumerable
4
- extend RSpec::SharedContext
3
+ RSpec.shared_examples 'an RDF::Enumerable' do
5
4
  include RDF::Spec::Matchers
6
5
 
7
- before :each do
8
- raise '+@enumerable+ must be defined in a before(:each) block' unless instance_variable_get('@enumerable')
6
+ before do
7
+ raise 'enumerable must be set with `let(:enumerable)' unless
8
+ defined? enumerable
9
9
 
10
10
  @statements ||= RDF::Spec.quads
11
11
 
12
- if @enumerable.empty?
13
- if (@enumerable.writable? rescue false)
14
- @enumerable.insert(*@statements)
15
- elsif @enumerable.respond_to?(:<<)
16
- @statements.each { |statement| @enumerable << statement }
12
+ if enumerable.empty?
13
+ if (enumerable.writable? rescue false)
14
+ enumerable.insert(*@statements)
15
+ elsif enumerable.respond_to?(:<<)
16
+ @statements.each { |statement| enumerable << statement }
17
17
  else
18
18
  raise "@enumerable must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
19
19
  end
20
20
  end
21
21
 
22
- @supports_context = @enumerable.supports?(:context) rescue true
22
+ @supports_context = enumerable.supports?(:context) rescue true
23
23
  end
24
24
 
25
- describe RDF::Enumerable do
26
- let(:subject_count) {@statements.map(&:subject).uniq.length}
27
- let(:bnode_subject_count) {@statements.map(&:subject).uniq.select(&:node?).length}
28
- let(:non_bnode_statements) {@statements.reject {|s| s.subject.node? || s.object.node?}}
25
+ let(:subject_count) {@statements.map(&:subject).uniq.length}
26
+ let(:bnode_subject_count) {@statements.map(&:subject).uniq.select(&:node?).length}
27
+ let(:non_bnode_statements) {@statements.reject {|s| s.subject.node? || s.object.node?}}
29
28
 
30
- subject {@enumerable}
31
- it {should respond_to(:supports?)}
29
+ subject { enumerable }
30
+ it {should respond_to(:supports?)}
31
+
32
+ describe "valid?" do
33
+ it "reports validity" do
34
+ if subject.supports?(:validity)
35
+ should be_valid
36
+ else
37
+ expect {subject.valid?}.to raise_error(NotImplementedError)
38
+ end
39
+ end
32
40
 
33
- describe "valid?" do
34
- it "reports validity" do
41
+ it "returns false if any statement is invalid" do
42
+ if subject.respond_to?(:<<) && (subject.writable? rescue true)
43
+ s = RDF::Statement.from([nil, nil, nil])
35
44
  if subject.supports?(:validity)
36
- should be_valid
45
+ expect(s).not_to be_valid
46
+ subject << s
47
+ expect(subject).not_to be_valid
37
48
  else
38
49
  expect {subject.valid?}.to raise_error(NotImplementedError)
39
50
  end
40
- end
41
-
42
- it "returns false if any statement is invalid" do
43
- if subject.respond_to?(:<<) && (subject.writable? rescue true)
44
- s = RDF::Statement.from([nil, nil, nil])
45
- if subject.supports?(:validity)
46
- expect(s).not_to be_valid
47
- subject << s
48
- expect(subject).not_to be_valid
49
- else
50
- expect {subject.valid?}.to raise_error(NotImplementedError)
51
- end
52
- else
53
- pending("can't add statement to immutable enumerable")
54
- end
51
+ else
52
+ skip("can't add statement to immutable enumerable")
55
53
  end
56
54
  end
55
+ end
57
56
 
58
- context "when counting statements" do
59
- it {should respond_to(:empty?)}
60
- it {should_not be_empty}
61
- it {should respond_to(:count)}
62
- its(:count) {should == @statements.size}
63
- it {should respond_to(:size)}
64
- its(:size) {should == @statements.size}
65
-
66
- context "and empty" do
67
- subject {[].extend(RDF::Enumerable)}
68
- it {should be_empty}
69
- its(:count) {should == 0}
70
- its(:size) {should == 0}
71
- end
57
+ context "when counting statements" do
58
+ it {should respond_to(:empty?)}
59
+ it {should_not be_empty}
60
+ it {should respond_to(:count)}
61
+ its(:count) {should == @statements.size}
62
+ it {should respond_to(:size)}
63
+ its(:size) {should == @statements.size}
64
+
65
+ context "and empty" do
66
+ subject {[].extend(RDF::Enumerable)}
67
+ it {should be_empty}
68
+ its(:count) {should == 0}
69
+ its(:size) {should == 0}
72
70
  end
71
+ end
73
72
 
74
- context "when enumerating statements" do
75
- it {should respond_to(:statements)}
76
- its(:statements) {should be_an_enumerator}
73
+ context "when enumerating statements" do
74
+ it {should respond_to(:statements)}
75
+ its(:statements) {should be_an_enumerator}
77
76
 
78
- context "#statements" do
79
- specify {expect(subject.statements.to_a.size).to eq @statements.size}
80
- specify {subject.statements.each { |statement| expect(statement).to be_a_statement }}
81
- end
77
+ context "#statements" do
78
+ specify {expect(subject.statements.to_a.size).to eq @statements.size}
79
+ specify {subject.statements.each { |statement| expect(statement).to be_a_statement }}
80
+ end
82
81
 
83
- it {should respond_to(:has_statement?)}
84
- context "#has_statement?" do
85
- let(:unknown_statement) {RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)}
86
- it "should have all statements" do
87
- # 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.
88
- non_bnode_statements.each do |statement|
89
- expect(subject).to have_statement(statement)
90
- end
82
+ it {should respond_to(:has_statement?)}
83
+ context "#has_statement?" do
84
+ let(:unknown_statement) {RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)}
85
+ it "should have all statements" do
86
+ # 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.
87
+ non_bnode_statements.each do |statement|
88
+ expect(subject).to have_statement(statement)
91
89
  end
90
+ end
92
91
 
93
- it "does not have statement in different context" do
94
- if @supports_context
95
- context = RDF::URI.new("urn:context:1")
96
- non_bnode_statements.each do |statement|
97
- s = statement.dup
98
- s.context = context
99
- expect(subject).not_to have_statement(s)
100
- end
92
+ it "does not have statement in different context" do
93
+ if @supports_context
94
+ context = RDF::URI.new("urn:context:1")
95
+ non_bnode_statements.each do |statement|
96
+ s = statement.dup
97
+ s.context = context
98
+ expect(subject).not_to have_statement(s)
101
99
  end
102
100
  end
103
-
104
- it "does not have an unknown statement" do
105
- expect(subject).not_to have_statement(unknown_statement)
106
- end
107
101
  end
108
102
 
109
- it {should respond_to(:each_statement)}
110
- its(:each_statement) {should be_an_enumerator}
111
- it "should implement #each_statement" do
112
- subject.each_statement { |statement| expect(statement).to be_a_statement }
103
+ it "does not have an unknown statement" do
104
+ expect(subject).not_to have_statement(unknown_statement)
113
105
  end
106
+ end
114
107
 
115
- it {should respond_to(:enum_statement)}
116
- its(:enum_statement) {should be_an_enumerator}
117
- its(:enum_statement) {should be_countable}
118
- its(:enum_statement) {should be_enumerable}
119
- its(:enum_statement) {should be_queryable}
120
- context "#enum_statement" do
121
- it "should enumerate all statements" do
122
- expect(subject.enum_statement.count).to eq @enumerable.each_statement.count
123
- subject.enum_statement.each do |s|
124
- expect(s).to be_a_statement
125
- expect(@enumerable.each_statement.to_a).to include(s) unless s.has_blank_nodes?
126
- end
108
+ it {should respond_to(:each_statement)}
109
+ its(:each_statement) {should be_an_enumerator}
110
+ it "should implement #each_statement" do
111
+ subject.each_statement { |statement| expect(statement).to be_a_statement }
112
+ end
113
+
114
+ it {should respond_to(:enum_statement)}
115
+ its(:enum_statement) {should be_an_enumerator}
116
+ its(:enum_statement) {should be_countable}
117
+ its(:enum_statement) {should be_enumerable}
118
+ its(:enum_statement) {should be_queryable}
119
+ context "#enum_statement" do
120
+ it "should enumerate all statements" do
121
+ expect(subject.enum_statement.count).to eq enumerable.each_statement.count
122
+ subject.enum_statement.each do |s|
123
+ expect(s).to be_a_statement
124
+ expect(enumerable.each_statement.to_a).to include(s) unless s.has_blank_nodes?
127
125
  end
128
126
  end
129
127
  end
128
+ end
130
129
 
131
- context "when enumerating triples" do
132
- it {should respond_to(:triples)}
133
- it {should respond_to(:has_triple?)}
134
- it {should respond_to(:each_triple)}
135
- it {should respond_to(:enum_triple)}
130
+ context "when enumerating triples" do
131
+ it {should respond_to(:triples)}
132
+ it {should respond_to(:has_triple?)}
133
+ it {should respond_to(:each_triple)}
134
+ it {should respond_to(:enum_triple)}
136
135
 
137
- its(:triples) {should be_an_enumerator}
138
- context "#triples" do
139
- specify {expect(subject.triples.to_a.size).to eq @statements.size}
140
- specify {subject.triples.each { |triple| expect(triple).to be_a_triple }}
141
- end
136
+ its(:triples) {should be_an_enumerator}
137
+ context "#triples" do
138
+ specify {expect(subject.triples.to_a.size).to eq @statements.size}
139
+ specify {subject.triples.each { |triple| expect(triple).to be_a_triple }}
140
+ end
142
141
 
143
- context "#has_triple?" do
144
- specify do
145
- non_bnode_statements.each do |statement|
146
- expect(subject).to have_triple(statement.to_triple)
147
- end
142
+ context "#has_triple?" do
143
+ specify do
144
+ non_bnode_statements.each do |statement|
145
+ expect(subject).to have_triple(statement.to_triple)
148
146
  end
149
147
  end
148
+ end
150
149
 
151
- its(:each_triple) {should be_an_enumerator}
152
- context "#each_triple" do
153
- specify {subject.each_triple { |*triple| expect(triple).to be_a_triple }}
154
- it "should iterate over all triples" do
155
- subject.each_triple do |*triple|
156
- triple.each {|r| expect(r).to be_a_term}
157
- expect(@enumerable).to have_triple(triple) unless triple.any?(&:node?)
158
- end
150
+ its(:each_triple) {should be_an_enumerator}
151
+ context "#each_triple" do
152
+ specify {subject.each_triple { |*triple| expect(triple).to be_a_triple }}
153
+ it "should iterate over all triples" do
154
+ subject.each_triple do |*triple|
155
+ triple.each {|r| expect(r).to be_a_term}
156
+ expect(enumerable).to have_triple(triple) unless triple.any?(&:node?)
159
157
  end
160
158
  end
159
+ end
161
160
 
162
- its(:enum_triple) {should be_an_enumerator}
163
- its(:enum_triple) {should be_countable}
164
- context "#enum_triple" do
165
- it "should enumerate all triples" do
166
- expect(subject.enum_triple.count).to eq @enumerable.each_triple.count
167
- subject.enum_triple.each do |s, p, o|
168
- [s, p, o].each {|r| expect(r).to be_a_term}
169
- expect(@enumerable).to have_triple([s, p, o]) unless [s, p, o].any?(&:node?)
170
- end
161
+ its(:enum_triple) {should be_an_enumerator}
162
+ its(:enum_triple) {should be_countable}
163
+ context "#enum_triple" do
164
+ it "should enumerate all triples" do
165
+ expect(subject.enum_triple.count).to eq enumerable.each_triple.count
166
+ subject.enum_triple.each do |s, p, o|
167
+ [s, p, o].each {|r| expect(r).to be_a_term}
168
+ expect(enumerable).to have_triple([s, p, o]) unless [s, p, o].any?(&:node?)
171
169
  end
172
170
  end
173
171
  end
172
+ end
174
173
 
175
- context "when enumerating quads" do
176
- it {should respond_to(:quads)}
177
- it {should respond_to(:has_quad?)}
178
- it {should respond_to(:each_quad)}
179
- it {should respond_to(:enum_quad)}
174
+ context "when enumerating quads" do
175
+ it {should respond_to(:quads)}
176
+ it {should respond_to(:has_quad?)}
177
+ it {should respond_to(:each_quad)}
178
+ it {should respond_to(:enum_quad)}
180
179
 
181
- its(:quads) {should be_an_enumerator}
182
- context "#quads" do
183
- specify {expect(subject.quads.to_a.size).to eq @statements.size}
184
- specify {subject.quads.each { |quad| expect(quad).to be_a_quad }}
185
- end
180
+ its(:quads) {should be_an_enumerator}
181
+ context "#quads" do
182
+ specify {expect(subject.quads.to_a.size).to eq @statements.size}
183
+ specify {subject.quads.each { |quad| expect(quad).to be_a_quad }}
184
+ end
186
185
 
187
- context "#has_quad?" do
188
- specify do
189
- if @supports_context
190
- non_bnode_statements.each do |statement|
191
- expect(subject).to have_quad(statement.to_quad)
192
- end
186
+ context "#has_quad?" do
187
+ specify do
188
+ if @supports_context
189
+ non_bnode_statements.each do |statement|
190
+ expect(subject).to have_quad(statement.to_quad)
193
191
  end
194
192
  end
195
193
  end
194
+ end
196
195
 
197
- its(:each_quad) {should be_an_enumerator}
198
- context "#each_quad" do
199
- specify {subject.each_quad {|*quad| expect(quad).to be_a_quad }}
200
- it "should iterate over all quads" do
201
- subject.each_quad do |*quad|
202
- quad.compact.each {|r| expect(r).to be_a_term}
203
- expect(@enumerable).to have_quad(quad) unless quad.compact.any?(&:node?)
204
- end
196
+ its(:each_quad) {should be_an_enumerator}
197
+ context "#each_quad" do
198
+ specify {subject.each_quad {|*quad| expect(quad).to be_a_quad }}
199
+ it "should iterate over all quads" do
200
+ subject.each_quad do |*quad|
201
+ quad.compact.each {|r| expect(r).to be_a_term}
202
+ expect(enumerable).to have_quad(quad) unless quad.compact.any?(&:node?)
205
203
  end
206
204
  end
205
+ end
207
206
 
208
- its(:enum_quad) {should be_an_enumerator}
209
- its(:enum_quad) {should be_countable}
210
- context "#enum_quad" do
211
- it "should enumerate all quads" do
212
- expect(subject.enum_quad.count).to eq @enumerable.each_quad.count
213
- subject.enum_quad.each do |s, p, o, c|
214
- [s, p, o, c].compact.each {|r| expect(r).to be_a_term}
215
- expect(@enumerable).to have_quad([s, p, o, c]) unless [s, p, o].any?(&:node?)
216
- end
207
+ its(:enum_quad) {should be_an_enumerator}
208
+ its(:enum_quad) {should be_countable}
209
+ context "#enum_quad" do
210
+ it "should enumerate all quads" do
211
+ expect(subject.enum_quad.count).to eq enumerable.each_quad.count
212
+ subject.enum_quad.each do |s, p, o, c|
213
+ [s, p, o, c].compact.each {|r| expect(r).to be_a_term}
214
+ expect(enumerable).to have_quad([s, p, o, c]) unless [s, p, o].any?(&:node?)
217
215
  end
218
216
  end
219
217
  end
218
+ end
220
219
 
221
- context "when enumerating subjects" do
222
- let(:subjects) {subject.map { |s| s.subject }.reject(&:node?).uniq}
223
- it {should respond_to(:subjects)}
224
- it {should respond_to(:has_subject?)}
225
- it {should respond_to(:each_subject)}
226
- it {should respond_to(:enum_subject)}
227
-
228
- its(:subjects) {should be_an_enumerator}
229
- context "#subjects" do
230
- subject {@enumerable.subjects}
220
+ context "when enumerating subjects" do
221
+ let(:subjects) {subject.map { |s| s.subject }.reject(&:node?).uniq}
222
+ it {should respond_to(:subjects)}
223
+ it {should respond_to(:has_subject?)}
224
+ it {should respond_to(:each_subject)}
225
+ it {should respond_to(:enum_subject)}
226
+
227
+ its(:subjects) {should be_an_enumerator}
228
+ context "#subjects" do
229
+ subject { enumerable.subjects }
230
+ specify {expect(subject).to be_an_enumerator}
231
+ specify {subject.each { |value| expect(value).to be_a_resource }}
232
+ context ":unique => false" do
233
+ subject { enumerable.subjects(:unique => false) }
231
234
  specify {expect(subject).to be_an_enumerator}
232
235
  specify {subject.each { |value| expect(value).to be_a_resource }}
233
- context ":unique => false" do
234
- subject {@enumerable.subjects(:unique => false)}
235
- specify {expect(subject).to be_an_enumerator}
236
- specify {subject.each { |value| expect(value).to be_a_resource }}
237
- end
238
236
  end
237
+ end
239
238
 
240
- context "#has_subject?" do
241
- specify do
242
- checked = []
243
- non_bnode_statements.each do |statement|
244
- expect(@enumerable).to have_subject(statement.subject) unless checked.include?(statement.subject)
245
- checked << statement.subject
246
- end
247
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
248
- expect(@enumerable).not_to have_subject(uri)
239
+ context "#has_subject?" do
240
+ specify do
241
+ checked = []
242
+ non_bnode_statements.each do |statement|
243
+ expect(enumerable).to have_subject(statement.subject) unless checked.include?(statement.subject)
244
+ checked << statement.subject
249
245
  end
246
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
247
+ expect(enumerable).not_to have_subject(uri)
250
248
  end
249
+ end
251
250
 
252
- its(:each_subject) {should be_an_enumerator}
253
- context "#each_subject" do
254
- specify {expect(subject.each_subject.reject(&:node?).size).to eq subjects.reject(&:node?).size}
255
- specify {subject.each_subject {|value| expect(value).to be_a_resource}}
256
- specify {subject.each_subject {|value| expect(subjects).to include(value) unless value.node?}}
257
- end
251
+ its(:each_subject) {should be_an_enumerator}
252
+ context "#each_subject" do
253
+ specify {expect(subject.each_subject.reject(&:node?).size).to eq subjects.reject(&:node?).size}
254
+ specify {subject.each_subject {|value| expect(value).to be_a_resource}}
255
+ specify {subject.each_subject {|value| expect(subjects).to include(value) unless value.node?}}
256
+ end
258
257
 
259
- its(:enum_subject) {should be_an_enumerator}
260
- its(:enum_subject) {should be_countable}
261
- context "#enum_subject" do
262
- specify {expect(subject.enum_subject.to_a.reject(&:node?).size).to eq subjects.reject(&:node?).size}
263
- it "should enumerate all subjects" do
264
- subject.enum_subject.each do |s|
265
- expect(s).to be_a_resource
266
- expect(subjects.to_a).to include(s) unless s.node?
267
- end
258
+ its(:enum_subject) {should be_an_enumerator}
259
+ its(:enum_subject) {should be_countable}
260
+ context "#enum_subject" do
261
+ specify {expect(subject.enum_subject.to_a.reject(&:node?).size).to eq subjects.reject(&:node?).size}
262
+ it "should enumerate all subjects" do
263
+ subject.enum_subject.each do |s|
264
+ expect(s).to be_a_resource
265
+ expect(subjects.to_a).to include(s) unless s.node?
268
266
  end
269
267
  end
270
268
  end
269
+ end
271
270
 
272
- context "when enumerating predicates" do
273
- let(:predicates) {@statements.map { |s| s.predicate }.uniq}
274
- it {should respond_to(:predicates)}
275
- it {should respond_to(:has_predicate?)}
276
- it {should respond_to(:each_predicate)}
277
- it {should respond_to(:enum_predicate)}
278
-
279
- its(:predicates) {should be_an_enumerator}
280
- context "#predicates" do
281
- subject {@enumerable.predicates}
271
+ context "when enumerating predicates" do
272
+ let(:predicates) {@statements.map { |s| s.predicate }.uniq}
273
+ it {should respond_to(:predicates)}
274
+ it {should respond_to(:has_predicate?)}
275
+ it {should respond_to(:each_predicate)}
276
+ it {should respond_to(:enum_predicate)}
277
+
278
+ its(:predicates) {should be_an_enumerator}
279
+ context "#predicates" do
280
+ subject { enumerable.predicates }
281
+ specify {expect(subject).to be_an_enumerator}
282
+ specify {subject.each { |value| expect(value).to be_a_uri }}
283
+ context ":unique => false" do
284
+ subject { enumerable.predicates(:unique => false) }
282
285
  specify {expect(subject).to be_an_enumerator}
283
286
  specify {subject.each { |value| expect(value).to be_a_uri }}
284
- context ":unique => false" do
285
- subject {@enumerable.predicates(:unique => false)}
286
- specify {expect(subject).to be_an_enumerator}
287
- specify {subject.each { |value| expect(value).to be_a_uri }}
288
- end
289
287
  end
288
+ end
290
289
 
291
- context "#has_predicate?" do
292
- specify do
293
- checked = []
294
- @statements.each do |statement|
295
- expect(@enumerable).to have_predicate(statement.predicate) unless checked.include?(statement.predicate)
296
- checked << statement.predicate
297
- end
298
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
299
- expect(@enumerable).not_to have_predicate(uri)
290
+ context "#has_predicate?" do
291
+ specify do
292
+ checked = []
293
+ @statements.each do |statement|
294
+ expect(enumerable).to have_predicate(statement.predicate) unless checked.include?(statement.predicate)
295
+ checked << statement.predicate
300
296
  end
297
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
298
+ expect(enumerable).not_to have_predicate(uri)
301
299
  end
300
+ end
302
301
 
303
- its(:each_predicate) {should be_an_enumerator}
304
- context "#each_predicate" do
305
- specify {expect(subject.each_predicate.to_a.size).to eq predicates.size}
306
- specify {subject.each_predicate {|value| expect(value).to be_a_uri}}
307
- specify {subject.each_predicate {|value| expect(predicates).to include(value)}}
308
- end
302
+ its(:each_predicate) {should be_an_enumerator}
303
+ context "#each_predicate" do
304
+ specify {expect(subject.each_predicate.to_a.size).to eq predicates.size}
305
+ specify {subject.each_predicate {|value| expect(value).to be_a_uri}}
306
+ specify {subject.each_predicate {|value| expect(predicates).to include(value)}}
307
+ end
309
308
 
310
- its(:enum_predicate) {should be_an_enumerator}
311
- its(:enum_predicate) {should be_countable}
312
- context "#enum_predicate" do
313
- it "should enumerate all predicates" do
314
- expect(subject.enum_predicate.to_a).to include(*predicates)
315
- end
309
+ its(:enum_predicate) {should be_an_enumerator}
310
+ its(:enum_predicate) {should be_countable}
311
+ context "#enum_predicate" do
312
+ it "should enumerate all predicates" do
313
+ expect(subject.enum_predicate.to_a).to include(*predicates)
316
314
  end
317
315
  end
316
+ end
318
317
 
319
- context "when enumerating objects" do
320
- let(:objects) {subject.map(&:object).reject(&:node?).uniq}
321
- it {should respond_to(:objects)}
322
- it {should respond_to(:has_object?)}
323
- it {should respond_to(:each_object)}
324
- it {should respond_to(:enum_object)}
325
-
326
- its(:objects) {should be_an_enumerator}
327
- context "#objects" do
328
- subject {@enumerable.objects}
318
+ context "when enumerating objects" do
319
+ let(:objects) {subject.map(&:object).reject(&:node?).uniq}
320
+ it {should respond_to(:objects)}
321
+ it {should respond_to(:has_object?)}
322
+ it {should respond_to(:each_object)}
323
+ it {should respond_to(:enum_object)}
324
+
325
+ its(:objects) {should be_an_enumerator}
326
+ context "#objects" do
327
+ subject { enumerable.objects }
328
+ specify {expect(subject).to be_an_enumerator}
329
+ specify {subject.each { |value| expect(value).to be_a_term }}
330
+ context ":unique => false" do
331
+ subject { enumerable.objects(:unique => false) }
329
332
  specify {expect(subject).to be_an_enumerator}
330
333
  specify {subject.each { |value| expect(value).to be_a_term }}
331
- context ":unique => false" do
332
- subject {@enumerable.objects(:unique => false)}
333
- specify {expect(subject).to be_an_enumerator}
334
- specify {subject.each { |value| expect(value).to be_a_term }}
335
- end
336
334
  end
335
+ end
337
336
 
338
- context "#has_object?" do
339
- specify do
340
- checked = []
341
- non_bnode_statements.each do |statement|
342
- expect(@enumerable).to have_object(statement.object) unless checked.include?(statement.object)
343
- checked << statement.object
344
- end
345
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
346
- expect(@enumerable).not_to have_object(uri)
337
+ context "#has_object?" do
338
+ specify do
339
+ checked = []
340
+ non_bnode_statements.each do |statement|
341
+ expect(enumerable).to have_object(statement.object) unless checked.include?(statement.object)
342
+ checked << statement.object
347
343
  end
344
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
345
+ expect(enumerable).not_to have_object(uri)
348
346
  end
347
+ end
349
348
 
350
- its(:each_object) {should be_an_enumerator}
351
- context "#each_object" do
352
- specify {expect(subject.each_object.reject(&:node?).size).to eq objects.size}
353
- specify {subject.each_object {|value| expect(value).to be_a_term}}
354
- specify {subject.each_object {|value| expect(objects).to include(value) unless value.node?}}
355
- end
349
+ its(:each_object) {should be_an_enumerator}
350
+ context "#each_object" do
351
+ specify {expect(subject.each_object.reject(&:node?).size).to eq objects.size}
352
+ specify {subject.each_object {|value| expect(value).to be_a_term}}
353
+ specify {subject.each_object {|value| expect(objects).to include(value) unless value.node?}}
354
+ end
356
355
 
357
- its(:enum_object) {should be_an_enumerator}
358
- its(:enum_object) {should be_countable}
359
- context "#enum_object" do
360
- it "should enumerate all objects" do
361
- subject.enum_object.each do |o|
362
- expect(o).to be_a_term
363
- expect(objects.to_a).to include(o) unless o.node?
364
- end
356
+ its(:enum_object) {should be_an_enumerator}
357
+ its(:enum_object) {should be_countable}
358
+ context "#enum_object" do
359
+ it "should enumerate all objects" do
360
+ subject.enum_object.each do |o|
361
+ expect(o).to be_a_term
362
+ expect(objects.to_a).to include(o) unless o.node?
365
363
  end
366
364
  end
367
365
  end
366
+ end
368
367
 
369
- context "when enumerating contexts" do
370
- it {should respond_to(:contexts)}
371
- it {should respond_to(:has_context?)}
372
- it {should respond_to(:each_context)}
373
- it {should respond_to(:enum_context)}
374
-
375
- its(:contexts) {should be_an_enumerator}
376
- describe "#contexts" do
377
- subject {@enumerable.contexts}
368
+ context "when enumerating contexts" do
369
+ it {should respond_to(:contexts)}
370
+ it {should respond_to(:has_context?)}
371
+ it {should respond_to(:each_context)}
372
+ it {should respond_to(:enum_context)}
373
+
374
+ its(:contexts) {should be_an_enumerator}
375
+ describe "#contexts" do
376
+ subject { enumerable.contexts }
377
+ specify {expect(subject).to be_an_enumerator}
378
+ it "values should be resources" do
379
+ subject.each { |value| expect(value).to be_a_resource }
380
+ end
381
+ context ":unique => false" do
382
+ subject { enumerable.contexts(:unique => false) }
378
383
  specify {expect(subject).to be_an_enumerator}
379
384
  it "values should be resources" do
380
385
  subject.each { |value| expect(value).to be_a_resource }
381
386
  end
382
- context ":unique => false" do
383
- subject {@enumerable.contexts(:unique => false)}
384
- specify {expect(subject).to be_an_enumerator}
385
- it "values should be resources" do
386
- subject.each { |value| expect(value).to be_a_resource }
387
- end
388
- end
389
387
  end
388
+ end
390
389
 
391
- it "should implement #has_context?" do
392
- if @supports_context
393
- @statements.each do |statement|
394
- if statement.has_context?
395
- expect(@enumerable).to have_context(statement.context)
396
- end
390
+ it "should implement #has_context?" do
391
+ if @supports_context
392
+ @statements.each do |statement|
393
+ if statement.has_context?
394
+ expect(enumerable).to have_context(statement.context)
397
395
  end
398
- uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
399
- expect(@enumerable).not_to have_context(uri)
400
396
  end
397
+ uri = RDF::URI.new('http://example.org/does/not/have/this/uri')
398
+ expect(enumerable).not_to have_context(uri)
401
399
  end
400
+ end
402
401
 
403
- its(:each_context) {should be_an_enumerator}
404
- context "#each_context" do
405
- let(:contexts) {@statements.map { |s| s.context }.uniq.compact}
406
- it "has appropriate number of contexts" do
407
- if @supports_context
408
- expect(subject.each_context.to_a.size).to eq contexts.size
409
- end
410
- end
411
- it "values should be resources" do
412
- subject.each_context {|value| expect(value).to be_a_resource}
413
- end
414
- it "should have all contexts" do
415
- subject.each_context {|value| expect(contexts).to include(value)}
402
+ its(:each_context) {should be_an_enumerator}
403
+ context "#each_context" do
404
+ let(:contexts) {@statements.map { |s| s.context }.uniq.compact}
405
+ it "has appropriate number of contexts" do
406
+ if @supports_context
407
+ expect(subject.each_context.to_a.size).to eq contexts.size
416
408
  end
417
409
  end
410
+ it "values should be resources" do
411
+ subject.each_context {|value| expect(value).to be_a_resource}
412
+ end
413
+ it "should have all contexts" do
414
+ subject.each_context {|value| expect(contexts).to include(value)}
415
+ end
416
+ end
418
417
 
419
- its(:enum_context) {should be_an_enumerator}
420
- its(:enum_context) {should be_countable}
421
- context "#enum_context" do
422
- it "should enumerate all contexts" do
423
- expect(subject.enum_context.to_a).to include(*@enumerable.each_context.to_a)
424
- end
418
+ its(:enum_context) {should be_an_enumerator}
419
+ its(:enum_context) {should be_countable}
420
+ context "#enum_context" do
421
+ it "should enumerate all contexts" do
422
+ expect(subject.enum_context.to_a).to include(*enumerable.each_context.to_a)
425
423
  end
426
424
  end
425
+ end
427
426
 
428
- context "when enumerating graphs" do
429
- it {should respond_to(:each_graph)}
430
- it {should respond_to(:enum_graph)}
427
+ context "when enumerating graphs" do
428
+ it {should respond_to(:each_graph)}
429
+ it {should respond_to(:enum_graph)}
431
430
 
432
- describe "#each_graph" do
433
- subject {@enumerable.each_graph}
434
- it {should be_an_enumerator}
435
- it "are all graphs" do
436
- subject.each { |value| expect(value).to be_a_graph } if @supports_context
437
- end
431
+ describe "#each_graph" do
432
+ subject { enumerable.each_graph }
433
+ it {should be_an_enumerator}
434
+ it "are all graphs" do
435
+ subject.each { |value| expect(value).to be_a_graph } if @supports_context
438
436
  end
437
+ end
439
438
 
440
- describe "#enum_graph" do
441
- subject {@enumerable.enum_graph}
442
- it {should be_an_enumerator}
443
- it {should be_countable}
444
- it "enumerates the same as #each_graph" do
445
- expect(subject.to_a).to include(*@enumerable.each_graph.to_a) if @supports_context # expect with match problematic
446
- end
439
+ describe "#enum_graph" do
440
+ subject { enumerable.enum_graph }
441
+ it {should be_an_enumerator}
442
+ it {should be_countable}
443
+ it "enumerates the same as #each_graph" do
444
+ expect(subject.to_a).to include(*enumerable.each_graph.to_a) if @supports_context # expect with match problematic
447
445
  end
448
446
  end
447
+ end
449
448
 
450
- context "when converting" do
451
- it {should respond_to(:to_hash)}
452
- its(:to_hash) {should be_instance_of(Hash)}
453
- context "#to_hash" do
454
- it "should have as many keys as subjects" do
455
- expect(subject.to_hash.keys.size).to eq @enumerable.subjects.to_a.size
456
- end
449
+ context "when converting" do
450
+ it {should respond_to(:to_hash)}
451
+ its(:to_hash) {should be_instance_of(Hash)}
452
+ context "#to_hash" do
453
+ it "should have as many keys as subjects" do
454
+ expect(subject.to_hash.keys.size).to eq enumerable.subjects.to_a.size
457
455
  end
458
456
  end
459
-
460
- context "when dumping" do
461
- it {should respond_to(:dump)}
462
-
463
- it "should implement #dump" do
464
- expect(subject.dump(:ntriples)).to eq RDF::NTriples::Writer.buffer() {|w| w << @enumerable}
465
- end
466
-
467
- it "raises error on unknown format" do
468
- expect {subject.dump(:foobar)}.to raise_error(RDF::WriterError, /No writer found/)
457
+ end
458
+
459
+ context "when dumping" do
460
+ it {should respond_to(:dump)}
461
+
462
+ it "should implement #dump" do
463
+ expect(subject.dump(:ntriples)).to eq RDF::NTriples::Writer.buffer() {|w| w << enumerable}
464
+ end
465
+
466
+ it "raises error on unknown format" do
467
+ expect {subject.dump(:foobar)}.to raise_error(RDF::WriterError, /No writer found/)
468
+ end
469
+ end
470
+ end
471
+
472
+ ##
473
+ # @deprecated use `it_behaves_like "an RDF::Enumerable"` instead
474
+ module RDF_Enumerable
475
+ extend RSpec::SharedContext
476
+ include RDF::Spec::Matchers
477
+
478
+ def self.included(mod)
479
+ warn "[DEPRECATION] `RDF_Enumerable` is deprecated. "\
480
+ "Please use `it_behaves_like 'an RDF::Enumerable'`"
481
+ end
482
+
483
+ describe 'examples for' do
484
+ include_examples 'an RDF::Enumerable' do
485
+ let(:enumerable) { @enumerable }
486
+
487
+ before do
488
+ raise '@enumerable must be defined' unless defined?(enumerable)
469
489
  end
470
490
  end
471
491
  end