Skip to content

Commit 61d02e2

Browse files
committed
Allow other options to be used when serialzing results in be_equivalent_graph.
1 parent 579f921 commit 61d02e2

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

lib/rdf/spec/matchers.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,18 @@ def io_name
266266
end
267267
end
268268

269-
Info = Struct.new(:id, :logger, :action, :result, :format)
269+
Info = Struct.new(:id, :logger, :action, :result, :format, :options) do
270+
def initialize(id:, logger: nil, action: nil, result: nil, format: nil, options: {}); super end
271+
end
270272

271273
RSpec::Matchers.define :be_equivalent_graph do |expected, info|
272274
match do |actual|
273275
@info = if (info.id rescue false)
274276
info
275277
elsif info.is_a?(Logger)
276-
Info.new("", info)
278+
Info.new(logger: info)
277279
elsif info.is_a?(Hash)
278-
Info.new(info[:id], info[:logger], info[:action], info[:result], info[:format])
280+
Info.new(options: info, **info)
279281
else
280282
Info.new(info)
281283
end
@@ -290,19 +292,21 @@ def io_name
290292
end
291293

292294
failure_message do |actual|
295+
dump_opts = {standard_prefixes: true, literal_shorthand: false, validate: false}.merge(@info.options)
293296
info = @info.respond_to?(:information) ? @info.information : @info.inspect
294297
if @expected.is_a?(RDF::Enumerable) && @actual.size != @expected.size
295298
"Graph entry counts differ:\nexpected: #{@expected.size}\nactual: #{@actual.size}\n"
296299
else
297300
"Graphs differ\n"
298301
end +
299302
"\n#{info + "\n" unless info.empty?}" +
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}" +
303+
"Expected:\n#{@expected.dump(@info.format, **dump_opts) rescue @expected.inspect}" +
304+
"Results:\n#{@actual.dump(@info.format, **dump_opts) rescue @actual.inspect}" +
302305
"\nDebug:\n#{@info.logger}"
303306
end
304307

305308
failure_message_when_negated do |actual|
309+
dump_opts = {standard_prefixes: true, literal_shorthand: false, validate: false}.merge(@info.options)
306310
format = case
307311
when RDF.const_defined?(:TriG) then :trig
308312
when RDF.const_defined?(:Turtle) then :ttl
@@ -311,7 +315,7 @@ def io_name
311315
info = @info.respond_to?(:information) ? @info.information : @info.inspect
312316
"Graphs identical\n" +
313317
"\n#{info + "\n" unless info.empty?}" +
314-
"Results:\n#{actual.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
318+
"Results:\n#{actual.dump(@info.format, **dump_opts) rescue @actual.inspect}" +
315319
"\nDebug:\n#{@info.logger}"
316320
end
317321

0 commit comments

Comments
 (0)