rdf-spec 1.1.5 → 1.1.13

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.
@@ -1,10 +1,23 @@
1
1
  require 'rdf/spec'
2
2
 
3
+ RSpec.shared_examples 'an RDF::Inferable' do
4
+ include RDF::Spec::Matchers
5
+
6
+ it "should implement specs" #TODO
7
+ end
8
+
9
+ ##
10
+ # @deprecated use `it_behaves_like "an RDF::Inferable"` instead
3
11
  module RDF_Inferable
4
12
  extend RSpec::SharedContext
5
13
  include RDF::Spec::Matchers
6
14
 
7
- describe RDF::Inferable do
8
- it "should implement specs" #TODO
15
+ def self.included(mod)
16
+ warn "[DEPRECATION] `RDF_Inferable` is deprecated. "\
17
+ "Please use `it_behaves_like 'an RDF::Inferable'`"
18
+ end
19
+
20
+ describe 'examples for' do
21
+ include_examples 'an RDF::Inferable'
9
22
  end
10
23
  end
@@ -0,0 +1,143 @@
1
+ ##
2
+ # Shared examples for RDF::Literals are broken up into multiple example sets.
3
+ #
4
+ # To use the core example sets that apply to most RDF::Literal implementations
5
+ # include the examples for `RDF::Literal`, `RDF::Literal validation`,
6
+ # `RDF::Literal canonicalization`, and `RDF::Literal lookup`.
7
+
8
+ shared_examples 'RDF::Literal' do |value, datatype_uri|
9
+ include_examples 'RDF::Literal with datatype and grammar', value, datatype_uri
10
+ include_examples 'RDF::Literal equality', value
11
+ include_examples 'RDF::Literal lexical values', value
12
+ end
13
+
14
+ shared_examples 'RDF::Literal with datatype and grammar' do |value, datatype_uri|
15
+ include_examples 'RDF::Literal with grammar'
16
+ include_examples 'RDF::Literal with datatype', value, datatype_uri
17
+ end
18
+
19
+ shared_examples 'RDF::Literal lexical values' do |value|
20
+ subject { described_class.new(value) }
21
+
22
+ describe '#humanize' do
23
+ it 'gives a string representation' do
24
+ expect(subject.humanize).to be_a String
25
+ end
26
+ end
27
+
28
+ describe '#to_s' do
29
+ it 'gives a string representation' do
30
+ expect(subject.to_s).to be_a String
31
+ end
32
+ end
33
+ end
34
+
35
+ shared_examples 'RDF::Literal with grammar' do
36
+ it 'has a GRAMMAR' do
37
+ expect(described_class::GRAMMAR).to respond_to :=~
38
+ end
39
+ end
40
+
41
+ shared_examples 'RDF::Literal equality' do |value, other|
42
+ subject { described_class.new(value) }
43
+
44
+ describe '#==' do
45
+ it { is_expected.to eq subject }
46
+ it { expect(subject.object).to eq (other || value) }
47
+ it { is_expected.not_to eq described_class.new('OTHER') }
48
+ it { is_expected.not_to eq nil }
49
+ end
50
+ end
51
+
52
+ shared_examples 'RDF::Literal with datatype' do |value, datatype_uri|
53
+ subject { described_class.new(value) }
54
+
55
+ it { is_expected.to be_literal }
56
+ it { is_expected.to be_typed }
57
+ it { is_expected.not_to be_plain }
58
+ it { is_expected.not_to be_anonymous }
59
+
60
+ it 'has a DATATYPE' do
61
+ expect(described_class::DATATYPE).to be_a RDF::URI
62
+ end
63
+
64
+ it 'has correct datatype' do
65
+ expect(subject.datatype).to eq datatype_uri
66
+ end
67
+ end
68
+
69
+ shared_examples 'RDF::Literal lookup' do |uri_hash|
70
+ uri_hash.each do |uri, klass|
71
+ it "finds #{klass} for #{uri}" do
72
+ expect(RDF::Literal("0", :datatype => uri).class).to eq klass
73
+ end
74
+ end
75
+ end
76
+
77
+ shared_examples 'RDF::Literal canonicalization' do |datatype, pairs|
78
+ pairs.each do |value, str|
79
+ klass = RDF::Literal.datatyped_class(datatype.to_s)
80
+
81
+ it "does not normalize '#{value}' by default" do
82
+ expect(RDF::Literal.new(value,
83
+ datatype: datatype ,
84
+ canonicalize: false).to_s)
85
+ .to eq value
86
+ end
87
+
88
+ it "normalizes double '#{value}' to '#{str}'" do
89
+ expect(RDF::Literal.new(value,
90
+ datatype: datatype,
91
+ canonicalize: true).to_s)
92
+ .to eq str
93
+ end
94
+
95
+ it "humanizes double '#{value}' to '#{str}'" do
96
+ expect(RDF::Literal.new(value,
97
+ datatype: datatype,
98
+ canonicalize: false).humanize)
99
+ .to eq value
100
+ end
101
+
102
+ it "instantiates '#{value}' as #{klass}" do
103
+ expect(RDF::Literal.new(value,
104
+ datatype: datatype,
105
+ canonicalize: true))
106
+ .to be_a(klass)
107
+ end
108
+
109
+ it "causes normalized '#{value}' to be == '#{str}'" do
110
+ expect(RDF::Literal.new(value,
111
+ datatype: datatype,
112
+ canonicalize: true))
113
+ .to eq RDF::Literal.new(str, datatype: datatype, canonicalize: false)
114
+ end
115
+ end
116
+ end
117
+
118
+ shared_examples 'RDF::Literal validation' do |datatype,
119
+ valid_values,
120
+ invalid_values|
121
+
122
+ klass = RDF::Literal.datatyped_class(datatype.to_s)
123
+
124
+ valid_values.each do |value|
125
+ it "validates #{klass} '#{value}'" do
126
+ expect(RDF::Literal.new(value, datatype: datatype)).to be_valid
127
+ end
128
+
129
+ it "does not invalidate #{klass} '#{value}'" do
130
+ expect(RDF::Literal.new(value, datatype: datatype)).not_to be_invalid
131
+ end
132
+ end
133
+
134
+ invalid_values.each do |value|
135
+ it "invalidates #{klass} '#{value}'" do
136
+ expect(RDF::Literal.new(value, datatype: datatype)).to be_invalid
137
+ end
138
+
139
+ it "does not validate #{klass} '#{value}'" do
140
+ expect(RDF::Literal.new(value, datatype: datatype)).not_to be_valid
141
+ end
142
+ end
143
+ end
@@ -1,39 +1,34 @@
1
1
  require 'rdf/spec'
2
2
  require 'rdf/ntriples'
3
3
 
4
- module RDF_Mutable
5
- extend RSpec::SharedContext
4
+ RSpec.shared_examples 'an RDF::Mutable' do
6
5
  include RDF::Spec::Matchers
7
6
 
8
- before :each do
9
- raise '+@mutable+ must be defined in a before(:each) block' unless instance_variable_get('@mutable')
7
+ before do
8
+ raise 'mutable must be defined with let(:mutable)' unless
9
+ defined? mutable
10
10
 
11
- @supports_context = @mutable.respond_to?(:supports?) && @mutable.supports?(:context)
11
+ @supports_context = mutable.respond_to?(:supports?) && mutable.supports?(:context)
12
12
  end
13
- let(:resource) {RDF::URI('http://rubygems.org/gems/rdf')}
14
- let(:context) {RDF::URI('http://example.org/context')}
13
+
14
+ let(:resource) { RDF::URI('http://rubygems.org/gems/rdf') }
15
+ let(:context) { RDF::URI('http://example.org/context') }
15
16
 
16
17
  describe RDF::Mutable do
17
- subject {@mutable}
18
+ subject { mutable }
18
19
 
19
20
  context "readability" do
20
21
  require 'rdf/spec/readable'
21
22
 
22
- before :each do
23
- @readable = @mutable
24
- end
25
-
26
- include RDF_Readable
23
+ let(:readable) { mutable }
24
+ it_behaves_like 'an RDF::Readable'
27
25
  end
28
26
 
29
27
  context "writability" do
30
28
  require 'rdf/spec/writable'
31
29
 
32
- before :each do
33
- @writable = @mutable
34
- end
35
-
36
- include RDF_Writable
30
+ let(:writable) { mutable }
31
+ it_behaves_like 'an RDF::Writable'
37
32
  end
38
33
 
39
34
  it {should be_empty}
@@ -80,7 +75,7 @@ module RDF_Mutable
80
75
  context "#from_{reader}" do
81
76
  it "should instantiate a reader" do
82
77
  reader = double("reader")
83
- expect(reader).to receive(:new).and_return(RDF::NTriples::Reader.new(""))
78
+ expect(reader).to receive(:new).and_return(RDF::Spec.quads.first)
84
79
  expect(RDF::Reader).to receive(:for).with(:a_reader).and_return(reader)
85
80
  subject.send(:from_a_reader)
86
81
  end
@@ -148,3 +143,25 @@ module RDF_Mutable
148
143
  end
149
144
  end
150
145
  end
146
+
147
+ ##
148
+ # @deprecated use `it_behaves_like "an RDF::Mutable"` instead
149
+ module RDF_Mutable
150
+ extend RSpec::SharedContext
151
+ include RDF::Spec::Matchers
152
+
153
+ def self.included(mod)
154
+ warn "[DEPRECATION] `RDF_Mutable` is deprecated. "\
155
+ "Please use `it_behaves_like 'an RDF::Mutable'`"
156
+ end
157
+
158
+ describe 'examples for' do
159
+ include_examples 'an RDF::Mutable' do
160
+ let(:mutable) { @mutable }
161
+
162
+ before do
163
+ raise '@mutable must be defined' unless defined?(mutable)
164
+ end
165
+ end
166
+ end
167
+ end
@@ -1,28 +1,28 @@
1
1
  require 'rdf/spec'
2
2
 
3
- module RDF_Queryable
4
- extend RSpec::SharedContext
3
+ RSpec.shared_examples 'an RDF::Queryable' do
5
4
  include RDF::Spec::Matchers
6
5
 
7
6
  before :each do
8
- raise '+@queryable+ must be defined in a before(:each) block' unless instance_variable_get('@queryable')
7
+ raise 'querable must be set with `let(:queryable)' unless
8
+ defined? queryable
9
9
 
10
10
  @doap = RDF::Spec::QUADS_FILE
11
11
  @statements = RDF::Spec.quads
12
12
 
13
- if @queryable.empty?
14
- if (@queryable.writable? rescue false)
15
- @queryable.insert(*@statements)
16
- elsif @queryable.respond_to?(:<<)
17
- @statements.each { |statement| @queryable << statement }
13
+ if queryable.empty?
14
+ if (queryable.writable? rescue false)
15
+ queryable.insert(*@statements)
16
+ elsif queryable.respond_to?(:<<)
17
+ @statements.each { |statement| queryable << statement }
18
18
  else
19
- raise "@queryable must respond to #<< or be pre-populated with the statements in #{@doap} in a before(:each) block"
19
+ raise "queryable must respond to #<< or be pre-populated with the statements in #{@doap} in a before(:each) block"
20
20
  end
21
21
  end
22
22
  end
23
23
 
24
24
  describe RDF::Queryable do
25
- subject {@queryable}
25
+ subject {queryable}
26
26
  let(:resource) {RDF::URI('http://rubygems.org/gems/rdf')}
27
27
  let(:literal) {RDF::Literal.new('J. Random Hacker')}
28
28
  let(:query) {RDF::Query.new {pattern [:s, :p, :o]}}
@@ -186,24 +186,37 @@ module RDF_Queryable
186
186
  # From data-r2/expr-equals
187
187
  context "data/r2/expr-equals" do
188
188
  context "graph-1" do
189
- subject {@queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Integer.new(1)).to_a}
190
- its(:count) {should == 2}
189
+ let(:result) do
190
+ queryable.query(:predicate => RDF::URI("http://example.org/p"),
191
+ :object => RDF::Literal::Integer.new(1)).to_a
192
+ end
191
193
 
192
- it "has two solutions" do
193
- expect(subject.any? {|s| s.subject == RDF::URI("http://example.org/xi1")}).to be_truthy
194
+ it 'has two solutions' do
195
+ expect(result.count).to eq 2
196
+ end
197
+
198
+ it "has xi1 as a solution" do
199
+ expect(result.any? {|s| s.subject == RDF::URI("http://example.org/xi1")}).to be_truthy
194
200
  end
195
201
 
196
202
  it "has xi2 as a solution" do
197
- expect(subject.any? {|s| s.subject == RDF::URI("http://example.org/xi2")}).to be_truthy
203
+ expect(result.any? {|s| s.subject == RDF::URI("http://example.org/xi2")}).to be_truthy
198
204
  end
199
205
  end
200
206
 
201
207
  context "graph-2" do
202
- subject {@queryable.query(:predicate => RDF::URI("http://example.org/p"), :object => RDF::Literal::Double.new("1.0e0")).to_a}
203
- its(:count) {should == 1}
208
+ let(:result) do
209
+ queryable.query(:predicate => RDF::URI("http://example.org/p"),
210
+ :object => RDF::Literal::Double.new("1.0e0"))
211
+ .to_a
212
+ end
213
+
214
+ it 'has one solution' do
215
+ expect(result.count).to eq 1
216
+ end
204
217
 
205
218
  it "has xd1 as a solution" do
206
- expect(subject.any? {|s| s.subject == RDF::URI("http://example.org/xd1")}).to be_truthy
219
+ expect(result.any? {|s| s.subject == RDF::URI("http://example.org/xd1")}).to be_truthy
207
220
  end
208
221
  end
209
222
  end
@@ -224,7 +237,7 @@ module RDF_Queryable
224
237
  end
225
238
 
226
239
  it "yields to the given block" do
227
- expect {|b| subject.send(:query_execute, query, &b)}.to yield_control.exactly(@queryable.count).times
240
+ expect {|b| subject.send(:query_execute, query, &b)}.to yield_control.exactly(queryable.count).times
228
241
  end
229
242
 
230
243
  it "yields solutions" do
@@ -248,7 +261,7 @@ module RDF_Queryable
248
261
  end
249
262
 
250
263
  it "yields to the given block" do
251
- expect {|b| subject.send(:query_pattern, RDF::Query::Pattern.new, &b)}.to yield_control.exactly(@queryable.count).times
264
+ expect {|b| subject.send(:query_pattern, RDF::Query::Pattern.new, &b)}.to yield_control.exactly(queryable.count).times
252
265
  end
253
266
 
254
267
  it "yields statements" do
@@ -256,7 +269,7 @@ module RDF_Queryable
256
269
  expect(statement).to be_a_statement
257
270
  end
258
271
  end
259
-
272
+
260
273
  context "with specific patterns" do
261
274
  # Note that "01" should not match 1, per data-r2/expr-equal/sameTerm
262
275
  {
@@ -317,7 +330,7 @@ module RDF_Queryable
317
330
  ##
318
331
  # @see RDF::Queryable#first
319
332
  describe "#first" do
320
- let(:failing_pattern) {[RDF::Node.new] * 3}
333
+ let(:failing_pattern) {[RDF::URI("http://no-such-resource"), RDF.type, RDF::Node.new]}
321
334
 
322
335
  it "should respond to #first" do
323
336
  expect(subject).to respond_to(:first)
@@ -328,7 +341,7 @@ module RDF_Queryable
328
341
  expect(subject.first).to eq subject.each.first # uses an Enumerator
329
342
  end
330
343
 
331
- it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
344
+ it "returns the correct value when the pattern matches" do
332
345
  matching_patterns = [[nil, nil, nil], subject.each.first]
333
346
  matching_patterns.each do |matching_pattern|
334
347
  expect(subject.first(matching_pattern)).to eq subject.query(matching_pattern).each.first
@@ -349,19 +362,19 @@ module RDF_Queryable
349
362
  ##
350
363
  # @see RDF::Queryable#first_subject
351
364
  describe "#first_subject" do
352
- let(:failing_pattern) {[RDF::Node.new, nil, nil]}
365
+ let(:failing_pattern) {[RDF::URI("http://no-such-resource"), nil, nil]}
353
366
 
354
367
  it "should respond to #first_subject" do
355
368
  expect(subject).to respond_to(:first_subject)
356
369
  end
357
370
 
358
- it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
371
+ it "returns enumerator without a pattern" do
359
372
  expect { subject.first_subject }.not_to raise_error
360
373
  expect(subject.first_subject).to eq subject.first.subject
361
374
  end
362
375
 
363
- it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
364
- matching_patterns = [[nil, nil, nil], [subject.first.subject, nil, nil]]
376
+ it "returns the correct value when the pattern matches" do
377
+ matching_patterns = [[nil, nil, nil], [RDF::URI("http://rubygems.org/gems/rdf"), nil, nil]]
365
378
  matching_patterns.each do |matching_pattern|
366
379
  expect(subject.first_subject(matching_pattern)).to eq subject.query(matching_pattern).first.subject
367
380
  end
@@ -382,16 +395,16 @@ module RDF_Queryable
382
395
  # @see RDF::Queryable#first_predicate
383
396
 
384
397
  describe "#first_predicate" do
385
- let(:failing_pattern) {[nil, RDF::Node.new, nil]}
398
+ let(:failing_pattern) {[nil, RDF::URI("http://no-such-resource"), nil]}
386
399
 
387
400
  it {should respond_to(:first_predicate)}
388
401
 
389
- it "returns enumerator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
402
+ it "returns enumerator without a pattern" do
390
403
  expect { subject.first_predicate }.not_to raise_error
391
404
  expect(subject.first_predicate).to eq subject.first.predicate
392
405
  end
393
406
 
394
- it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
407
+ it "returns the correct value when the pattern matches" do
395
408
  matching_patterns = [[nil, nil, nil], [nil, subject.first.predicate, nil]]
396
409
  matching_patterns.each do |matching_pattern|
397
410
  expect(subject.first_predicate(matching_pattern)).to eq subject.query(matching_pattern).first.predicate
@@ -413,15 +426,15 @@ module RDF_Queryable
413
426
  # @see RDF::Queryable#first_object
414
427
 
415
428
  describe "#first_object" do
416
- let(:failing_pattern) {[nil, nil, RDF::Node.new]}
429
+ let(:failing_pattern) {[nil, nil, RDF::URI("http://no-such-resource")]}
417
430
  it {should respond_to(:first_object)}
418
431
 
419
- it "returns enurator without a pattern", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
432
+ it "returns enurator without a pattern" do
420
433
  expect { subject.first_object }.not_to raise_error
421
434
  expect(subject.first_object).to eq subject.first.object
422
435
  end
423
436
 
424
- it "returns the correct value when the pattern matches", :pending => (defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java') do
437
+ it "returns the correct value when the pattern matches" do
425
438
  matching_patterns = [[nil, nil, nil], [nil, nil, subject.first.object]]
426
439
  matching_patterns.each do |matching_pattern|
427
440
  expect(subject.first_object(matching_pattern)).to eq subject.query(matching_pattern).first.object
@@ -514,3 +527,25 @@ module RDF_Queryable
514
527
  end
515
528
  end
516
529
  end
530
+
531
+ ##
532
+ # @deprecated use `it_behaves_like "an RDF::Queryable"` instead
533
+ module RDF_Queryable
534
+ extend RSpec::SharedContext
535
+ include RDF::Spec::Matchers
536
+
537
+ def self.included(mod)
538
+ warn "[DEPRECATION] `RDF_Queryable` is deprecated. "\
539
+ "Please use `it_behaves_like 'an RDF::Queryable'`"
540
+ end
541
+
542
+ describe 'examples for' do
543
+ include_examples 'an RDF::Queryable' do
544
+ let(:queryable) { @queryable }
545
+
546
+ before do
547
+ raise '@queryable must be defined' unless defined?(queryable)
548
+ end
549
+ end
550
+ end
551
+ end