class RoadForest::Testing::MatchesQuery
Public Class Methods
new(pattern = nil, &block)
click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 184 def initialize(pattern = nil, &block) if pattern.nil? and block.nil? raise "Matches query (e.g. should match_query) created with no patterns: probably used a do block..." end pattern ||= [] if Hash === pattern pattern = [pattern] end pattern = pattern.map do |item| ::RDF::Query::Pattern.from(item) end @query = ::RDF::Query.new(pattern, &block) end
Public Instance Methods
failure_message_for_should()
click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 208 def failure_message_for_should require 'pp' "expected: \n#{indent(@query.patterns.pretty_inspect)} \nto return solutions on \n\n#{indent(@actual.dump(:nquads))}\n but didn't" end
failure_message_for_should_not()
click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 213 def failure_message_for_should_not require 'pp' "expected: \n#{indent(@query.patterns.pretty_inspect)} \nnot to return solutions on \n\n#{indent(@actual.dump(:nquads))}\n but does" end
indent(string)
click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 204 def indent(string) string.split("\n").map{|line| " " + line}.join("\n") end
matches?(actual)
click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 198 def matches?(actual) @actual = actual solutions = @query.execute(actual) not solutions.empty? end