rdf-spec 1.0.9 → 1.1.0.p1
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.
- checksums.yaml +14 -6
- data/AUTHORS +1 -1
- data/README +16 -23
- data/VERSION +1 -1
- data/etc/bendiken.nq +8 -8
- data/etc/bendiken.nt +8 -0
- data/etc/bendiken.ttl +17 -0
- data/etc/bhuga.nq +6 -6
- data/etc/bhuga.nt +6 -0
- data/etc/bhuga.ttl +15 -0
- data/etc/{triples.nt → doap.nq} +73 -76
- data/etc/doap.nt +39 -39
- data/etc/doap.ttl +79 -0
- data/etc/gkellogg.nq +5 -6
- data/etc/gkellogg.nt +5 -0
- data/etc/gkellogg.ttl +14 -0
- data/etc/test-data.nt +1 -0
- data/lib/rdf/spec.rb +0 -20
- data/lib/rdf/spec/countable.rb +26 -21
- data/lib/rdf/spec/durable.rb +13 -9
- data/lib/rdf/spec/enumerable.rb +314 -264
- data/lib/rdf/spec/format.rb +8 -9
- data/lib/rdf/spec/indexable.rb +13 -6
- data/lib/rdf/spec/matchers.rb +38 -38
- data/lib/rdf/spec/mutable.rb +81 -84
- data/lib/rdf/spec/queryable.rb +168 -195
- data/lib/rdf/spec/readable.rb +7 -3
- data/lib/rdf/spec/reader.rb +43 -43
- data/lib/rdf/spec/repository.rb +26 -15
- data/lib/rdf/spec/transaction.rb +90 -42
- data/lib/rdf/spec/writable.rb +55 -68
- data/lib/rdf/spec/writer.rb +36 -35
- data/spec/version_spec.rb +1 -1
- metadata +41 -34
- data/etc/quads.nq +0 -95
data/lib/rdf/spec/format.rb
CHANGED
@@ -9,33 +9,32 @@ module RDF_Format
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe RDF::Format do
|
12
|
-
subject {@format_class}
|
13
12
|
describe ".for" do
|
14
13
|
RDF::Format.file_extensions.each do |ext, formats|
|
15
14
|
it "detects #{formats.first} using file path foo.#{ext}" do
|
16
|
-
|
15
|
+
RDF::Format.for("foo.#{ext}").should == formats.first
|
17
16
|
end
|
18
17
|
|
19
18
|
it "detects #{formats.first} using file_name foo.#{ext}" do
|
20
|
-
|
19
|
+
RDF::Format.for(:file_name => "foo.#{ext}").should == formats.first
|
21
20
|
end
|
22
21
|
|
23
22
|
it "detects #{formats.first} using file_extension #{ext}" do
|
24
|
-
|
23
|
+
RDF::Format.for(:file_extension => ext).should == formats.first
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
27
|
RDF::Format.content_types.each do |content_type, formats|
|
29
28
|
it "detects #{formats.first} using content_type #{content_type}" do
|
30
|
-
|
29
|
+
RDF::Format.for(:content_type => content_type).should == formats.first
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
34
|
describe ".reader" do
|
36
35
|
it "returns a reader" do
|
37
|
-
|
38
|
-
|
36
|
+
@format_class.each do |f|
|
37
|
+
f.reader.should_not be_nil
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
@@ -44,9 +43,9 @@ module RDF_Format
|
|
44
43
|
##
|
45
44
|
# May not return a writer, only does if one is defined by the format
|
46
45
|
it "returns a writer" do
|
47
|
-
|
46
|
+
@format_class.each do |f|
|
48
47
|
format_namespace = f.name.split('::')[0..-2].inject(Kernel) {|base, const| base.const_get(const)}
|
49
|
-
|
48
|
+
f.writer.should_not be_nil if format_namespace.const_defined?(:Writer)
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
data/lib/rdf/spec/indexable.rb
CHANGED
@@ -9,17 +9,24 @@ module RDF_Indexable
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe RDF::Indexable do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
it "responds to #indexed?" do
|
13
|
+
@indexable.respond_to?(:indexed?)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "implements #indexed?" do
|
17
|
+
!!@indexable.indexed?.should == @indexable.indexed?
|
18
|
+
end
|
19
|
+
|
20
|
+
it "responds to #index!" do
|
21
|
+
@indexable.respond_to?(:index!)
|
22
|
+
end
|
16
23
|
|
17
24
|
it "does not raise error on #index! if #indexed?" do
|
18
|
-
|
25
|
+
lambda {@indexable.index!}.should_not raise_error if @indexable.indexed?
|
19
26
|
end
|
20
27
|
|
21
28
|
it "raises error on #index! if not #indexed?" do
|
22
|
-
|
29
|
+
lambda {@indexable.index!}.should raise_error unless @indexable.indexed?
|
23
30
|
end
|
24
31
|
end
|
25
32
|
end
|
data/lib/rdf/spec/matchers.rb
CHANGED
@@ -8,113 +8,113 @@ module RDF; module Spec
|
|
8
8
|
module Matchers
|
9
9
|
RSpec::Matchers.define :be_countable do
|
10
10
|
match do |countable|
|
11
|
-
|
11
|
+
countable.should be_a_kind_of(RDF::Countable)
|
12
12
|
true
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
RSpec::Matchers.define :be_enumerable do
|
17
17
|
match do |enumerable|
|
18
|
-
|
18
|
+
enumerable.should be_a_kind_of(RDF::Enumerable)
|
19
19
|
true
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
RSpec::Matchers.define :be_an_enumerator do
|
24
24
|
match do |enumerator|
|
25
|
-
|
25
|
+
enumerator.should be_a_kind_of(Enumerator)
|
26
26
|
true
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
RSpec::Matchers.define :be_queryable do
|
31
31
|
match do |enumerable|
|
32
|
-
|
32
|
+
enumerable.should be_a_kind_of(RDF::Queryable)
|
33
33
|
true
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
RSpec::Matchers.define :be_mutable do
|
38
38
|
match do |enumerable|
|
39
|
-
|
39
|
+
enumerable.should be_a_kind_of(RDF::Mutable)
|
40
40
|
true
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
RSpec::Matchers.define :be_a_statement do
|
45
45
|
match do |statement|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
statement.should be_instance_of(RDF::Statement)
|
47
|
+
statement.subject.should be_a_kind_of(RDF::Resource)
|
48
|
+
statement.predicate.should be_a_kind_of(RDF::URI)
|
49
|
+
statement.object.should be_a_kind_of(RDF::Value)
|
50
50
|
true
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
RSpec::Matchers.define :be_a_triple do
|
55
55
|
match do |triple|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
triple.should be_instance_of(Array)
|
57
|
+
triple.size.should == 3
|
58
|
+
triple[0].should be_a_kind_of(RDF::Resource)
|
59
|
+
triple[1].should be_a_kind_of(RDF::URI)
|
60
|
+
triple[2].should be_a_kind_of(RDF::Value)
|
61
61
|
true
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
RSpec::Matchers.define :be_a_quad do
|
66
66
|
match do |quad|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
quad.should be_instance_of(Array)
|
68
|
+
quad.size.should == 4
|
69
|
+
quad[0].should be_a_kind_of(RDF::Resource)
|
70
|
+
quad[1].should be_a_kind_of(RDF::URI)
|
71
|
+
quad[2].should be_a_kind_of(RDF::Value)
|
72
|
+
quad[3].should be_a_kind_of(RDF::Resource) unless quad[3].nil?
|
73
73
|
true
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
RSpec::Matchers.define :be_a_resource do
|
78
78
|
match do |value|
|
79
|
-
|
79
|
+
value.should be_a_kind_of(RDF::Resource)
|
80
80
|
true
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
RSpec::Matchers.define :be_a_node do
|
85
85
|
match do |value|
|
86
|
-
|
86
|
+
value.should be_a_kind_of(RDF::Node)
|
87
87
|
true
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
RSpec::Matchers.define :be_a_uri do
|
92
92
|
match do |value|
|
93
|
-
|
93
|
+
value.should be_a_kind_of(RDF::URI)
|
94
94
|
true
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
RSpec::Matchers.define :be_a_value do
|
99
99
|
match do |value|
|
100
|
-
|
100
|
+
value.should be_a_kind_of(RDF::Value)
|
101
101
|
true
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
RSpec::Matchers.define :be_a_list do
|
106
106
|
match do |value|
|
107
|
-
|
107
|
+
value.should be_an(RDF::List)
|
108
108
|
true
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
RSpec::Matchers.define :be_a_vocabulary do |base_uri|
|
113
113
|
match do |vocabulary|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
vocabulary.should be_a_kind_of(Module)
|
115
|
+
vocabulary.should respond_to(:to_uri)
|
116
|
+
vocabulary.to_uri.to_s.should == base_uri
|
117
|
+
vocabulary.should respond_to(:[])
|
118
118
|
true
|
119
119
|
end
|
120
120
|
end
|
@@ -122,13 +122,13 @@ module RDF; module Spec
|
|
122
122
|
RSpec::Matchers.define :have_properties do |base_uri, properties|
|
123
123
|
match do |vocabulary|
|
124
124
|
properties.map { |p| p.to_sym }.each do |property|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
125
|
+
vocabulary[property].should be_a_uri
|
126
|
+
vocabulary[property].to_s.should == "#{base_uri}#{property}"
|
127
|
+
vocabulary.should respond_to(property)
|
128
|
+
lambda { vocabulary.send(property) }.should_not raise_error
|
129
|
+
vocabulary.send(property).should be_a_uri
|
130
|
+
vocabulary.send(property.to_s).should be_a_uri
|
131
|
+
vocabulary.send(property).to_s.should == "#{base_uri}#{property}"
|
132
132
|
end
|
133
133
|
true
|
134
134
|
end
|
@@ -145,14 +145,14 @@ module RDF; module Spec
|
|
145
145
|
|
146
146
|
RSpec::Matchers.define :be_a_repository do
|
147
147
|
match do |repository|
|
148
|
-
|
148
|
+
repository.should be_a_kind_of(RDF::Repository)
|
149
149
|
true
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
RSpec::Matchers.define :be_a_repository_of_size do |size|
|
154
154
|
match do |repository|
|
155
|
-
|
155
|
+
repository.should be_a_repository
|
156
156
|
repository.size == size
|
157
157
|
end
|
158
158
|
end
|
data/lib/rdf/spec/mutable.rb
CHANGED
@@ -8,14 +8,15 @@ module RDF_Mutable
|
|
8
8
|
before :each do
|
9
9
|
raise '+@mutable+ must be defined in a before(:each) block' unless instance_variable_get('@mutable')
|
10
10
|
|
11
|
+
@filename = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'etc', 'doap.nt'))
|
12
|
+
|
13
|
+
@subject = RDF::URI('http://rubygems.org/gems/rdf')
|
14
|
+
@context = RDF::URI('http://example.org/context')
|
15
|
+
|
11
16
|
@supports_context = @mutable.respond_to?(:supports?) && @mutable.supports?(:context)
|
12
17
|
end
|
13
|
-
let(:resource) {RDF::URI('http://rubygems.org/gems/rdf')}
|
14
|
-
let(:context) {RDF::URI('http://example.org/context')}
|
15
18
|
|
16
19
|
describe RDF::Mutable do
|
17
|
-
subject {@mutable}
|
18
|
-
|
19
20
|
context "readability" do
|
20
21
|
require 'rdf/spec/readable'
|
21
22
|
|
@@ -36,123 +37,119 @@ module RDF_Mutable
|
|
36
37
|
include RDF_Writable
|
37
38
|
end
|
38
39
|
|
39
|
-
it
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
it
|
45
|
-
|
46
|
-
|
40
|
+
it "should be empty initially" do
|
41
|
+
@mutable.empty?.should be_true
|
42
|
+
@mutable.count.should be_zero
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be readable" do
|
46
|
+
@mutable.readable?.should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should be writable" do
|
50
|
+
@mutable.writable?.should be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be mutable" do
|
54
|
+
@mutable.immutable?.should be_false
|
55
|
+
@mutable.mutable?.should be_true
|
56
|
+
end
|
47
57
|
|
48
|
-
|
58
|
+
it "should support #load" do
|
59
|
+
@mutable.respond_to?(:load).should be_true
|
60
|
+
end
|
49
61
|
|
50
62
|
context "#load" do
|
51
63
|
it "should require an argument" do
|
52
|
-
|
64
|
+
lambda { @mutable.load }.should raise_error(ArgumentError)
|
53
65
|
end
|
54
66
|
|
55
67
|
it "should accept a string filename argument" do
|
56
|
-
|
57
|
-
expect { subject.load(RDF::Spec::TRIPLES_FILE) }.not_to raise_error
|
58
|
-
end
|
68
|
+
lambda { @mutable.load(@filename) }.should_not raise_error(ArgumentError)
|
59
69
|
end
|
60
70
|
|
61
71
|
it "should accept an optional hash argument" do
|
62
|
-
|
63
|
-
expect { subject.load(RDF::Spec::TRIPLES_FILE, {}) }.not_to raise_error
|
64
|
-
end
|
72
|
+
lambda { @mutable.load(@filename,{}) }.should_not raise_error(ArgumentError)
|
65
73
|
end
|
66
74
|
|
67
75
|
it "should load statements" do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
expect(subject).to have_subject(resource)
|
72
|
-
end
|
76
|
+
@mutable.load @filename
|
77
|
+
@mutable.size.should == File.readlines(@filename).size
|
78
|
+
@mutable.should have_subject(@subject)
|
73
79
|
end
|
74
80
|
|
75
81
|
it "should load statements with a context override" do
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
80
86
|
end
|
81
87
|
end
|
82
88
|
end
|
83
89
|
|
84
|
-
context "#from_{reader}" do
|
85
|
-
it "should instantiate a reader" do
|
86
|
-
reader = double("reader")
|
87
|
-
expect(reader).to receive(:new).and_return(RDF::NTriples::Reader.new(""))
|
88
|
-
expect(RDF::Reader).to receive(:for).with(:a_reader).and_return(reader)
|
89
|
-
subject.send(:from_a_reader)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
90
|
context "when deleting statements" do
|
94
91
|
before :each do
|
95
|
-
@statements = RDF::NTriples::Reader.new(File.open(
|
96
|
-
|
92
|
+
@statements = RDF::NTriples::Reader.new(File.open(@filename)).to_a
|
93
|
+
@mutable.insert(*@statements)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should support #delete" do
|
97
|
+
@mutable.should respond_to(:delete)
|
97
98
|
end
|
98
99
|
|
99
100
|
it "should not raise errors" do
|
100
|
-
|
101
|
-
expect { subject.delete(@statements.first) }.not_to raise_error
|
102
|
-
end
|
101
|
+
lambda { @mutable.delete(@statements.first) }.should_not raise_error
|
103
102
|
end
|
104
103
|
|
105
104
|
it "should support deleting one statement at a time" do
|
106
|
-
|
107
|
-
|
108
|
-
expect(subject).not_to have_statement(@statements.first)
|
109
|
-
end
|
105
|
+
@mutable.delete(@statements.first)
|
106
|
+
@mutable.should_not have_statement(@statements.first)
|
110
107
|
end
|
111
108
|
|
112
109
|
it "should support deleting multiple statements at a time" do
|
113
|
-
|
114
|
-
|
115
|
-
expect(subject.find { |s| subject.has_statement?(s) }).to be_false
|
116
|
-
end
|
110
|
+
@mutable.delete(*@statements)
|
111
|
+
@statements.find { |s| @mutable.has_statement?(s) }.should be_false
|
117
112
|
end
|
118
113
|
|
119
114
|
it "should support wildcard deletions" do
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
expect(subject).to be_empty
|
131
|
-
end
|
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
|
132
125
|
end
|
133
126
|
|
134
127
|
it "should only delete statements when the context matches" do
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
148
|
+
end
|
149
|
+
|
150
|
+
context "when clearing all statements" do
|
151
|
+
it "should support #clear" do
|
152
|
+
@mutable.should respond_to(:clear)
|
156
153
|
end
|
157
154
|
end
|
158
155
|
end
|