rdf-spec 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55c31bab33a2dc7cc1c62abaa30fad175fe9ef7d86fe7829a2b314b637415f10
4
- data.tar.gz: 3ff601a8bc5d1805aa6ae0ccf15423ebf26e33a3c9a34ba49c539ad7096f70ad
3
+ metadata.gz: 5928f2b27a2fd48bd147f95e502dd5baec82b4198d902d0045919939ee0f9e9a
4
+ data.tar.gz: ba8e5efa9daaa1c4634760e3c3995692b4b125b65d8d969d217858858a527972
5
5
  SHA512:
6
- metadata.gz: d2c23be61c1f038c029a248e7cbf32b6ab0aca33ace482ea1c87b427db560e08fa6c72149372a2c731ded61aac3401447e7f9711e13d4344dbb97d9a4ffb8272
7
- data.tar.gz: f28c1b26da93bf7959fda4fdb7e52183c1d7620fc713854000d4890d2a14eb25836daf8b5446174153806b9d80e16dea8b2e6a0d27ec69b9248c2aec61d264fe
6
+ metadata.gz: ee1b742ef3450114f2b2fac9087d7c5ca26f6d89e5dd230435219c0268dab3f7dce40b89ced30b8f08e8dfd74bb4d817374da9a3f742c322d604583a6f670bc7
7
+ data.tar.gz: 49b6a758deb8b713363056780d0fd544b9f478d53a0049dc69c67621fc12f14790bec32ddc18735195a662b63b050e0db9f7020771e7ae02b72e7e91d71f89c1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.1.0
@@ -7,25 +7,24 @@ RSpec.shared_examples 'an RDF::Enumerable' do
7
7
  raise 'enumerable must be set with `let(:enumerable)' unless
8
8
  defined? enumerable
9
9
 
10
- @statements ||= RDF::Spec.quads
10
+ @rdf_enumerable_iv_statements ||= RDF::Spec.quads
11
11
 
12
12
  if enumerable.empty?
13
13
  if (enumerable.writable? rescue false)
14
- enumerable.insert(*@statements)
14
+ enumerable.insert(*@rdf_enumerable_iv_statements)
15
15
  elsif enumerable.respond_to?(:<<)
16
- @statements.each { |statement| enumerable << statement }
16
+ @rdf_enumerable_iv_statements.each { |statement| enumerable << statement }
17
17
  else
18
18
  raise "@enumerable must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
19
19
  end
20
20
  end
21
-
22
- @supports_named_graphs = enumerable.supports?(:graph_name) rescue true
23
21
  end
24
22
 
25
- let(:subject_count) {@statements.map(&:subject).uniq.length}
26
- let(:bnode_subject_count) {@statements.map(&:subject).uniq.select(&:node?).length}
27
- let(:non_bnode_statements) {@statements.reject(&:node?)}
28
- let(:non_bnode_terms) {@statements.map(&:to_quad).flatten.compact.reject(&:node?).uniq}
23
+ let(:supports_named_graphs) {enumerable.supports?(:graph_name) rescue true}
24
+ let(:subject_count) {@rdf_enumerable_iv_statements.map(&:subject).uniq.length}
25
+ let(:bnode_subject_count) {@rdf_enumerable_iv_statements.map(&:subject).uniq.select(&:node?).length}
26
+ let(:non_bnode_statements) {@rdf_enumerable_iv_statements.reject(&:node?)}
27
+ let(:non_bnode_terms) {@rdf_enumerable_iv_statements.map(&:to_quad).flatten.compact.reject(&:node?).uniq}
29
28
 
30
29
  subject { enumerable }
31
30
  it {is_expected.to respond_to(:supports?)}
@@ -57,9 +56,9 @@ RSpec.shared_examples 'an RDF::Enumerable' do
57
56
  it {is_expected.to respond_to(:empty?)}
58
57
  it {is_expected.to_not be_empty}
59
58
  it {is_expected.to respond_to(:count)}
60
- its(:count) {is_expected.to eq @statements.size}
59
+ its(:count) {is_expected.to eq @rdf_enumerable_iv_statements.size}
61
60
  it {is_expected.to respond_to(:size)}
62
- its(:size) {is_expected.to eq @statements.size}
61
+ its(:size) {is_expected.to eq @rdf_enumerable_iv_statements.size}
63
62
 
64
63
  context "and empty" do
65
64
  subject {[].extend(RDF::Enumerable)}
@@ -74,7 +73,7 @@ RSpec.shared_examples 'an RDF::Enumerable' do
74
73
  its(:statements) {is_expected.to be_a(Array)}
75
74
 
76
75
  context "#statements" do
77
- specify {expect(subject.statements.size).to eq @statements.size}
76
+ specify {expect(subject.statements.size).to eq @rdf_enumerable_iv_statements.size}
78
77
  specify {expect(subject.statements).to all(be_a_statement)}
79
78
  end
80
79
 
@@ -89,7 +88,7 @@ RSpec.shared_examples 'an RDF::Enumerable' do
89
88
  end
90
89
 
91
90
  it "does not have statement in different named graph" do
92
- if @supports_named_graphs
91
+ if supports_named_graphs
93
92
  graph_name = RDF::URI.new("urn:graph_name:1")
94
93
  non_bnode_statements.each do |statement|
95
94
  s = statement.dup
@@ -132,7 +131,7 @@ RSpec.shared_examples 'an RDF::Enumerable' do
132
131
 
133
132
  its(:triples) {is_expected.to be_a(Array)}
134
133
  context "#triples" do
135
- specify {expect(subject.triples.size).to eq @statements.size}
134
+ specify {expect(subject.triples.size).to eq @rdf_enumerable_iv_statements.size}
136
135
  specify {expect(subject.triples).to all(be_a_triple)}
137
136
  end
138
137
 
@@ -176,13 +175,13 @@ RSpec.shared_examples 'an RDF::Enumerable' do
176
175
 
177
176
  its(:quads) {is_expected.to be_a(Array)}
178
177
  context "#quads" do
179
- specify {expect(subject.quads.size).to eq @statements.size}
178
+ specify {expect(subject.quads.size).to eq @rdf_enumerable_iv_statements.size}
180
179
  specify {expect(subject.quads).to all(be_a_quad)}
181
180
  end
182
181
 
183
182
  context "#has_quad?" do
184
183
  specify do
185
- if @supports_named_graphs
184
+ if supports_named_graphs
186
185
  non_bnode_statements.each do |statement|
187
186
  is_expected.to have_quad(statement.to_quad)
188
187
  end
@@ -265,7 +264,7 @@ RSpec.shared_examples 'an RDF::Enumerable' do
265
264
  end
266
265
 
267
266
  context "when enumerating predicates" do
268
- let(:predicates) {@statements.map { |s| s.predicate }.uniq}
267
+ let(:predicates) {@rdf_enumerable_iv_statements.map { |s| s.predicate }.uniq}
269
268
  it {is_expected.to respond_to(:predicates)}
270
269
  it {is_expected.to respond_to(:has_predicate?)}
271
270
  it {is_expected.to respond_to(:each_predicate)}
@@ -285,7 +284,7 @@ RSpec.shared_examples 'an RDF::Enumerable' do
285
284
  context "#has_predicate?" do
286
285
  specify do
287
286
  checked = []
288
- @statements.each do |statement|
287
+ @rdf_enumerable_iv_statements.each do |statement|
289
288
  expect(enumerable).to have_predicate(statement.predicate) unless checked.include?(statement.predicate)
290
289
  checked << statement.predicate
291
290
  end
@@ -434,8 +433,8 @@ RSpec.shared_examples 'an RDF::Enumerable' do
434
433
  end
435
434
 
436
435
  it "should implement #has_graph?" do
437
- if @supports_named_graphs
438
- @statements.each do |statement|
436
+ if supports_named_graphs
437
+ @rdf_enumerable_iv_statements.each do |statement|
439
438
  if statement.has_graph?
440
439
  expect(enumerable).to have_graph(statement.graph_name)
441
440
  end
@@ -480,21 +479,21 @@ RSpec.shared_examples 'an RDF::Enumerable' do
480
479
 
481
480
  context "non-existing graph" do
482
481
  let(:graph_name) {RDF::URI.new('http://example.org/does/not/have/this/uri')}
483
- specify {expect(subject.project_graph(graph_name)).to be_empty if @supports_named_graphs}
482
+ specify {expect(subject.project_graph(graph_name)).to be_empty if supports_named_graphs}
484
483
  end
485
484
  end
486
485
 
487
486
  its(:each_graph) {is_expected.to be_an_enumerator}
488
487
 
489
488
  describe "#each_graph" do
490
- let(:graph_names) {@statements.map { |s| s.graph_name }.uniq.compact}
489
+ let(:graph_names) {@rdf_enumerable_iv_statements.map { |s| s.graph_name }.uniq.compact}
491
490
  subject { enumerable.each_graph }
492
491
  it {is_expected.to be_an_enumerator}
493
- specify {is_expected.to all(be_a_graph) if @supports_named_graphs}
492
+ specify {is_expected.to all(be_a_graph) if supports_named_graphs}
494
493
 
495
494
  it "has appropriate number of graphs" do
496
- if @supports_named_graphs
497
- graph_names = @statements.map { |s| s.graph_name }.uniq.compact
495
+ if supports_named_graphs
496
+ graph_names = @rdf_enumerable_iv_statements.map { |s| s.graph_name }.uniq.compact
498
497
  expect(subject.to_a.size).to eq (graph_names.size + 1)
499
498
  end
500
499
  end
@@ -505,7 +504,7 @@ RSpec.shared_examples 'an RDF::Enumerable' do
505
504
  it {is_expected.to be_an_enumerator}
506
505
  it {is_expected.to be_countable}
507
506
  it "enumerates the same as #each_graph" do
508
- expect(subject.to_a).to include(*enumerable.each_graph.to_a) if @supports_named_graphs # expect with match problematic
507
+ expect(subject.to_a).to include(*enumerable.each_graph.to_a) if supports_named_graphs # expect with match problematic
509
508
  end
510
509
  end
511
510
  end
@@ -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|
@@ -31,38 +31,6 @@ class RDF::Query
31
31
  end
32
32
  end
33
33
 
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
34
  class RDF::Query::Solutions
67
35
  def inspect
68
36
  string = "vars: #{variable_names.join(",")}\n#{to_a.inspect}"
@@ -1,4 +1,5 @@
1
1
  require 'rspec/matchers' # @see http://rubygems.org/gems/rspec
2
+ require 'awesome_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| @io = 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
- @io ||= :output
260
+ @rdf_matcher_iv_io ||= :output
260
261
  end
261
262
 
262
263
  # IO name is used for description message
@@ -265,7 +266,7 @@ 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)
269
270
 
270
271
  RSpec::Matchers.define :be_equivalent_graph do |expected, info|
271
272
  match do |actual|
@@ -274,21 +275,21 @@ module RDF; module Spec
274
275
  elsif info.is_a?(Logger)
275
276
  Info.new("", 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])
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
- format = case
288
- when RDF.const_defined?(:TriG) then :trig
289
- when RDF.const_defined?(:Turtle) then :ttl
290
- else :nquads
291
- end
292
293
  info = @info.respond_to?(:information) ? @info.information : @info.inspect
293
294
  if @expected.is_a?(RDF::Enumerable) && @actual.size != @expected.size
294
295
  "Graph entry counts differ:\nexpected: #{@expected.size}\nactual: #{@actual.size}\n"
@@ -296,8 +297,8 @@ module RDF; module Spec
296
297
  "Graphs differ\n"
297
298
  end +
298
299
  "\n#{info + "\n" unless info.empty?}" +
299
- "Expected:\n#{@expected.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @expected.inspect}" +
300
- "Results:\n#{@actual.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
300
+ "Expected:\n#{@expected.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @expected.inspect}" +
301
+ "Results:\n#{@actual.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
301
302
  "\nDebug:\n#{@info.logger}"
302
303
  end
303
304
 
@@ -310,7 +311,7 @@ module RDF; module Spec
310
311
  info = @info.respond_to?(:information) ? @info.information : @info.inspect
311
312
  "Graphs identical\n" +
312
313
  "\n#{info + "\n" unless info.empty?}" +
313
- "Results:\n#{actual.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
314
+ "Results:\n#{actual.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
314
315
  "\nDebug:\n#{@info.logger}"
315
316
  end
316
317
 
@@ -329,15 +330,6 @@ module RDF; module Spec
329
330
  end
330
331
  end
331
332
 
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
333
  RSpec::Matchers.define :produce do |expected, info|
342
334
  match do |actual|
343
335
  @info = if (info.id rescue false)
@@ -355,8 +347,8 @@ module RDF; module Spec
355
347
  failure_message do |actual|
356
348
  info = @info.respond_to?(:information) ? @info.information : @info.inspect
357
349
 
358
- "Expected: #{expected.is_a?(String) ? expected : expected.to_json(JSON_STATE) rescue 'malformed json'}\n" +
359
- "Actual : #{actual.is_a?(String) ? actual : actual.to_json(JSON_STATE) rescue 'malformed json'}\n" +
350
+ "Expected: #{expected.ai}\n" +
351
+ "Actual : #{actual.ai}\n" +
360
352
  "\n#{info + "\n" unless info.empty?}" +
361
353
  "\nDebug:\n#{@info.logger}"
362
354
  end
@@ -365,7 +357,7 @@ module RDF; module Spec
365
357
  info = @info.respond_to?(:information) ? @info.information : @info.inspect
366
358
 
367
359
  "Expected not to produce the following:\n" +
368
- "Actual : #{actual.is_a?(String) ? actual : actual.to_json(JSON_STATE) rescue 'malformed json'}\n" +
360
+ "Actual : #{actual.ai}\n" +
369
361
  "\n#{info + "\n" unless info.empty?}" +
370
362
  "\nDebug:\n#{@info.logger}"
371
363
  end
@@ -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
- @statements = RDF::Spec.triples
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
17
  let(:resource) { RDF::URI('http://rubygems.org/gems/rdf') }
18
18
  let(:graph_name) { RDF::URI('http://example.org/graph_name') }
19
- let(:non_bnode_statements) {@statements.reject(&:node?)}
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(*@statements)
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(*@statements)
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(@statements, [statement])
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(@statements, [@statements.first])
243
- is_expected.to contain_exactly @statements.first
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(@statements, [nil]) }
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
@@ -7,16 +7,16 @@ 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
- @doap = RDF::Spec::QUADS_FILE
11
- @statements = RDF::Spec.quads
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(*@statements)
15
+ queryable.insert(*@rdf_queryable_iv_statements)
16
16
  elsif queryable.respond_to?(:<<)
17
- @statements.each { |statement| queryable << statement }
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 #{@doap} in a before(:each) block"
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
@@ -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 @statements.size
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(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
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 @statements.size
237
- expect(subject.query([resource, nil, nil]).size).to eq File.readlines(@doap).grep(/^<http:\/\/rubygems\.org\/gems\/rdf>/).size
238
- expect(subject.query([RDF::URI("http://ar.to/#self"), nil, nil]).size).to eq File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
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(/^<http:\/\/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 @statements.size
245
- expect(subject.query(subject: resource).size).to eq File.readlines(@doap).grep(/^<http:\/\/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
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(/^<http:\/\/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 @statements.size
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
- object: RDF::Literal::Integer.new(1)).to_a
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
- object: RDF::Literal::Double.new("1.0e0"))
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
 
@@ -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 eq({a: "b"})
210
+ expect(r.prefixes).to include({a: "b"})
211
211
  end
212
212
  end
213
213
  end
@@ -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(*@statements)
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(*@statements)
37
+ delete(*statements)
38
38
  raise 'my error'
39
39
  end
40
40
  end.to raise_error RuntimeError
@@ -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
@@ -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
- @dir = Dir.mktmpdir
59
- @basename = File.join(@dir, "foo")
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(@dir)
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: "#{@basename}.#{sym}").and_return(writer_class)
71
- writer_class.open("#{@basename}.#{sym}") do |r|
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("#{@basename}.#{sym}", format: sym) do |r|
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: "#{@basename}.#{sym}").and_return(writer_class)
94
- writer_class.open("#{@basename}.#{sym}", file_name: "#{@basename}.#{sym}") do |r|
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: @basename).and_return(writer_class)
106
- writer_class.open(@basename, content_type: content_type) do |r|
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
@@ -1,7 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
  require 'rdf/spec/transaction'
3
3
 
4
- describe RDF::Transaction, skip: "pending fixes to immutability errors" do
4
+ describe RDF::Transaction do
5
+ let(:repository) { RDF::Repository.new }
5
6
  # @see lib/rdf/spec/transaction.rb in rdf-spec
6
7
  it_behaves_like "an RDF::Transaction", RDF::Transaction
7
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf-spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-12-14 00:00:00.000000000 Z
13
+ date: 2019-12-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf
@@ -18,14 +18,28 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '3.0'
21
+ version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '3.0'
28
+ version: '3.1'
29
+ - !ruby/object:Gem::Dependency
30
+ name: awesome_print
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.8'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.8'
29
43
  - !ruby/object:Gem::Dependency
30
44
  name: rdf-isomorphic
31
45
  requirement: !ruby/object:Gem::Requirement
@@ -46,56 +60,56 @@ dependencies:
46
60
  requirements:
47
61
  - - "~>"
48
62
  - !ruby/object:Gem::Version
49
- version: '3.7'
63
+ version: '3.9'
50
64
  type: :runtime
51
65
  prerelease: false
52
66
  version_requirements: !ruby/object:Gem::Requirement
53
67
  requirements:
54
68
  - - "~>"
55
69
  - !ruby/object:Gem::Version
56
- version: '3.7'
70
+ version: '3.9'
57
71
  - !ruby/object:Gem::Dependency
58
72
  name: rspec-its
59
73
  requirement: !ruby/object:Gem::Requirement
60
74
  requirements:
61
75
  - - "~>"
62
76
  - !ruby/object:Gem::Version
63
- version: '1.2'
77
+ version: '1.3'
64
78
  type: :runtime
65
79
  prerelease: false
66
80
  version_requirements: !ruby/object:Gem::Requirement
67
81
  requirements:
68
82
  - - "~>"
69
83
  - !ruby/object:Gem::Version
70
- version: '1.2'
84
+ version: '1.3'
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: webmock
73
87
  requirement: !ruby/object:Gem::Requirement
74
88
  requirements:
75
89
  - - "~>"
76
90
  - !ruby/object:Gem::Version
77
- version: '3.1'
91
+ version: '3.7'
78
92
  type: :runtime
79
93
  prerelease: false
80
94
  version_requirements: !ruby/object:Gem::Requirement
81
95
  requirements:
82
96
  - - "~>"
83
97
  - !ruby/object:Gem::Version
84
- version: '3.1'
98
+ version: '3.7'
85
99
  - !ruby/object:Gem::Dependency
86
100
  name: yard
87
101
  requirement: !ruby/object:Gem::Requirement
88
102
  requirements:
89
103
  - - "~>"
90
104
  - !ruby/object:Gem::Version
91
- version: 0.9.12
105
+ version: 0.9.20
92
106
  type: :development
93
107
  prerelease: false
94
108
  version_requirements: !ruby/object:Gem::Requirement
95
109
  requirements:
96
110
  - - "~>"
97
111
  - !ruby/object:Gem::Version
98
- version: 0.9.12
112
+ version: 0.9.20
99
113
  description: RDF.rb extension that provides RSpec matchers and shared examples for
100
114
  RDF objects.
101
115
  email: public-rdf-ruby@w3.org
@@ -167,15 +181,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
181
  requirements:
168
182
  - - ">="
169
183
  - !ruby/object:Gem::Version
170
- version: 2.2.2
184
+ version: '2.4'
171
185
  required_rubygems_version: !ruby/object:Gem::Requirement
172
186
  requirements:
173
187
  - - ">="
174
188
  - !ruby/object:Gem::Version
175
189
  version: '0'
176
190
  requirements: []
177
- rubyforge_project:
178
- rubygems_version: 2.7.3
191
+ rubygems_version: 3.0.6
179
192
  signing_key:
180
193
  specification_version: 4
181
194
  summary: RSpec extensions for RDF.rb.