rdf-spec 1.1.13 → 1.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rdf/spec.rb +1 -0
- data/lib/rdf/spec/countable.rb +11 -11
- data/lib/rdf/spec/durable.rb +6 -6
- data/lib/rdf/spec/enumerable.rb +170 -148
- data/lib/rdf/spec/format.rb +3 -3
- data/lib/rdf/spec/http_adapter.rb +28 -6
- data/lib/rdf/spec/indexable.rb +6 -8
- data/lib/rdf/spec/inferable.rb +1 -1
- data/lib/rdf/spec/inspects.rb +71 -0
- data/lib/rdf/spec/literal.rb +7 -6
- data/lib/rdf/spec/matchers.rb +21 -0
- data/lib/rdf/spec/mutable.rb +85 -73
- data/lib/rdf/spec/queryable.rb +73 -41
- data/lib/rdf/spec/reader.rb +20 -20
- data/lib/rdf/spec/transaction.rb +24 -13
- data/lib/rdf/spec/writable.rb +97 -63
- data/lib/rdf/spec/writer.rb +18 -18
- data/spec/spec_helper.rb +2 -2
- data/spec/version_spec.rb +1 -1
- metadata +6 -5
data/lib/rdf/spec/format.rb
CHANGED
@@ -17,17 +17,17 @@ RSpec.shared_examples 'an RDF::Format' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "detects #{formats.first} using file_name foo.#{ext}" do
|
20
|
-
expect(RDF::Format.for(:
|
20
|
+
expect(RDF::Format.for(file_name: "foo.#{ext}")).to eq formats.first
|
21
21
|
end
|
22
22
|
|
23
23
|
it "detects #{formats.first} using file_extension #{ext}" do
|
24
|
-
expect(RDF::Format.for(:
|
24
|
+
expect(RDF::Format.for(file_extension: ext)).to eq formats.first
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
RDF::Format.content_types.each do |content_type, formats|
|
29
29
|
it "detects #{formats.first} using content_type #{content_type}" do
|
30
|
-
expect(RDF::Format.for(:
|
30
|
+
expect(RDF::Format.for(content_type: content_type)).to eq formats.first
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
require 'rdf/spec'
|
2
3
|
require 'webmock/rspec'
|
3
4
|
|
@@ -64,19 +65,28 @@ RSpec.shared_examples 'an RDF::HttpAdapter' do
|
|
64
65
|
WebMock.stub_request(:get, uri).to_return(body: "foo", headers: {"Content-Type" => "text/turtle"})
|
65
66
|
RDF::Util::File.open_file(uri) do |f|
|
66
67
|
expect(f.content_type).to eq "text/turtle"
|
67
|
-
expect(f.charset).to eq
|
68
|
-
expect(f.content_encoding).to eq "utf-8"
|
68
|
+
expect(f.charset).to eq "utf-8"
|
69
69
|
expect(f.external_encoding.to_s.downcase).to eq "utf-8"
|
70
70
|
opened.opened
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
it "sets content_type and encoding if provided" do
|
75
|
-
WebMock.stub_request(:get, uri).to_return(body: "foo", headers: {"Content-Type" => "text/turtle ; charset=
|
74
|
+
it "sets content_type and encoding if provided and UTF" do
|
75
|
+
WebMock.stub_request(:get, uri).to_return(body: "foo".force_encoding("UTF-16"), headers: {"Content-Type" => "text/turtle ; charset=UTF-16"})
|
76
76
|
RDF::Util::File.open_file(uri) do |f|
|
77
77
|
expect(f.content_type).to eq "text/turtle"
|
78
|
-
expect(f.charset).to eq "
|
79
|
-
expect(f.external_encoding.to_s.downcase).to eq "
|
78
|
+
expect(f.charset).to eq "utf-16"
|
79
|
+
expect(f.external_encoding.to_s.downcase).to eq "utf-16"
|
80
|
+
opened.opened
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it "sets content_type and encoding to UTF-8 if provided and not UTF" do
|
85
|
+
WebMock.stub_request(:get, uri).to_return(body: "foo".force_encoding("ISO-8859-4"), headers: {"Content-Type" => "text/turtle ; charset=ISO-8859-4"})
|
86
|
+
RDF::Util::File.open_file(uri) do |f|
|
87
|
+
expect(f.content_type).to eq "text/turtle"
|
88
|
+
expect(f.charset).to eq "iso-8859-4"
|
89
|
+
expect(f.external_encoding.to_s.downcase).to eq "utf-8"
|
80
90
|
opened.opened
|
81
91
|
end
|
82
92
|
end
|
@@ -162,6 +172,18 @@ RSpec.shared_examples 'an RDF::HttpAdapter' do
|
|
162
172
|
end
|
163
173
|
end
|
164
174
|
|
175
|
+
it "follows 302 to a relative location" do
|
176
|
+
rel = "../etc/doap.ttl"
|
177
|
+
|
178
|
+
WebMock.stub_request(:get, uri).to_return({status: 302, headers: {"Location" => rel}})
|
179
|
+
WebMock.stub_request(:get, RDF::URI(uri).join(rel).to_s).to_return({body: "foo"})
|
180
|
+
RDF::Util::File.open_file(uri) do |f|
|
181
|
+
expect(f.base_uri).to eq RDF::URI(uri).join(rel).to_s
|
182
|
+
expect(f.read).to eq "foo"
|
183
|
+
opened.opened
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
165
187
|
it "raises an IOError for HTTP 4xx status codes" do
|
166
188
|
opened.opened
|
167
189
|
|
data/lib/rdf/spec/indexable.rb
CHANGED
@@ -10,18 +10,16 @@ RSpec.shared_examples 'an RDF::Indexable' do
|
|
10
10
|
|
11
11
|
subject { indexable }
|
12
12
|
|
13
|
-
it {
|
14
|
-
|
15
|
-
it {should respond_to(:index!)}
|
13
|
+
it {is_expected.to respond_to(:indexed?)}
|
14
|
+
it {is_expected.to respond_to(:index!)}
|
16
15
|
|
17
|
-
it "
|
18
|
-
expect
|
16
|
+
it "returns boolean for #indexed?" do
|
17
|
+
expect(subject.indexed?).to satisfy {|x| x.is_a?(TrueClass) || x.is_a?(FalseClass)}
|
19
18
|
end
|
20
19
|
|
21
|
-
it "
|
22
|
-
expect
|
20
|
+
it "returns self on #index!" do
|
21
|
+
expect(subject.index!).to be
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
26
24
|
|
27
25
|
##
|
data/lib/rdf/spec/inferable.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require 'rdf/ntriples'
|
3
|
+
# override several inspect functions to improve output for what we're doing
|
4
|
+
|
5
|
+
class RDF::Literal
|
6
|
+
def inspect
|
7
|
+
RDF::NTriples::Writer.serialize(self) + " R:L:(#{self.class.to_s.match(/([^:]*)$/)})"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class RDF::URI
|
12
|
+
def inspect
|
13
|
+
RDF::NTriples::Writer.serialize(self)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class RDF::Node
|
18
|
+
def inspect
|
19
|
+
RDF::NTriples::Writer.serialize(self) + "(#{object_id})"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class RDF::Graph
|
24
|
+
def inspect
|
25
|
+
"\n" + dump(RDF.const_defined?(:Turtle) ? :ttl : :ntriples, standard_prefixes: true) + "\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class RDF::Query
|
30
|
+
def inspect
|
31
|
+
"RDF::Query(#{graph_name ? graph_name.to_sxp : 'nil'})#{patterns.inspect}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Array
|
36
|
+
alias_method :inspect_without_formatting, :inspect
|
37
|
+
def inspect_with_formatting
|
38
|
+
if all? { |item| item.is_a?(Hash) }
|
39
|
+
string = "[\n"
|
40
|
+
each do |item|
|
41
|
+
string += " {\n"
|
42
|
+
item.keys.map(&:to_s).sort.each do |key|
|
43
|
+
string += " #{key}: #{item[key.to_sym].inspect}\n"
|
44
|
+
end
|
45
|
+
string += " },\n"
|
46
|
+
end
|
47
|
+
string += "]"
|
48
|
+
string
|
49
|
+
elsif all? { |item| item.is_a?(RDF::Query::Solution)}
|
50
|
+
string = "[\n"
|
51
|
+
each do |item|
|
52
|
+
string += " {\n"
|
53
|
+
item.bindings.keys.map(&:to_s).sort.each do |key|
|
54
|
+
string += " #{key}: #{item.bindings[key.to_sym].inspect}\n"
|
55
|
+
end
|
56
|
+
string += " },\n"
|
57
|
+
end
|
58
|
+
string += "]"
|
59
|
+
string
|
60
|
+
else
|
61
|
+
inspect_without_formatting
|
62
|
+
end
|
63
|
+
end
|
64
|
+
alias_method :inspect, :inspect_with_formatting
|
65
|
+
end
|
66
|
+
|
67
|
+
class RDF::Query::Solutions
|
68
|
+
def inspect
|
69
|
+
string = "vars: #{variable_names.join(",")}\n#{to_a.inspect}"
|
70
|
+
end
|
71
|
+
end
|
data/lib/rdf/spec/literal.rb
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
shared_examples 'RDF::Literal' do |value, datatype_uri|
|
9
9
|
include_examples 'RDF::Literal with datatype and grammar', value, datatype_uri
|
10
|
-
include_examples 'RDF::Literal equality', value
|
10
|
+
include_examples 'RDF::Literal equality', value, value
|
11
11
|
include_examples 'RDF::Literal lexical values', value
|
12
12
|
end
|
13
13
|
|
@@ -69,13 +69,14 @@ end
|
|
69
69
|
shared_examples 'RDF::Literal lookup' do |uri_hash|
|
70
70
|
uri_hash.each do |uri, klass|
|
71
71
|
it "finds #{klass} for #{uri}" do
|
72
|
-
expect(RDF::Literal("0", :
|
72
|
+
expect(RDF::Literal("0", datatype: uri).class).to eq klass
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
shared_examples 'RDF::Literal canonicalization' do |datatype, pairs|
|
78
|
-
pairs.each do |value, str|
|
78
|
+
pairs.each do |value, str, human = nil|
|
79
|
+
human ||= value
|
79
80
|
klass = RDF::Literal.datatyped_class(datatype.to_s)
|
80
81
|
|
81
82
|
it "does not normalize '#{value}' by default" do
|
@@ -85,18 +86,18 @@ shared_examples 'RDF::Literal canonicalization' do |datatype, pairs|
|
|
85
86
|
.to eq value
|
86
87
|
end
|
87
88
|
|
88
|
-
it "normalizes
|
89
|
+
it "normalizes '#{value}' to '#{str}'" do
|
89
90
|
expect(RDF::Literal.new(value,
|
90
91
|
datatype: datatype,
|
91
92
|
canonicalize: true).to_s)
|
92
93
|
.to eq str
|
93
94
|
end
|
94
95
|
|
95
|
-
it "humanizes
|
96
|
+
it "humanizes '#{value}' to '#{str}'" do
|
96
97
|
expect(RDF::Literal.new(value,
|
97
98
|
datatype: datatype,
|
98
99
|
canonicalize: false).humanize)
|
99
|
-
.to eq
|
100
|
+
.to eq human
|
100
101
|
end
|
101
102
|
|
102
103
|
it "instantiates '#{value}' as #{klass}" do
|
data/lib/rdf/spec/matchers.rb
CHANGED
@@ -34,6 +34,10 @@ module RDF; module Spec
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
RSpec::Matchers.define :match_triple_pattern do |*pattern|
|
38
|
+
match { |queryable| not queryable.first(pattern).nil? }
|
39
|
+
end
|
40
|
+
|
37
41
|
RSpec::Matchers.define :be_mutable do
|
38
42
|
match do |enumerable|
|
39
43
|
expect(enumerable).to be_a_kind_of(RDF::Mutable)
|
@@ -256,3 +260,20 @@ module RDF; module Spec
|
|
256
260
|
end
|
257
261
|
end # Matchers
|
258
262
|
end; end # RDF::Spec
|
263
|
+
|
264
|
+
|
265
|
+
module RSpec
|
266
|
+
module Matchers
|
267
|
+
class MatchArray
|
268
|
+
private
|
269
|
+
def safe_sort(array)
|
270
|
+
case
|
271
|
+
when array.all?{|item| item.respond_to?(:<=>) && !item.is_a?(Hash)}
|
272
|
+
array.sort
|
273
|
+
else
|
274
|
+
array
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
data/lib/rdf/spec/mutable.rb
CHANGED
@@ -8,11 +8,11 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
8
8
|
raise 'mutable must be defined with let(:mutable)' unless
|
9
9
|
defined? mutable
|
10
10
|
|
11
|
-
@
|
11
|
+
@supports_named_graphs = mutable.respond_to?(:supports?) && mutable.supports?(:graph_name)
|
12
12
|
end
|
13
13
|
|
14
14
|
let(:resource) { RDF::URI('http://rubygems.org/gems/rdf') }
|
15
|
-
let(:
|
15
|
+
let(:graph_name) { RDF::URI('http://example.org/graph_name') }
|
16
16
|
|
17
17
|
describe RDF::Mutable do
|
18
18
|
subject { mutable }
|
@@ -31,51 +31,60 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
31
31
|
it_behaves_like 'an RDF::Writable'
|
32
32
|
end
|
33
33
|
|
34
|
-
it {
|
35
|
-
it {
|
36
|
-
it {
|
37
|
-
it {
|
38
|
-
it {
|
39
|
-
it {
|
40
|
-
it {
|
41
|
-
it {
|
34
|
+
it {is_expected.to be_empty}
|
35
|
+
it {is_expected.to be_readable}
|
36
|
+
it {is_expected.to be_writable}
|
37
|
+
it {is_expected.to be_mutable}
|
38
|
+
it {is_expected.to_not be_immutable}
|
39
|
+
it {is_expected.to respond_to(:load)}
|
40
|
+
it {is_expected.to respond_to(:clear)}
|
41
|
+
it {is_expected.to respond_to(:delete)}
|
42
42
|
|
43
|
-
its(:count) {
|
43
|
+
its(:count) {is_expected.to be_zero}
|
44
44
|
|
45
45
|
context "#load" do
|
46
|
-
it "
|
46
|
+
it "is_expected.to require an argument" do
|
47
47
|
expect { subject.load }.to raise_error(ArgumentError)
|
48
48
|
end
|
49
49
|
|
50
|
-
it "
|
51
|
-
|
52
|
-
expect { subject.load(RDF::Spec::TRIPLES_FILE) }.not_to raise_error
|
50
|
+
it "is_expected.to accept a string filename argument" do
|
51
|
+
expect { subject.load(RDF::Spec::TRIPLES_FILE) }.not_to raise_error if subject.mutable?
|
53
52
|
end
|
54
53
|
|
55
|
-
it "
|
56
|
-
|
57
|
-
expect { subject.load(RDF::Spec::TRIPLES_FILE, {}) }.not_to raise_error
|
54
|
+
it "is_expected.to accept an optional hash argument" do
|
55
|
+
expect { subject.load(RDF::Spec::TRIPLES_FILE, {}) }.not_to raise_error if subject.mutable?
|
58
56
|
end
|
59
57
|
|
60
|
-
it "
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
it "is_expected.to load statements" do
|
59
|
+
if subject.mutable?
|
60
|
+
subject.load RDF::Spec::TRIPLES_FILE
|
61
|
+
expect(subject.size).to eq File.readlines(RDF::Spec::TRIPLES_FILE).size
|
62
|
+
is_expected.to have_subject(resource)
|
63
|
+
end
|
65
64
|
end
|
66
65
|
|
67
|
-
it "
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
it "is_expected.to load statements with a context override", unless: RDF::VERSION.to_s >= "1.99" do
|
67
|
+
if subject.mutable? && @supports_named_graphs
|
68
|
+
subject.load RDF::Spec::TRIPLES_FILE, context: graph_name
|
69
|
+
is_expected.to have_context(graph_name)
|
70
|
+
expect(subject.query(context: graph_name).size).to eq subject.size
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "is_expected.to load statements with a graph_name override", if: RDF::VERSION.to_s >= "1.99" do
|
75
|
+
if subject.mutable? && @supports_named_graphs
|
76
|
+
subject.load RDF::Spec::TRIPLES_FILE, graph_name: graph_name
|
77
|
+
is_expected.to have_graph(graph_name)
|
78
|
+
expect(subject.query(graph_name: graph_name).size).to eq subject.size
|
79
|
+
end
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
75
83
|
context "#from_{reader}" do
|
76
|
-
it "
|
84
|
+
it "is_expected.to instantiate a reader" do
|
77
85
|
reader = double("reader")
|
78
86
|
expect(reader).to receive(:new).and_return(RDF::Spec.quads.first)
|
87
|
+
allow(RDF::Reader).to receive(:for).and_call_original
|
79
88
|
expect(RDF::Reader).to receive(:for).with(:a_reader).and_return(reader)
|
80
89
|
subject.send(:from_a_reader)
|
81
90
|
end
|
@@ -87,58 +96,61 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
87
96
|
subject.insert(*@statements)
|
88
97
|
end
|
89
98
|
|
90
|
-
it "
|
91
|
-
|
92
|
-
expect { subject.delete(@statements.first) }.not_to raise_error
|
99
|
+
it "is_expected.to not raise errors" do
|
100
|
+
expect { subject.delete(@statements.first) }.not_to raise_error if subject.mutable?
|
93
101
|
end
|
94
102
|
|
95
|
-
it "
|
96
|
-
|
97
|
-
|
98
|
-
|
103
|
+
it "is_expected.to support deleting one statement at a time" do
|
104
|
+
if subject.mutable?
|
105
|
+
subject.delete(@statements.first)
|
106
|
+
is_expected.not_to have_statement(@statements.first)
|
107
|
+
end
|
99
108
|
end
|
100
109
|
|
101
|
-
it "
|
102
|
-
|
103
|
-
|
104
|
-
|
110
|
+
it "is_expected.to support deleting multiple statements at a time" do
|
111
|
+
if subject.mutable?
|
112
|
+
subject.delete(*@statements)
|
113
|
+
expect(subject.find { |s| subject.has_statement?(s) }).to be_nil
|
114
|
+
end
|
105
115
|
end
|
106
116
|
|
107
|
-
it "
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
117
|
+
it "is_expected.to support wildcard deletions" do
|
118
|
+
if subject.mutable?
|
119
|
+
# nothing deleted
|
120
|
+
require 'digest/sha1'
|
121
|
+
count = subject.count
|
122
|
+
subject.delete([nil, nil, Digest::SHA1.hexdigest(File.read(__FILE__))])
|
123
|
+
is_expected.not_to be_empty
|
124
|
+
expect(subject.count).to eq count
|
125
|
+
|
126
|
+
# everything deleted
|
127
|
+
subject.delete([nil, nil, nil])
|
128
|
+
is_expected.to be_empty
|
129
|
+
end
|
119
130
|
end
|
120
131
|
|
121
|
-
it "
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
132
|
+
it "is_expected.to only delete statements when the graph_name matches" do
|
133
|
+
if subject.mutable?
|
134
|
+
# Setup three statements identical except for graph_name
|
135
|
+
count = subject.count + (@supports_named_graphs ? 3 : 1)
|
136
|
+
s1 = RDF::Statement.new(resource, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:1"))
|
137
|
+
s2 = s1.dup
|
138
|
+
s2.graph_name = RDF::URI.new("urn:graph_name:1")
|
139
|
+
s3 = s1.dup
|
140
|
+
s3.graph_name = RDF::URI.new("urn:graph_name:2")
|
141
|
+
subject.insert(s1)
|
142
|
+
subject.insert(s2)
|
143
|
+
subject.insert(s3)
|
144
|
+
expect(subject.count).to eq count
|
145
|
+
|
146
|
+
# Delete one by one
|
147
|
+
subject.delete(s1)
|
148
|
+
expect(subject.count).to eq count - (@supports_named_graphs ? 1 : 1)
|
149
|
+
subject.delete(s2)
|
150
|
+
expect(subject.count).to eq count - (@supports_named_graphs ? 2 : 1)
|
151
|
+
subject.delete(s3)
|
152
|
+
expect(subject.count).to eq count - (@supports_named_graphs ? 3 : 1)
|
153
|
+
end
|
142
154
|
end
|
143
155
|
end
|
144
156
|
end
|