Permalink
Browse files

Use hash diff when looking at failures.

  • Loading branch information...
gkellogg committed May 5, 2012
1 parent 49242c8 commit 322b43f40dbd5a8f8df3f542ac7cd8e3bb8ea205
Showing with 12 additions and 48 deletions.
  1. +1 −48 spec/matchers.rb
  2. +1 −0 spec/suite_helper.rb
  3. +10 −0 spec/support/extensions.rb
View
@@ -61,54 +61,7 @@ def normalize(graph)
failure_message_for_should do |actual|
"Expected: #{expected.is_a?(String) ? expected : expected.to_json(JSON_STATE)}\n" +
"Actual : #{actual.is_a?(String) ? actual : actual.to_json(JSON_STATE)}\n" +
- "Inspect : #{actual.inspect}\n" +
+ (expected.is_a?(Hash) && actual.is_a?(Hash) ? "Diff: #{expected.diff(actual).to_json(JSON_STATE)}\n" : "") +
"Processing results:\n#{info.join("\n")}"
end
end
-
-RSpec::Matchers.define :pass_query do |expected, info|
- match do |actual|
- if info.respond_to?(:information)
- @info = info
- elsif info.is_a?(Hash)
- trace = info[:trace]
- trace = trace.join("\n") if trace.is_a?(Array)
- @info = Info.new(info[:about] || info[:inputDocument] || "", info[:information] || "", trace, info[:inputDocument])
- @info[:expectedResults] = info[:expectedResults] || RDF::Literal::Boolean.new(true)
- elsif info.is_a?(Array)
- @info = Info.new()
- @info[:trace] = info.join("\n")
- @info[:expectedResults] = RDF::Literal::Boolean.new(true)
- else
- @info = Info.new()
- @info[:expectedResults] = RDF::Literal::Boolean.new(true)
- end
-
- @expected = expected.respond_to?(:read) ? expected.read : expected
- @expected = @expected.force_encoding("utf-8") if @expected.respond_to?(:force_encoding)
-
- require 'sparql'
- query = SPARQL.parse(@expected)
- actual = actual.force_encoding("utf-8") if actual.respond_to?(:force_encoding)
- @results = query.execute(actual)
- @results.should == @info.expectedResults
- end
-
- failure_message_for_should do |actual|
- "#{@info.inspect + "\n"}" +
- "#{@info.name + "\n" if @info.name}" +
- if @results.nil?
- "Query failed to return results"
- elsif !@results.is_a?(RDF::Literal::Boolean)
- "Query returned non-boolean results"
- elsif @info.expectedResults != @results
- "Query returned false (expected #{@info.expectedResults})"
- else
- "Query returned true (expected #{@info.expectedResults})"
- end +
- "\n#{@expected}" +
- "\nResults:\n#{@actual.dump(:ttl, :standard_prefixes => true)}" +
- (@info.inputDocument ? "\nInput file: #{@info.input.read}\n" : "") +
- "\nDebug:\n#{@info.trace}"
- end
-end
View
@@ -3,6 +3,7 @@
require 'spira'
require 'json/ld'
require 'open-uri'
+require 'support/extensions'
# For now, override RDF::Utils::File.open_file to look for the file locally before attempting to retrieve it
module RDF::Util
View
@@ -0,0 +1,10 @@
+class Hash
+ def diff(other)
+ self.keys.inject({}) do |memo, key|
+ unless self[key] == other[key]
+ memo[key] = [self[key], other[key]]
+ end
+ memo
+ end
+ end
+end

0 comments on commit 322b43f

Please sign in to comment.