Class: QueryMatchers::QueryExecutionMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/query_matchers/query_execution_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected, counter = QueryCounter.new) ⇒ QueryExecutionMatcher

Returns a new instance of QueryExecutionMatcher.



6
7
8
9
# File 'lib/query_matchers/query_execution_matcher.rb', line 6

def initialize(expected, counter = QueryCounter.new)
  @expected = expected
  @counter = counter
end

Instance Method Details

#failure_messageObject Also known as: failure_message_for_should



17
18
19
20
21
22
# File 'lib/query_matchers/query_execution_matcher.rb', line 17

def failure_message
  "expected block to execute #{@expected} SQL queries, " <<
    "but executed #{@counter.query_count}: \n\n" <<
    @counter.queries.map {|q| " - #{q}" }.join("\n") << "\n\n" <<
    "Total queries: #{@counter.query_count}"
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



24
25
26
# File 'lib/query_matchers/query_execution_matcher.rb', line 24

def failure_message_when_negated
  "expected block not to execute #{@expected} SQL queries, but did"
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/query_matchers/query_execution_matcher.rb', line 11

def matches?(target)
  @counter.execute!(target)

  @counter.query_count == @expected
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/query_matchers/query_execution_matcher.rb', line 32

def supports_block_expectations?
  true
end