Skip to content

Commit 4726bb4

Browse files
committed
Finish 3.1.0
2 parents 59eae01 + 84a9cbe commit 4726bb4

File tree

16 files changed

+165
-169
lines changed

16 files changed

+165
-169
lines changed

.travis.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
language: ruby
2-
bundler_args: --without debug
32
script: "bundle exec rspec spec"
4-
before_install: "gem update --system"
53
env:
64
- CI=true
75
rvm:
8-
- 2.2
9-
- 2.3
106
- 2.4
117
- 2.5
12-
- jruby-9
13-
- rbx-3
8+
- 2.6
9+
- 2.7
10+
- jruby
1411
cache: bundler
1512
sudo: false
1613
matrix:
1714
allow_failures:
18-
- rvm: jruby-9
19-
- rvm: rbx-3
15+
- rvm: jruby
16+
- rvm: 2.7
2017
dist: trusty

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ group :debug do
1010
end
1111

1212
group :development, :test do
13-
gem 'simplecov', require: false, platform: :mri
14-
gem 'coveralls', require: false, platform: :mri
13+
gem 'simplecov', platforms: :mri
14+
gem 'coveralls', '~> 0.8', platforms: :mri
1515
end

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0
1+
3.1.0

lib/rdf/spec/enumerable.rb

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,24 @@
77
raise 'enumerable must be set with `let(:enumerable)' unless
88
defined? enumerable
99

10-
@statements ||= RDF::Spec.quads
10+
@rdf_enumerable_iv_statements ||= RDF::Spec.quads
1111

1212
if enumerable.empty?
1313
if (enumerable.writable? rescue false)
14-
enumerable.insert(*@statements)
14+
enumerable.insert(*@rdf_enumerable_iv_statements)
1515
elsif enumerable.respond_to?(:<<)
16-
@statements.each { |statement| enumerable << statement }
16+
@rdf_enumerable_iv_statements.each { |statement| enumerable << statement }
1717
else
1818
raise "@enumerable must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
1919
end
2020
end
21-
22-
@supports_named_graphs = enumerable.supports?(:graph_name) rescue true
2321
end
2422

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}
2928

3029
subject { enumerable }
3130
it {is_expected.to respond_to(:supports?)}
@@ -57,9 +56,9 @@
5756
it {is_expected.to respond_to(:empty?)}
5857
it {is_expected.to_not be_empty}
5958
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}
6160
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}
6362

6463
context "and empty" do
6564
subject {[].extend(RDF::Enumerable)}
@@ -74,7 +73,7 @@
7473
its(:statements) {is_expected.to be_a(Array)}
7574

7675
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}
7877
specify {expect(subject.statements).to all(be_a_statement)}
7978
end
8079

@@ -89,7 +88,7 @@
8988
end
9089

9190
it "does not have statement in different named graph" do
92-
if @supports_named_graphs
91+
if supports_named_graphs
9392
graph_name = RDF::URI.new("urn:graph_name:1")
9493
non_bnode_statements.each do |statement|
9594
s = statement.dup
@@ -132,7 +131,7 @@
132131

133132
its(:triples) {is_expected.to be_a(Array)}
134133
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}
136135
specify {expect(subject.triples).to all(be_a_triple)}
137136
end
138137

@@ -176,13 +175,13 @@
176175

177176
its(:quads) {is_expected.to be_a(Array)}
178177
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}
180179
specify {expect(subject.quads).to all(be_a_quad)}
181180
end
182181

183182
context "#has_quad?" do
184183
specify do
185-
if @supports_named_graphs
184+
if supports_named_graphs
186185
non_bnode_statements.each do |statement|
187186
is_expected.to have_quad(statement.to_quad)
188187
end
@@ -265,7 +264,7 @@
265264
end
266265

267266
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}
269268
it {is_expected.to respond_to(:predicates)}
270269
it {is_expected.to respond_to(:has_predicate?)}
271270
it {is_expected.to respond_to(:each_predicate)}
@@ -285,7 +284,7 @@
285284
context "#has_predicate?" do
286285
specify do
287286
checked = []
288-
@statements.each do |statement|
287+
@rdf_enumerable_iv_statements.each do |statement|
289288
expect(enumerable).to have_predicate(statement.predicate) unless checked.include?(statement.predicate)
290289
checked << statement.predicate
291290
end
@@ -434,8 +433,8 @@
434433
end
435434

436435
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|
439438
if statement.has_graph?
440439
expect(enumerable).to have_graph(statement.graph_name)
441440
end
@@ -480,21 +479,21 @@
480479

481480
context "non-existing graph" do
482481
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}
484483
end
485484
end
486485

487486
its(:each_graph) {is_expected.to be_an_enumerator}
488487

489488
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}
491490
subject { enumerable.each_graph }
492491
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}
494493

495494
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
498497
expect(subject.to_a.size).to eq (graph_names.size + 1)
499498
end
500499
end
@@ -505,7 +504,7 @@
505504
it {is_expected.to be_an_enumerator}
506505
it {is_expected.to be_countable}
507506
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
509508
end
510509
end
511510
end

lib/rdf/spec/http_adapter.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@
6363
end
6464
end
6565

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+
6684
it "sets content_type and encoding to utf-8 if absent" do
6785
WebMock.stub_request(:get, uri).to_return(body: "foo", headers: {"Content-Type" => "text/turtle"})
6886
RDF::Util::File.open_file(uri) do |f|

lib/rdf/spec/inspects.rb

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,6 @@ def inspect
3131
end
3232
end
3333

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-
6634
class RDF::Query::Solutions
6735
def inspect
6836
string = "vars: #{variable_names.join(",")}\n#{to_a.inspect}"

lib/rdf/spec/matchers.rb

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rspec/matchers' # @see http://rubygems.org/gems/rspec
2+
require 'awesome_print'
23

34
module RDF; module Spec
45
##
@@ -187,17 +188,17 @@ module Matchers
187188
RSpec::Matchers.define :write_each do |*messages|
188189
supports_block_expectations { true }
189190

190-
match do |block|
191+
match(notify_expectation_failures: true) do |block|
191192
messages.each { |message| expect(&block).to write(message) }
192193
end
193194
end
194195

195196
RSpec::Matchers.define :write do |message|
196-
chain(:to) { |io| @io = io }
197+
chain(:to) { |io| @rdf_matcher_iv_io = io }
197198

198199
supports_block_expectations { true }
199200

200-
match do |block|
201+
match(notify_expectation_failures: true) do |block|
201202
@output =
202203
case io
203204
when :output then fake_stdout(&block)
@@ -256,7 +257,7 @@ def fake_stdout
256257

257258
# default IO is standard output
258259
def io
259-
@io ||= :output
260+
@rdf_matcher_iv_io ||= :output
260261
end
261262

262263
# IO name is used for description message
@@ -265,7 +266,7 @@ def io_name
265266
end
266267
end
267268

268-
Info = Struct.new(:id, :logger, :action, :result)
269+
Info = Struct.new(:id, :logger, :action, :result, :format)
269270

270271
RSpec::Matchers.define :be_equivalent_graph do |expected, info|
271272
match do |actual|
@@ -274,30 +275,30 @@ def io_name
274275
elsif info.is_a?(Logger)
275276
Info.new("", info)
276277
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])
278279
else
279280
Info.new(info)
280281
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
281287
@expected = normalize(expected)
282288
@actual = normalize(actual)
283289
@actual.isomorphic_with?(@expected) rescue false
284290
end
285291

286292
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
292293
info = @info.respond_to?(:information) ? @info.information : @info.inspect
293294
if @expected.is_a?(RDF::Enumerable) && @actual.size != @expected.size
294295
"Graph entry counts differ:\nexpected: #{@expected.size}\nactual: #{@actual.size}\n"
295296
else
296297
"Graphs differ\n"
297298
end +
298299
"\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}" +
301302
"\nDebug:\n#{@info.logger}"
302303
end
303304

@@ -310,7 +311,7 @@ def io_name
310311
info = @info.respond_to?(:information) ? @info.information : @info.inspect
311312
"Graphs identical\n" +
312313
"\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}" +
314315
"\nDebug:\n#{@info.logger}"
315316
end
316317

@@ -329,15 +330,6 @@ def normalize(graph)
329330
end
330331
end
331332

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-
341333
RSpec::Matchers.define :produce do |expected, info|
342334
match do |actual|
343335
@info = if (info.id rescue false)
@@ -355,8 +347,8 @@ def normalize(graph)
355347
failure_message do |actual|
356348
info = @info.respond_to?(:information) ? @info.information : @info.inspect
357349

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" +
360352
"\n#{info + "\n" unless info.empty?}" +
361353
"\nDebug:\n#{@info.logger}"
362354
end
@@ -365,7 +357,7 @@ def normalize(graph)
365357
info = @info.respond_to?(:information) ? @info.information : @info.inspect
366358

367359
"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" +
369361
"\n#{info + "\n" unless info.empty?}" +
370362
"\nDebug:\n#{@info.logger}"
371363
end

0 commit comments

Comments
 (0)