Skip to content

Commit f8914d7

Browse files
committed
Allow dump format to be specified in be_equivalent_graph.
1 parent 1b54f9c commit f8914d7

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

lib/rdf/spec/matchers.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def io_name
265265
end
266266
end
267267

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

270270
RSpec::Matchers.define :be_equivalent_graph do |expected, info|
271271
match do |actual|
@@ -274,30 +274,30 @@ def io_name
274274
elsif info.is_a?(Logger)
275275
Info.new("", info)
276276
elsif info.is_a?(Hash)
277-
Info.new(info[:id], info[:logger], info[:action], info[:result])
277+
Info.new(info[:id], info[:logger], info[:action], info[:result], info[:format])
278278
else
279279
Info.new(info)
280280
end
281+
@info.format ||= case
282+
when RDF.const_defined?(:TriG) then :trig
283+
when RDF.const_defined?(:Turtle) then :ttl
284+
else :nquads
285+
end
281286
@expected = normalize(expected)
282287
@actual = normalize(actual)
283288
@actual.isomorphic_with?(@expected) rescue false
284289
end
285290

286291
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
292292
info = @info.respond_to?(:information) ? @info.information : @info.inspect
293293
if @expected.is_a?(RDF::Enumerable) && @actual.size != @expected.size
294294
"Graph entry counts differ:\nexpected: #{@expected.size}\nactual: #{@actual.size}\n"
295295
else
296296
"Graphs differ\n"
297297
end +
298298
"\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}" +
299+
"Expected:\n#{@expected.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @expected.inspect}" +
300+
"Results:\n#{@actual.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
301301
"\nDebug:\n#{@info.logger}"
302302
end
303303

@@ -310,7 +310,7 @@ def io_name
310310
info = @info.respond_to?(:information) ? @info.information : @info.inspect
311311
"Graphs identical\n" +
312312
"\n#{info + "\n" unless info.empty?}" +
313-
"Results:\n#{actual.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
313+
"Results:\n#{actual.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
314314
"\nDebug:\n#{@info.logger}"
315315
end
316316

0 commit comments

Comments
 (0)