rdf-spec 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rdf/spec.rb +2 -2
- data/lib/rdf/spec/countable.rb +3 -2
- data/lib/rdf/spec/durable.rb +20 -18
- data/lib/rdf/spec/enumerable.rb +337 -314
- data/lib/rdf/spec/format.rb +31 -28
- data/lib/rdf/spec/indexable.rb +19 -16
- data/lib/rdf/spec/inferable.rb +5 -2
- data/lib/rdf/spec/matchers.rb +6 -6
- data/lib/rdf/spec/mutable.rb +110 -107
- data/lib/rdf/spec/queryable.rb +331 -330
- data/lib/rdf/spec/readable.rb +10 -7
- data/lib/rdf/spec/reader.rb +119 -116
- data/lib/rdf/spec/repository.rb +39 -36
- data/lib/rdf/spec/transaction.rb +44 -40
- data/lib/rdf/spec/writable.rb +86 -57
- data/lib/rdf/spec/writer.rb +126 -123
- metadata +4 -6
- data/lib/rdf/spec/query.rb +0 -7
- data/lib/rdf/spec/vocab.rb +0 -7
data/lib/rdf/spec/format.rb
CHANGED
@@ -1,49 +1,52 @@
|
|
1
1
|
require 'rdf/spec'
|
2
2
|
|
3
|
-
|
3
|
+
module RDF_Format
|
4
|
+
extend RSpec::SharedContext
|
4
5
|
include RDF::Spec::Matchers
|
5
6
|
|
6
7
|
before(:each) do
|
7
8
|
raise raise '+@format_class+ must be defined in a before(:each) block' unless instance_variable_get('@format_class')
|
8
9
|
end
|
9
10
|
|
10
|
-
describe
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
describe RDF::Format do
|
12
|
+
describe ".for" do
|
13
|
+
RDF::Format.file_extensions.each do |ext, formats|
|
14
|
+
it "detects #{formats.first} using file path foo.#{ext}" do
|
15
|
+
RDF::Format.for("foo.#{ext}").should == formats.first
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
it "detects #{formats.first} using file_name foo.#{ext}" do
|
19
|
+
RDF::Format.for(:file_name => "foo.#{ext}").should == formats.first
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
it "detects #{formats.first} using file_extension #{ext}" do
|
23
|
+
RDF::Format.for(:file_extension => ext).should == formats.first
|
24
|
+
end
|
22
25
|
end
|
23
|
-
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
RDF::Format.content_types.each do |content_type, formats|
|
28
|
+
it "detects #{formats.first} using content_type #{content_type}" do
|
29
|
+
RDF::Format.for(:content_type => content_type).should == formats.first
|
30
|
+
end
|
28
31
|
end
|
29
32
|
end
|
30
|
-
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
describe ".reader" do
|
35
|
+
it "returns a reader" do
|
36
|
+
@format_class.each do |f|
|
37
|
+
f.reader.should_not be_nil
|
38
|
+
end
|
36
39
|
end
|
37
40
|
end
|
38
|
-
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
describe ".writer" do
|
43
|
+
##
|
44
|
+
# May not return a writer, only does if one is defined by the format
|
45
|
+
it "returns a writer" do
|
46
|
+
@format_class.each do |f|
|
47
|
+
format_namespace = f.name.split('::')[0..-2].inject(Kernel) {|base, const| base.const_get(const)}
|
48
|
+
f.writer.should_not be_nil if format_namespace.const_defined?(:Writer)
|
49
|
+
end
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
data/lib/rdf/spec/indexable.rb
CHANGED
@@ -1,29 +1,32 @@
|
|
1
1
|
require 'rdf/spec'
|
2
2
|
|
3
|
-
|
3
|
+
module RDF_Indexable
|
4
|
+
extend RSpec::SharedContext
|
4
5
|
include RDF::Spec::Matchers
|
5
6
|
|
6
7
|
before :each do
|
7
8
|
raise '+@indexable+ must be defined in a before(:each) block' unless instance_variable_get('@indexable')
|
8
9
|
end
|
10
|
+
|
11
|
+
describe RDF::Indexable do
|
12
|
+
it "responds to #indexed?" do
|
13
|
+
@indexable.respond_to?(:indexed?)
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
it "implements #indexed?" do
|
15
|
-
!!@indexable.indexed?.should == @indexable.indexed?
|
16
|
-
end
|
16
|
+
it "implements #indexed?" do
|
17
|
+
!!@indexable.indexed?.should == @indexable.indexed?
|
18
|
+
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
it "responds to #index!" do
|
21
|
+
@indexable.respond_to?(:index!)
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
it "does not raise error on #index! if #indexed?" do
|
25
|
+
lambda {@indexable.index!}.should_not raise_error if @indexable.indexed?
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
+
it "raises error on #index! if not #indexed?" do
|
29
|
+
lambda {@indexable.index!}.should raise_error unless @indexable.indexed?
|
30
|
+
end
|
28
31
|
end
|
29
32
|
end
|
data/lib/rdf/spec/inferable.rb
CHANGED
data/lib/rdf/spec/matchers.rb
CHANGED
@@ -46,7 +46,7 @@ module RDF; module Spec
|
|
46
46
|
statement.should be_instance_of(RDF::Statement)
|
47
47
|
statement.subject.should be_a_kind_of(RDF::Resource)
|
48
48
|
statement.predicate.should be_a_kind_of(RDF::URI)
|
49
|
-
statement.object.should be_a_kind_of(RDF::Value)
|
49
|
+
statement.object.should be_a_kind_of(RDF::Value)
|
50
50
|
true
|
51
51
|
end
|
52
52
|
end
|
@@ -57,7 +57,7 @@ module RDF; module Spec
|
|
57
57
|
triple.size.should == 3
|
58
58
|
triple[0].should be_a_kind_of(RDF::Resource)
|
59
59
|
triple[1].should be_a_kind_of(RDF::URI)
|
60
|
-
triple[2].should be_a_kind_of(RDF::Value)
|
60
|
+
triple[2].should be_a_kind_of(RDF::Value)
|
61
61
|
true
|
62
62
|
end
|
63
63
|
end
|
@@ -68,7 +68,7 @@ module RDF; module Spec
|
|
68
68
|
quad.size.should == 4
|
69
69
|
quad[0].should be_a_kind_of(RDF::Resource)
|
70
70
|
quad[1].should be_a_kind_of(RDF::URI)
|
71
|
-
quad[2].should be_a_kind_of(RDF::Value)
|
71
|
+
quad[2].should be_a_kind_of(RDF::Value)
|
72
72
|
quad[3].should be_a_kind_of(RDF::Resource) unless quad[3].nil?
|
73
73
|
true
|
74
74
|
end
|
@@ -97,7 +97,7 @@ module RDF; module Spec
|
|
97
97
|
|
98
98
|
RSpec::Matchers.define :be_a_value do
|
99
99
|
match do |value|
|
100
|
-
value.should be_a_kind_of(RDF::Value)
|
100
|
+
value.should be_a_kind_of(RDF::Value)
|
101
101
|
true
|
102
102
|
end
|
103
103
|
end
|
@@ -124,7 +124,7 @@ module RDF; module Spec
|
|
124
124
|
properties.map { |p| p.to_sym }.each do |property|
|
125
125
|
vocabulary[property].should be_a_uri
|
126
126
|
vocabulary[property].to_s.should == "#{base_uri}#{property}"
|
127
|
-
|
127
|
+
vocabulary.should respond_to(property)
|
128
128
|
lambda { vocabulary.send(property) }.should_not raise_error
|
129
129
|
vocabulary.send(property).should be_a_uri
|
130
130
|
vocabulary.send(property.to_s).should be_a_uri
|
@@ -137,7 +137,7 @@ module RDF; module Spec
|
|
137
137
|
RSpec::Matchers.define :have_subclasses do |base_uri, klasses|
|
138
138
|
match do |vocabulary|
|
139
139
|
klasses.map { |k| k.to_sym }.each do |klass|
|
140
|
-
#
|
140
|
+
pending "checks that #{base_uri} has subClassOf for #{klass}"
|
141
141
|
end
|
142
142
|
true
|
143
143
|
end
|
data/lib/rdf/spec/mutable.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'rdf/spec'
|
2
2
|
require 'rdf/ntriples'
|
3
3
|
|
4
|
-
|
4
|
+
module RDF_Mutable
|
5
|
+
extend RSpec::SharedContext
|
5
6
|
include RDF::Spec::Matchers
|
6
7
|
|
7
8
|
before :each do
|
@@ -15,139 +16,141 @@ share_as :RDF_Mutable do
|
|
15
16
|
@supports_context = @mutable.respond_to?(:supports?) && @mutable.supports?(:context)
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
describe RDF::Mutable do
|
20
|
+
context "readability" do
|
21
|
+
require 'rdf/spec/readable'
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
it_should_behave_like RDF_Readable
|
26
|
-
end
|
27
|
-
|
28
|
-
context "writability" do
|
29
|
-
require 'rdf/spec/writable'
|
23
|
+
before :each do
|
24
|
+
@readable = @mutable
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
@writable = @mutable
|
27
|
+
include RDF_Readable
|
33
28
|
end
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
it "should be empty initially" do
|
39
|
-
@mutable.empty?.should be_true
|
40
|
-
@mutable.count.should be_zero
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should be readable" do
|
44
|
-
@mutable.readable?.should be_true
|
45
|
-
end
|
30
|
+
context "writability" do
|
31
|
+
require 'rdf/spec/writable'
|
46
32
|
|
47
|
-
|
48
|
-
|
49
|
-
|
33
|
+
before :each do
|
34
|
+
@writable = @mutable
|
35
|
+
end
|
50
36
|
|
51
|
-
|
52
|
-
|
53
|
-
@mutable.mutable?.should be_true
|
54
|
-
end
|
37
|
+
include RDF_Writable
|
38
|
+
end
|
55
39
|
|
56
|
-
|
57
|
-
|
58
|
-
|
40
|
+
it "should be empty initially" do
|
41
|
+
@mutable.empty?.should be_true
|
42
|
+
@mutable.count.should be_zero
|
43
|
+
end
|
59
44
|
|
60
|
-
|
61
|
-
|
62
|
-
lambda { @mutable.load }.should raise_error(ArgumentError)
|
45
|
+
it "should be readable" do
|
46
|
+
@mutable.readable?.should be_true
|
63
47
|
end
|
64
48
|
|
65
|
-
it "should
|
66
|
-
|
49
|
+
it "should be writable" do
|
50
|
+
@mutable.writable?.should be_true
|
67
51
|
end
|
68
52
|
|
69
|
-
it "should
|
70
|
-
|
53
|
+
it "should be mutable" do
|
54
|
+
@mutable.immutable?.should be_false
|
55
|
+
@mutable.mutable?.should be_true
|
71
56
|
end
|
72
57
|
|
73
|
-
it "should load
|
74
|
-
@mutable.load
|
75
|
-
@mutable.size.should == File.readlines(@filename).size
|
76
|
-
@mutable.should have_subject(@subject)
|
58
|
+
it "should support #load" do
|
59
|
+
@mutable.respond_to?(:load).should be_true
|
77
60
|
end
|
78
61
|
|
79
|
-
|
80
|
-
|
81
|
-
@mutable.load
|
82
|
-
@mutable.should have_context(@context)
|
83
|
-
@mutable.query(:context => @context).size.should == @mutable.size
|
62
|
+
context "#load" do
|
63
|
+
it "should require an argument" do
|
64
|
+
lambda { @mutable.load }.should raise_error(ArgumentError)
|
84
65
|
end
|
85
|
-
end
|
86
|
-
end
|
87
66
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
@mutable.insert(*@statements)
|
92
|
-
end
|
67
|
+
it "should accept a string filename argument" do
|
68
|
+
lambda { @mutable.load(@filename) }.should_not raise_error(ArgumentError)
|
69
|
+
end
|
93
70
|
|
94
|
-
|
95
|
-
|
96
|
-
|
71
|
+
it "should accept an optional hash argument" do
|
72
|
+
lambda { @mutable.load(@filename,{}) }.should_not raise_error(ArgumentError)
|
73
|
+
end
|
97
74
|
|
98
|
-
|
99
|
-
|
100
|
-
|
75
|
+
it "should load statements" do
|
76
|
+
@mutable.load @filename
|
77
|
+
@mutable.size.should == File.readlines(@filename).size
|
78
|
+
@mutable.should have_subject(@subject)
|
79
|
+
end
|
101
80
|
|
102
|
-
|
103
|
-
|
104
|
-
|
81
|
+
it "should load statements with a context override" do
|
82
|
+
if @supports_context
|
83
|
+
@mutable.load @filename, :context => @context
|
84
|
+
@mutable.should have_context(@context)
|
85
|
+
@mutable.query(:context => @context).size.should == @mutable.size
|
86
|
+
end
|
87
|
+
end
|
105
88
|
end
|
106
89
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
90
|
+
context "when deleting statements" do
|
91
|
+
before :each do
|
92
|
+
@statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
|
93
|
+
@mutable.insert(*@statements)
|
94
|
+
end
|
111
95
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
96
|
+
it "should support #delete" do
|
97
|
+
@mutable.should respond_to(:delete)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not raise errors" do
|
101
|
+
lambda { @mutable.delete(@statements.first) }.should_not raise_error
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should support deleting one statement at a time" do
|
105
|
+
@mutable.delete(@statements.first)
|
106
|
+
@mutable.should_not have_statement(@statements.first)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should support deleting multiple statements at a time" do
|
110
|
+
@mutable.delete(*@statements)
|
111
|
+
@statements.find { |s| @mutable.has_statement?(s) }.should be_false
|
112
|
+
end
|
124
113
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
114
|
+
it "should support wildcard deletions" do
|
115
|
+
# nothing deleted
|
116
|
+
require 'digest/sha1'
|
117
|
+
count = @mutable.count
|
118
|
+
@mutable.delete([nil, nil, random = Digest::SHA1.hexdigest(File.read(__FILE__))])
|
119
|
+
@mutable.should_not be_empty
|
120
|
+
@mutable.count.should == count
|
121
|
+
|
122
|
+
# everything deleted
|
123
|
+
@mutable.delete([nil, nil, nil])
|
124
|
+
@mutable.should be_empty
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should only delete statements when the context matches" do
|
128
|
+
# Setup three statements identical except for context
|
129
|
+
count = @mutable.count + (@supports_context ? 3 : 1)
|
130
|
+
s1 = RDF::Statement.new(@subject, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:1"))
|
131
|
+
s2 = s1.dup
|
132
|
+
s2.context = RDF::URI.new("urn:context:1")
|
133
|
+
s3 = s1.dup
|
134
|
+
s3.context = RDF::URI.new("urn:context:2")
|
135
|
+
@mutable.insert(s1)
|
136
|
+
@mutable.insert(s2)
|
137
|
+
@mutable.insert(s3)
|
138
|
+
@mutable.count.should == count
|
139
|
+
|
140
|
+
# Delete one by one
|
141
|
+
@mutable.delete(s1)
|
142
|
+
@mutable.count.should == count - (@supports_context ? 1 : 1)
|
143
|
+
@mutable.delete(s2)
|
144
|
+
@mutable.count.should == count - (@supports_context ? 2 : 1)
|
145
|
+
@mutable.delete(s3)
|
146
|
+
@mutable.count.should == count - (@supports_context ? 3 : 1)
|
147
|
+
end
|
145
148
|
end
|
146
|
-
end
|
147
149
|
|
148
|
-
|
149
|
-
|
150
|
-
|
150
|
+
context "when clearing all statements" do
|
151
|
+
it "should support #clear" do
|
152
|
+
@mutable.should respond_to(:clear)
|
153
|
+
end
|
151
154
|
end
|
152
155
|
end
|
153
156
|
end
|