rdf-spec 3.0.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -19
- data/UNLICENSE +1 -1
- data/VERSION +1 -1
- data/etc/artob.nq +6 -0
- data/etc/bhuga.nq +5 -6
- data/etc/doap.nt +79 -85
- data/etc/doap.ttl +46 -0
- data/etc/gkellogg.nq +6 -6
- data/etc/quads.nq +79 -85
- data/etc/triples.nt +79 -85
- data/lib/rdf/spec/enumerable.rb +26 -27
- data/lib/rdf/spec/http_adapter.rb +18 -0
- data/lib/rdf/spec/inspects.rb +3 -33
- data/lib/rdf/spec/literal.rb +1 -0
- data/lib/rdf/spec/matchers.rb +34 -28
- data/lib/rdf/spec/mutable.rb +11 -11
- data/lib/rdf/spec/queryable.rb +23 -23
- data/lib/rdf/spec/reader.rb +1 -1
- data/lib/rdf/spec/repository.rb +1 -2
- data/lib/rdf/spec/transactable.rb +2 -2
- data/lib/rdf/spec/transaction.rb +2 -2
- data/lib/rdf/spec/writer.rb +50 -23
- data/lib/rdf/spec.rb +17 -15
- data/spec/spec_helper.rb +9 -2
- data/spec/transaction_spec.rb +2 -1
- metadata +50 -22
- data/etc/bendiken.nq +0 -8
@@ -63,6 +63,24 @@ RSpec.shared_examples 'an RDF::HttpAdapter' do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
it "adds User-Agent header using default" do
|
67
|
+
WebMock.stub_request(:get, uri).with do |request|
|
68
|
+
expect(request.headers['User-Agent']).to eq "Ruby RDF.rb/#{RDF::VERSION}"
|
69
|
+
end.to_return(body: "foo")
|
70
|
+
RDF::Util::File.open_file(uri) do |f|
|
71
|
+
opened.opened
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "used provided User-Agent header" do
|
76
|
+
WebMock.stub_request(:get, uri).with do |request|
|
77
|
+
expect(request.headers["User-Agent"]).to eq "Foo"
|
78
|
+
end.to_return(body: "foo")
|
79
|
+
RDF::Util::File.open_file(uri, headers: {"User-Agent" => "Foo"}) do |f|
|
80
|
+
opened.opened
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
66
84
|
it "sets content_type and encoding to utf-8 if absent" do
|
67
85
|
WebMock.stub_request(:get, uri).to_return(body: "foo", headers: {"Content-Type" => "text/turtle"})
|
68
86
|
RDF::Util::File.open_file(uri) do |f|
|
data/lib/rdf/spec/inspects.rb
CHANGED
@@ -3,7 +3,9 @@ require 'rdf'
|
|
3
3
|
|
4
4
|
class RDF::Literal
|
5
5
|
def inspect
|
6
|
-
|
6
|
+
klass = self.class.to_s.match(/([^:]*)$/).to_s
|
7
|
+
dt = self.datatype
|
8
|
+
"\"#{escape(value)}\"#{('@' + self.language.to_s) if self.language?} R:L:(#{klass == 'Literal' && dt ? dt : klass})"
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
@@ -31,38 +33,6 @@ class RDF::Query
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
class Array
|
35
|
-
alias_method :inspect_without_formatting, :inspect
|
36
|
-
def inspect_with_formatting
|
37
|
-
if all? { |item| item.is_a?(Hash) }
|
38
|
-
string = "[\n"
|
39
|
-
each do |item|
|
40
|
-
string += " {\n"
|
41
|
-
item.keys.sort_by(&:to_s).each do |key|
|
42
|
-
string += " #{key.inspect}: #{item[key].inspect}\n"
|
43
|
-
end
|
44
|
-
string += " },\n"
|
45
|
-
end
|
46
|
-
string += "]"
|
47
|
-
string
|
48
|
-
elsif all? { |item| item.is_a?(RDF::Query::Solution)}
|
49
|
-
string = "[\n"
|
50
|
-
each do |item|
|
51
|
-
string += " {\n"
|
52
|
-
item.bindings.keys.sort_by(&:to_s).each do |key|
|
53
|
-
string += " #{key.inspect}: #{item.bindings[key].inspect}\n"
|
54
|
-
end
|
55
|
-
string += " },\n"
|
56
|
-
end
|
57
|
-
string += "]"
|
58
|
-
string
|
59
|
-
else
|
60
|
-
inspect_without_formatting
|
61
|
-
end
|
62
|
-
end
|
63
|
-
alias_method :inspect, :inspect_with_formatting
|
64
|
-
end
|
65
|
-
|
66
36
|
class RDF::Query::Solutions
|
67
37
|
def inspect
|
68
38
|
string = "vars: #{variable_names.join(",")}\n#{to_a.inspect}"
|
data/lib/rdf/spec/literal.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
# include the examples for `RDF::Literal`, `RDF::Literal validation`,
|
6
6
|
# `RDF::Literal canonicalization`, and `RDF::Literal lookup`.
|
7
7
|
|
8
|
+
# @private
|
8
9
|
shared_examples 'RDF::Literal' do |value, datatype_uri|
|
9
10
|
include_examples 'RDF::Literal with datatype and grammar', value, datatype_uri
|
10
11
|
include_examples 'RDF::Literal equality', value, value
|
data/lib/rdf/spec/matchers.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'rspec/matchers' # @see
|
1
|
+
require 'rspec/matchers' # @see https://rubygems.org/gems/rspec
|
2
|
+
require 'amazing_print'
|
2
3
|
|
3
4
|
module RDF; module Spec
|
4
5
|
##
|
@@ -187,17 +188,17 @@ module RDF; module Spec
|
|
187
188
|
RSpec::Matchers.define :write_each do |*messages|
|
188
189
|
supports_block_expectations { true }
|
189
190
|
|
190
|
-
match do |block|
|
191
|
+
match(notify_expectation_failures: true) do |block|
|
191
192
|
messages.each { |message| expect(&block).to write(message) }
|
192
193
|
end
|
193
194
|
end
|
194
195
|
|
195
196
|
RSpec::Matchers.define :write do |message|
|
196
|
-
chain(:to) { |io| @
|
197
|
+
chain(:to) { |io| @rdf_matcher_iv_io = io }
|
197
198
|
|
198
199
|
supports_block_expectations { true }
|
199
200
|
|
200
|
-
match do |block|
|
201
|
+
match(notify_expectation_failures: true) do |block|
|
201
202
|
@output =
|
202
203
|
case io
|
203
204
|
when :output then fake_stdout(&block)
|
@@ -256,7 +257,7 @@ module RDF; module Spec
|
|
256
257
|
|
257
258
|
# default IO is standard output
|
258
259
|
def io
|
259
|
-
@
|
260
|
+
@rdf_matcher_iv_io ||= :output
|
260
261
|
end
|
261
262
|
|
262
263
|
# IO name is used for description message
|
@@ -265,30 +266,37 @@ module RDF; module Spec
|
|
265
266
|
end
|
266
267
|
end
|
267
268
|
|
268
|
-
Info = Struct.new(:id, :logger, :action, :result)
|
269
|
+
Info = Struct.new(:id, :logger, :action, :result, :format, :base, :prefixes)
|
269
270
|
|
270
271
|
RSpec::Matchers.define :be_equivalent_graph do |expected, info|
|
271
272
|
match do |actual|
|
272
273
|
@info = if (info.id rescue false)
|
273
274
|
info
|
274
275
|
elsif info.is_a?(Logger)
|
275
|
-
Info.new(
|
276
|
+
Info.new({logger: info})
|
276
277
|
elsif info.is_a?(Hash)
|
277
|
-
Info.new(info[:id], info[:logger], info[:action], info[:result])
|
278
|
+
Info.new(info[:id], info[:logger], info[:action], info[:result], info[:format], info[:base], info[:prefixes])
|
278
279
|
else
|
279
280
|
Info.new(info)
|
280
281
|
end
|
282
|
+
@info.format ||= case
|
283
|
+
when RDF.const_defined?(:TriG) then :trig
|
284
|
+
when RDF.const_defined?(:Turtle) then :ttl
|
285
|
+
else :nquads
|
286
|
+
end
|
281
287
|
@expected = normalize(expected)
|
282
288
|
@actual = normalize(actual)
|
283
289
|
@actual.isomorphic_with?(@expected) rescue false
|
284
290
|
end
|
285
291
|
|
286
292
|
failure_message do |actual|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
293
|
+
dump_opts = {
|
294
|
+
standard_prefixes: true,
|
295
|
+
literal_shorthand: false,
|
296
|
+
validate: false,
|
297
|
+
base_uri: @info.base,
|
298
|
+
prefixes: @info.prefixes
|
299
|
+
}
|
292
300
|
info = @info.respond_to?(:information) ? @info.information : @info.inspect
|
293
301
|
if @expected.is_a?(RDF::Enumerable) && @actual.size != @expected.size
|
294
302
|
"Graph entry counts differ:\nexpected: #{@expected.size}\nactual: #{@actual.size}\n"
|
@@ -296,12 +304,19 @@ module RDF; module Spec
|
|
296
304
|
"Graphs differ\n"
|
297
305
|
end +
|
298
306
|
"\n#{info + "\n" unless info.empty?}" +
|
299
|
-
"Expected:\n#{@expected.dump(format,
|
300
|
-
"Results:\n#{@actual.dump(format,
|
307
|
+
"Expected:\n#{@expected.dump(@info.format, **dump_opts) rescue @expected.inspect}" +
|
308
|
+
"Results:\n#{@actual.dump(@info.format, **dump_opts) rescue @actual.inspect}" +
|
301
309
|
"\nDebug:\n#{@info.logger}"
|
302
310
|
end
|
303
311
|
|
304
312
|
failure_message_when_negated do |actual|
|
313
|
+
dump_opts = {
|
314
|
+
standard_prefixes: true,
|
315
|
+
literal_shorthand: false,
|
316
|
+
validate: false,
|
317
|
+
base: @info.base,
|
318
|
+
prefixes: @info.prefixes
|
319
|
+
}
|
305
320
|
format = case
|
306
321
|
when RDF.const_defined?(:TriG) then :trig
|
307
322
|
when RDF.const_defined?(:Turtle) then :ttl
|
@@ -310,7 +325,7 @@ module RDF; module Spec
|
|
310
325
|
info = @info.respond_to?(:information) ? @info.information : @info.inspect
|
311
326
|
"Graphs identical\n" +
|
312
327
|
"\n#{info + "\n" unless info.empty?}" +
|
313
|
-
"Results:\n#{actual.dump(format,
|
328
|
+
"Results:\n#{actual.dump(@info.format, **dump_opts) rescue @actual.inspect}" +
|
314
329
|
"\nDebug:\n#{@info.logger}"
|
315
330
|
end
|
316
331
|
|
@@ -329,15 +344,6 @@ module RDF; module Spec
|
|
329
344
|
end
|
330
345
|
end
|
331
346
|
|
332
|
-
require 'json'
|
333
|
-
JSON_STATE = ::JSON::State.new(
|
334
|
-
indent: " ",
|
335
|
-
space: " ",
|
336
|
-
space_before: "",
|
337
|
-
object_nl: "\n",
|
338
|
-
array_nl: "\n"
|
339
|
-
)
|
340
|
-
|
341
347
|
RSpec::Matchers.define :produce do |expected, info|
|
342
348
|
match do |actual|
|
343
349
|
@info = if (info.id rescue false)
|
@@ -355,8 +361,8 @@ module RDF; module Spec
|
|
355
361
|
failure_message do |actual|
|
356
362
|
info = @info.respond_to?(:information) ? @info.information : @info.inspect
|
357
363
|
|
358
|
-
"Expected: #{expected.
|
359
|
-
"Actual : #{actual.
|
364
|
+
"Expected: #{expected.ai}\n" +
|
365
|
+
"Actual : #{actual.ai}\n" +
|
360
366
|
"\n#{info + "\n" unless info.empty?}" +
|
361
367
|
"\nDebug:\n#{@info.logger}"
|
362
368
|
end
|
@@ -365,7 +371,7 @@ module RDF; module Spec
|
|
365
371
|
info = @info.respond_to?(:information) ? @info.information : @info.inspect
|
366
372
|
|
367
373
|
"Expected not to produce the following:\n" +
|
368
|
-
"Actual : #{actual.
|
374
|
+
"Actual : #{actual.ai}\n" +
|
369
375
|
"\n#{info + "\n" unless info.empty?}" +
|
370
376
|
"\nDebug:\n#{@info.logger}"
|
371
377
|
end
|
data/lib/rdf/spec/mutable.rb
CHANGED
@@ -9,14 +9,14 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
9
9
|
defined? mutable
|
10
10
|
|
11
11
|
skip "Immutable resource" unless mutable.mutable?
|
12
|
-
@
|
12
|
+
@rdf_mutable_iv_statements = RDF::Spec.triples
|
13
13
|
@supports_named_graphs = mutable.respond_to?(:supports?) && mutable.supports?(:graph_name)
|
14
14
|
@supports_literal_equality = mutable.respond_to?(:supports?) && mutable.supports?(:literal_equality)
|
15
15
|
end
|
16
16
|
|
17
|
-
let(:resource) { RDF::URI('
|
17
|
+
let(:resource) { RDF::URI('https://rubygems.org/gems/rdf') }
|
18
18
|
let(:graph_name) { RDF::URI('http://example.org/graph_name') }
|
19
|
-
let(:non_bnode_statements) {@
|
19
|
+
let(:non_bnode_statements) {@rdf_mutable_iv_statements.reject(&:node?)}
|
20
20
|
|
21
21
|
describe RDF::Mutable do
|
22
22
|
subject { mutable }
|
@@ -56,7 +56,7 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should accept an optional hash argument" do
|
59
|
-
expect { subject.load(RDF::Spec::TRIPLES_FILE, {}) }.not_to raise_error
|
59
|
+
expect { subject.load(RDF::Spec::TRIPLES_FILE, **{}) }.not_to raise_error
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should load statements" do
|
@@ -69,7 +69,7 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
69
69
|
if @supports_named_graphs
|
70
70
|
subject.load RDF::Spec::TRIPLES_FILE, graph_name: graph_name
|
71
71
|
is_expected.to have_graph(graph_name)
|
72
|
-
expect(subject.query(graph_name: graph_name).size).to eq subject.size
|
72
|
+
expect(subject.query({graph_name: graph_name}).size).to eq subject.size
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
@@ -139,7 +139,7 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
139
139
|
|
140
140
|
context "when deleting statements" do
|
141
141
|
before :each do
|
142
|
-
subject.insert(*@
|
142
|
+
subject.insert(*@rdf_mutable_iv_statements)
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should not raise errors" do
|
@@ -152,7 +152,7 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should support deleting multiple statements at a time" do
|
155
|
-
subject.delete(*@
|
155
|
+
subject.delete(*@rdf_mutable_iv_statements)
|
156
156
|
expect(subject.find { |s| subject.has_statement?(s) }).to be_nil
|
157
157
|
end
|
158
158
|
|
@@ -234,13 +234,13 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
234
234
|
end
|
235
235
|
|
236
236
|
it 'deletes and inserts' do
|
237
|
-
subject.delete_insert(@
|
237
|
+
subject.delete_insert(@rdf_mutable_iv_statements, [statement])
|
238
238
|
is_expected.to contain_exactly statement
|
239
239
|
end
|
240
240
|
|
241
241
|
it 'deletes before inserting' do
|
242
|
-
subject.delete_insert(@
|
243
|
-
is_expected.to contain_exactly @
|
242
|
+
subject.delete_insert(@rdf_mutable_iv_statements, [@rdf_mutable_iv_statements.first])
|
243
|
+
is_expected.to contain_exactly @rdf_mutable_iv_statements.first
|
244
244
|
end
|
245
245
|
|
246
246
|
it 'deletes patterns' do
|
@@ -276,7 +276,7 @@ RSpec.shared_examples 'an RDF::Mutable' do
|
|
276
276
|
if subject.mutable? && subject.supports?(:atomic_write)
|
277
277
|
contents = subject.statements.to_a
|
278
278
|
|
279
|
-
expect { subject.delete_insert(@
|
279
|
+
expect { subject.delete_insert(@rdf_mutable_iv_statements, [nil]) }
|
280
280
|
.to raise_error ArgumentError
|
281
281
|
expect(subject.statements).to contain_exactly(*contents)
|
282
282
|
end
|
data/lib/rdf/spec/queryable.rb
CHANGED
@@ -7,23 +7,23 @@ RSpec.shared_examples 'an RDF::Queryable' do
|
|
7
7
|
raise 'querable must be set with `let(:queryable)' unless
|
8
8
|
defined? queryable
|
9
9
|
|
10
|
-
@
|
11
|
-
@
|
10
|
+
@rdf_queryable_iv_doap = RDF::Spec::QUADS_FILE
|
11
|
+
@rdf_queryable_iv_statements = RDF::Spec.quads
|
12
12
|
|
13
13
|
if queryable.empty?
|
14
14
|
if (queryable.writable? rescue false)
|
15
|
-
queryable.insert(*@
|
15
|
+
queryable.insert(*@rdf_queryable_iv_statements)
|
16
16
|
elsif queryable.respond_to?(:<<)
|
17
|
-
@
|
17
|
+
@rdf_queryable_iv_statements.each { |statement| queryable << statement }
|
18
18
|
else
|
19
|
-
raise "queryable must respond to #<< or be pre-populated with the statements in #{@
|
19
|
+
raise "queryable must respond to #<< or be pre-populated with the statements in #{@rdf_queryable_iv_doap} in a before(:each) block"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe RDF::Queryable do
|
25
25
|
subject {queryable}
|
26
|
-
let(:resource) {RDF::URI('
|
26
|
+
let(:resource) {RDF::URI('https://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]}}
|
29
29
|
|
@@ -95,7 +95,7 @@ RSpec.shared_examples 'an RDF::Queryable' do
|
|
95
95
|
pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: nil)
|
96
96
|
solutions = []
|
97
97
|
subject.send(method, pattern) {|s| solutions << s}
|
98
|
-
expect(solutions.size).to eq @
|
98
|
+
expect(solutions.size).to eq @rdf_queryable_iv_statements.size
|
99
99
|
end
|
100
100
|
|
101
101
|
it "returns statements from named graphs with variable graph_name" do
|
@@ -114,7 +114,7 @@ RSpec.shared_examples 'an RDF::Queryable' do
|
|
114
114
|
pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: RDF::URI("http://ar.to/#self"))
|
115
115
|
solutions = []
|
116
116
|
subject.send(method, pattern) {|s| solutions << s}
|
117
|
-
expect(solutions.size).to eq File.readlines(@
|
117
|
+
expect(solutions.size).to eq File.readlines(@rdf_queryable_iv_doap).grep(/^<http:\/\/ar.to\/\#self>/).size
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
@@ -233,22 +233,22 @@ RSpec.shared_examples 'an RDF::Queryable' do
|
|
233
233
|
end
|
234
234
|
|
235
235
|
it "returns the correct number of results for array queries" do
|
236
|
-
expect(subject.query([nil, nil, nil]).size).to eq @
|
237
|
-
expect(subject.query([resource, nil, nil]).size).to eq File.readlines(@
|
238
|
-
expect(subject.query([RDF::URI("http://ar.to/#self"), nil, nil]).size).to eq File.readlines(@
|
236
|
+
expect(subject.query([nil, nil, nil]).size).to eq @rdf_queryable_iv_statements.size
|
237
|
+
expect(subject.query([resource, nil, nil]).size).to eq File.readlines(@rdf_queryable_iv_doap).grep(/^<https:\/\/rubygems\.org\/gems\/rdf>/).size
|
238
|
+
expect(subject.query([RDF::URI("http://ar.to/#self"), nil, nil]).size).to eq File.readlines(@rdf_queryable_iv_doap).grep(/^<http:\/\/ar.to\/\#self>/).size
|
239
239
|
expect(subject.query([resource, RDF::URI("http://usefulinc.com/ns/doap#name"), nil]).size).to eq 1
|
240
240
|
expect(subject.query([nil, nil, RDF::URI("http://usefulinc.com/ns/doap#Project")]).size).to eq 1
|
241
241
|
end
|
242
242
|
|
243
243
|
it "returns the correct number of results for hash queries" do
|
244
|
-
expect(subject.query({}).size).to eq @
|
245
|
-
expect(subject.query(subject: resource).size).to eq File.readlines(@
|
246
|
-
expect(subject.query(subject: resource, predicate: RDF::URI("http://usefulinc.com/ns/doap#name")).size).to eq 1
|
247
|
-
expect(subject.query(object: RDF::URI("http://usefulinc.com/ns/doap#Project")).size).to eq 1
|
244
|
+
expect(subject.query({}).size).to eq @rdf_queryable_iv_statements.size
|
245
|
+
expect(subject.query({subject: resource}).size).to eq File.readlines(@rdf_queryable_iv_doap).grep(/^<https:\/\/rubygems\.org\/gems\/rdf>/).size
|
246
|
+
expect(subject.query({subject: resource, predicate: RDF::URI("http://usefulinc.com/ns/doap#name")}).size).to eq 1
|
247
|
+
expect(subject.query({object: RDF::URI("http://usefulinc.com/ns/doap#Project")}).size).to eq 1
|
248
248
|
end
|
249
249
|
|
250
250
|
it "returns the correct number of results for query queries" do
|
251
|
-
expect(subject.query(query).size).to eq @
|
251
|
+
expect(subject.query(query).size).to eq @rdf_queryable_iv_statements.size
|
252
252
|
end
|
253
253
|
end
|
254
254
|
end
|
@@ -256,13 +256,13 @@ RSpec.shared_examples 'an RDF::Queryable' do
|
|
256
256
|
context "with specific patterns from SPARQL" do
|
257
257
|
context "triple pattern combinations" do
|
258
258
|
it "?s p o" do
|
259
|
-
expect(subject.query(predicate: RDF::URI("http://example.org/p"), object: RDF::Literal.new(1)).to_a).to(
|
259
|
+
expect(subject.query({predicate: RDF::URI("http://example.org/p"), object: RDF::Literal.new(1)}).to_a).to(
|
260
260
|
include *[RDF::Statement.new(RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1), RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
|
261
261
|
)
|
262
262
|
end
|
263
263
|
|
264
264
|
it "s ?p o" do
|
265
|
-
expect(subject.query(subject: RDF::URI("http://example.org/xi2"), object: RDF::Literal.new(1)).to_a).to(
|
265
|
+
expect(subject.query({subject: RDF::URI("http://example.org/xi2"), object: RDF::Literal.new(1)}).to_a).to(
|
266
266
|
include *[RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
|
267
267
|
)
|
268
268
|
end
|
@@ -272,8 +272,8 @@ RSpec.shared_examples 'an RDF::Queryable' do
|
|
272
272
|
context "data/r2/expr-equals" do
|
273
273
|
context "graph-1" do
|
274
274
|
let(:result) do
|
275
|
-
queryable.query(predicate: RDF::URI("http://example.org/p"),
|
276
|
-
|
275
|
+
queryable.query({predicate: RDF::URI("http://example.org/p"),
|
276
|
+
object: RDF::Literal::Integer.new(1)}).to_a
|
277
277
|
end
|
278
278
|
|
279
279
|
it 'has two solutions' do
|
@@ -293,8 +293,8 @@ RSpec.shared_examples 'an RDF::Queryable' do
|
|
293
293
|
|
294
294
|
context "graph-2" do
|
295
295
|
let(:result) do
|
296
|
-
queryable.query(predicate: RDF::URI("http://example.org/p"),
|
297
|
-
|
296
|
+
queryable.query({predicate: RDF::URI("http://example.org/p"),
|
297
|
+
object: RDF::Literal::Double.new("1.0e0")})
|
298
298
|
.to_a
|
299
299
|
end
|
300
300
|
|
@@ -384,7 +384,7 @@ RSpec.shared_examples 'an RDF::Queryable' do
|
|
384
384
|
end
|
385
385
|
|
386
386
|
it "returns an appropriate value when the pattern matches" do
|
387
|
-
matching_patterns = [[nil, nil, nil], [RDF::URI("
|
387
|
+
matching_patterns = [[nil, nil, nil], [RDF::URI("https://rubygems.org/gems/rdf"), nil, nil]]
|
388
388
|
matching_patterns.each do |matching_pattern|
|
389
389
|
matching_values = subject.query(matching_pattern).map(&:subject)
|
390
390
|
expect(matching_values).to include subject.first_subject(matching_pattern)
|
data/lib/rdf/spec/reader.rb
CHANGED
@@ -207,7 +207,7 @@ RSpec.shared_examples 'an RDF::Reader' do
|
|
207
207
|
expect(reader_mock).to receive(:got_here)
|
208
208
|
reader_class.new(reader_input, prefixes: {a: "b"}) do |r|
|
209
209
|
reader_mock.got_here
|
210
|
-
expect(r.prefixes).to
|
210
|
+
expect(r.prefixes).to include({a: "b"})
|
211
211
|
end
|
212
212
|
end
|
213
213
|
end
|
data/lib/rdf/spec/repository.rb
CHANGED
@@ -7,9 +7,8 @@ RSpec.shared_examples 'an RDF::Repository' do
|
|
7
7
|
raise 'repository must be set with `let(:repository)' unless
|
8
8
|
defined? repository
|
9
9
|
|
10
|
-
@statements = RDF::Spec.quads
|
11
10
|
if repository.empty? && repository.writable?
|
12
|
-
repository.insert(
|
11
|
+
repository.insert(*RDF::Spec.quads)
|
13
12
|
elsif repository.empty?
|
14
13
|
raise "+@repository+ must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
|
15
14
|
end
|
@@ -3,7 +3,7 @@ require 'rdf/spec'
|
|
3
3
|
RSpec.shared_examples 'an RDF::Transactable' do
|
4
4
|
include RDF::Spec::Matchers
|
5
5
|
|
6
|
-
let(:statements) { RDF::Spec.quads }
|
6
|
+
let(:statements) { @rdf_transactable_iv_statements = RDF::Spec.quads }
|
7
7
|
|
8
8
|
before do
|
9
9
|
raise '`transactable` must be set with `let(:transactable)`' unless
|
@@ -34,7 +34,7 @@ RSpec.shared_examples 'an RDF::Transactable' do
|
|
34
34
|
|
35
35
|
expect do
|
36
36
|
subject.transaction(mutable: true) do
|
37
|
-
delete(
|
37
|
+
delete(*statements)
|
38
38
|
raise 'my error'
|
39
39
|
end
|
40
40
|
end.to raise_error RuntimeError
|
data/lib/rdf/spec/transaction.rb
CHANGED
@@ -212,10 +212,10 @@ shared_examples "an RDF::Transaction" do |klass|
|
|
212
212
|
with_name = st.dup
|
213
213
|
with_name.graph_name = graph_uri
|
214
214
|
|
215
|
-
expect do
|
215
|
+
expect do
|
216
216
|
subject.insert(st)
|
217
217
|
subject.execute
|
218
|
-
end.to change { subject.repository }
|
218
|
+
end.to change { subject.repository.statements }
|
219
219
|
|
220
220
|
expect(subject.repository).to have_statement(with_name)
|
221
221
|
end
|
data/lib/rdf/spec/writer.rb
CHANGED
@@ -13,6 +13,27 @@ RSpec.shared_examples 'an RDF::Writer' do
|
|
13
13
|
let(:reader_class) { writer_class.format.reader}
|
14
14
|
let(:format_class) { writer_class.format }
|
15
15
|
|
16
|
+
let(:graph) do
|
17
|
+
@rdf_writer_iv_graph ||= begin
|
18
|
+
n1 = RDF::Node("a")
|
19
|
+
n2 = RDF::Node("a")
|
20
|
+
p = RDF::URI("http://example/pred")
|
21
|
+
s1 = RDF::Statement(n1, p, n1)
|
22
|
+
s2 = RDF::Statement(n2, p, n2)
|
23
|
+
s3 = RDF::Statement(n1, p, n2)
|
24
|
+
s4 = RDF::Statement(n2, p, n1)
|
25
|
+
RDF::Graph.new.insert(s1, s2, s3, s4)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:serialized) do
|
30
|
+
@rdf_writer_iv_serialized ||= begin
|
31
|
+
writer_class.buffer do |w|
|
32
|
+
w << graph
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
16
37
|
describe ".each" do
|
17
38
|
it "yields each writer" do
|
18
39
|
writer_class.each do |r|
|
@@ -31,18 +52,6 @@ RSpec.shared_examples 'an RDF::Writer' do
|
|
31
52
|
|
32
53
|
it "should serialize different BNodes sharing a common identifier to using different BNode ids" do
|
33
54
|
if reader_class
|
34
|
-
n1 = RDF::Node("a")
|
35
|
-
n2 = RDF::Node("a")
|
36
|
-
p = RDF::URI("http://example/pred")
|
37
|
-
s1 = RDF::Statement(n1, p, n1)
|
38
|
-
s2 = RDF::Statement(n2, p, n2)
|
39
|
-
s3 = RDF::Statement(n1, p, n2)
|
40
|
-
s4 = RDF::Statement(n2, p, n1)
|
41
|
-
graph = RDF::Graph.new.insert(s1, s2, s3, s4)
|
42
|
-
expect(graph.count).to eql 4
|
43
|
-
serialized = writer_class.buffer do |w|
|
44
|
-
w << graph
|
45
|
-
end
|
46
55
|
expect(serialized).not_to be_empty
|
47
56
|
graph2 = RDF::Graph.new do |g|
|
48
57
|
g << reader_class.new(serialized)
|
@@ -50,25 +59,43 @@ RSpec.shared_examples 'an RDF::Writer' do
|
|
50
59
|
expect(graph2.count).to eql 4
|
51
60
|
end
|
52
61
|
end
|
62
|
+
|
63
|
+
it "returns a string" do
|
64
|
+
expect(serialized).to be_a(String)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should use encoding defined for format by default" do
|
68
|
+
writer_class.new do |w|
|
69
|
+
expect(serialized.encoding).to eql w.encoding
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should use provided encoding if specified" do
|
74
|
+
str = writer_class.buffer(encoding: Encoding::ASCII_8BIT) do |w|
|
75
|
+
w << graph
|
76
|
+
end
|
77
|
+
|
78
|
+
expect(str.encoding).to eql Encoding::ASCII_8BIT
|
79
|
+
end
|
53
80
|
end
|
54
81
|
|
55
82
|
describe ".open" do
|
56
83
|
before(:each) do
|
57
84
|
allow(RDF::Util::File).to receive(:open_file).and_yield(StringIO.new("foo"))
|
58
|
-
@
|
59
|
-
@
|
85
|
+
@rdf_writer_iv_dir = Dir.mktmpdir
|
86
|
+
@rdf_writer_iv_basename = File.join(@rdf_writer_iv_dir, "foo")
|
60
87
|
end
|
61
88
|
|
62
89
|
after(:each) do
|
63
|
-
FileUtils.rm_rf(@
|
90
|
+
FileUtils.rm_rf(@rdf_writer_iv_dir)
|
64
91
|
end
|
65
92
|
|
66
93
|
it "yields writer given file_name" do
|
67
94
|
format_class.file_extensions.each_pair do |sym, content_type|
|
68
95
|
writer_mock = double("writer")
|
69
96
|
expect(writer_mock).to receive(:got_here)
|
70
|
-
expect(writer_class).to receive(:for).with(file_name: "#{@
|
71
|
-
writer_class.open("#{@
|
97
|
+
expect(writer_class).to receive(:for).with(file_name: "#{@rdf_writer_iv_basename}.#{sym}").and_return(writer_class)
|
98
|
+
writer_class.open("#{@rdf_writer_iv_basename}.#{sym}") do |r|
|
72
99
|
expect(r).to be_a(RDF::Writer)
|
73
100
|
writer_mock.got_here
|
74
101
|
end
|
@@ -80,7 +107,7 @@ RSpec.shared_examples 'an RDF::Writer' do
|
|
80
107
|
writer_mock = double("writer")
|
81
108
|
expect(writer_mock).to receive(:got_here)
|
82
109
|
expect(writer_class).to receive(:for).with(sym).and_return(writer_class)
|
83
|
-
writer_class.open("#{@
|
110
|
+
writer_class.open("#{@rdf_writer_iv_basename}.#{sym}", format: sym) do |r|
|
84
111
|
expect(r).to be_a(RDF::Writer)
|
85
112
|
writer_mock.got_here
|
86
113
|
end
|
@@ -90,8 +117,8 @@ RSpec.shared_examples 'an RDF::Writer' do
|
|
90
117
|
format_class.file_extensions.each_pair do |sym, content_type|
|
91
118
|
writer_mock = double("writer")
|
92
119
|
expect(writer_mock).to receive(:got_here)
|
93
|
-
expect(writer_class).to receive(:for).with(file_name: "#{@
|
94
|
-
writer_class.open("#{@
|
120
|
+
expect(writer_class).to receive(:for).with(file_name: "#{@rdf_writer_iv_basename}.#{sym}").and_return(writer_class)
|
121
|
+
writer_class.open("#{@rdf_writer_iv_basename}.#{sym}", file_name: "#{@rdf_writer_iv_basename}.#{sym}") do |r|
|
95
122
|
expect(r).to be_a(RDF::Writer)
|
96
123
|
writer_mock.got_here
|
97
124
|
end
|
@@ -102,8 +129,8 @@ RSpec.shared_examples 'an RDF::Writer' do
|
|
102
129
|
format_class.content_types.each_pair do |content_type, formats|
|
103
130
|
writer_mock = double("writer")
|
104
131
|
expect(writer_mock).to receive(:got_here)
|
105
|
-
expect(writer_class).to receive(:for).with(content_type: content_type, file_name: @
|
106
|
-
writer_class.open(@
|
132
|
+
expect(writer_class).to receive(:for).with(content_type: content_type, file_name: @rdf_writer_iv_basename).and_return(writer_class)
|
133
|
+
writer_class.open(@rdf_writer_iv_basename, content_type: content_type) do |r|
|
107
134
|
expect(r).to be_a(RDF::Writer)
|
108
135
|
writer_mock.got_here
|
109
136
|
end
|
@@ -155,7 +182,7 @@ RSpec.shared_examples 'an RDF::Writer' do
|
|
155
182
|
expect do
|
156
183
|
writer_class.new(file, logger: false) do |w|
|
157
184
|
w << RDF::Statement(
|
158
|
-
RDF::URI("
|
185
|
+
RDF::URI("https://rubygems.org/gems/rdf"),
|
159
186
|
RDF::URI("http://purl.org/dc/terms/creator"),
|
160
187
|
nil)
|
161
188
|
end
|