Skip to content

Commit 177852f

Browse files
committed
Use graph equivalence check from rdf-spec.
1 parent a99585a commit 177852f

4 files changed

Lines changed: 4 additions & 54 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ rvm:
77
- 2.0
88
- 2.1
99
- 2.2.4
10+
- 2.3.0
1011
- jruby-9.0.4.0
1112
- rbx-2
1213
cache: bundler

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ group :debug do
1111
end
1212

1313
group :development, :test do
14+
gem 'rdf-spec', git: "git://github.com/ruby-rdf/rdf-spec.git", branch: "develop"
1415
gem "rdf-vocab", git: "git://github.com/ruby-rdf/rdf-vocab.git", branch: "develop"
1516
gem 'rdf-turtle', git: "git://github.com/ruby-rdf/rdf-turtle.git", branch: "develop"
1617
gem 'rest-client-components'

spec/matchers.rb

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# coding: utf-8
2-
require 'rdf/isomorphic'
32
require 'json'
43
JSON_STATE = JSON::State.new(
54
indent: " ",
@@ -9,59 +8,6 @@
98
array_nl: "\n"
109
)
1110

12-
def normalize(graph)
13-
case graph
14-
when RDF::Queryable then graph
15-
when IO, StringIO
16-
RDF::Graph.new.load(graph, base_uri: @info.about)
17-
else
18-
# Figure out which parser to use
19-
g = RDF::Repository.new
20-
reader_class = detect_format(graph)
21-
reader_class.new(graph, base_uri: @info.about).each {|s| g << s}
22-
g
23-
end
24-
end
25-
26-
Info = Struct.new(:about, :coment, :trace, :input, :result, :action, :expected)
27-
28-
RSpec::Matchers.define :be_equivalent_graph do |expected, info|
29-
match do |actual|
30-
@info = if info.respond_to?(:input)
31-
info
32-
elsif info.is_a?(Hash)
33-
identifier = info[:identifier] || expected.is_a?(RDF::Enumerable) ? expected.context : info[:about]
34-
trace = info[:trace]
35-
if trace.is_a?(Array)
36-
trace = trace.map {|s| s.dup.force_encoding(Encoding::UTF_8)}.join("\n")
37-
end
38-
Info.new(identifier, info[:comment] || "", trace)
39-
else
40-
Info.new(expected.is_a?(RDF::Enumerable) ? expected.context : info, info.to_s)
41-
end
42-
@expected = normalize(expected)
43-
@actual = normalize(actual)
44-
@actual.isomorphic_with?(@expected) rescue false
45-
end
46-
47-
failure_message do |actual|
48-
info = @info.respond_to?(:comment) ? @info.comment : @info.inspect
49-
if @expected.is_a?(RDF::Graph) && @actual.size != @expected.size
50-
"Graph entry count differs:\nexpected: #{@expected.size}\nactual: #{@actual.size}"
51-
elsif @expected.is_a?(Array) && @actual.size != @expected.length
52-
"Graph entry count differs:\nexpected: #{@expected.length}\nactual: #{@actual.size}"
53-
else
54-
"Graph differs"
55-
end +
56-
"\n#{info + "\n" unless info.empty?}" +
57-
(@info.action ? "Input file: #{@info.action}\n" : "") +
58-
(@info.result ? "Result file: #{@info.result}\n" : "") +
59-
"Unsorted Expected:\n#{@expected.dump(:ttl, standard_prefixes: true)}" +
60-
"Unsorted Results:\n#{@actual.dump(:ttl, standard_prefixes: true)}" +
61-
(@info.trace ? "\nDebug:\n#{@info.trace}" : "")
62-
end
63-
end
64-
6511
RSpec::Matchers.define :generate do |expected, options = {}|
6612
def parser(options = {})
6713
@debug = options[:progress] ? 2 : []

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require "bundler/setup"
22
require 'rspec/its'
3+
require 'rdf/spec'
4+
require 'rdf/spec/matchers'
35
require 'matchers'
46
require 'webmock/rspec'
57
require 'rdf/turtle'

0 commit comments

Comments
 (0)