Skip to content

Commit

Permalink
Add a write_each for unordered write matching
Browse files Browse the repository at this point in the history
The `write` matcher looks for exact strings. Using `write_each` allows
passing multiple arguments to check writes of individual statements
without order dependence.
  • Loading branch information
Tom Johnson committed Jan 16, 2016
1 parent ec008c9 commit 2db722c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/rdf/spec/matchers.rb
Expand Up @@ -184,12 +184,18 @@ module Matchers
end
end

RSpec::Matchers.define :write do |message|
chain(:to) do |io|
@io = io
RSpec::Matchers.define :write_each do |*messages|
supports_block_expectations { true }

match do |block|
messages.each { |message| expect(&block).to write(message) }
end
end

supports_block_expectations {true}
RSpec::Matchers.define :write do |message|
chain(:to) { |io| @io = io }

supports_block_expectations { true }

match do |block|
@output =
Expand Down Expand Up @@ -290,7 +296,7 @@ def normalize(graph)
@actual = normalize(actual)
@actual.isomorphic_with?(@expected) rescue false
end

failure_message do |actual|
format = case
when RDF.const_defined?(:TriG) then :trig
Expand All @@ -307,7 +313,7 @@ def normalize(graph)
"Expected:\n#{@expected.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @expected.inspect}" +
"Results:\n#{@actual.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
"\nDebug:\n#{@info.logger}"
end
end
end

require 'json'
Expand All @@ -332,7 +338,7 @@ def normalize(graph)
end
expect(actual).to eq expected
end

failure_message do |actual|
info = @info.respond_to?(:information) ? @info.information : @info.inspect

Expand Down

0 comments on commit 2db722c

Please sign in to comment.