Class: RoadForest::Testing::MatchesQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/test-support/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern = nil, &block) ⇒ MatchesQuery

Returns a new instance of MatchesQuery.



4
5
6
7
8
9
10
11
12
13
# File 'lib/roadforest/test-support/matchers.rb', line 4

def initialize(pattern = nil, &block)
  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

Instance Method Details

#failure_message_for_shouldObject



21
22
23
# File 'lib/roadforest/test-support/matchers.rb', line 21

def failure_message_for_should
  "expected #{@query.patterns.inspect} to return solutions on \n#{@actual.dump(:nquads)}\n but didn't"
end

#failure_message_for_should_notObject



25
26
27
# File 'lib/roadforest/test-support/matchers.rb', line 25

def failure_message_for_should_not
  "expected #{@query.patterns.inspect} not to return solutions on \n#{@actual.dump(:nquads)}\n but does"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/roadforest/test-support/matchers.rb', line 15

def matches?(actual)
  @actual = actual
  solutions = @query.execute(actual)
  not solutions.empty?
end