Module: RSpec::SqlMatcher::HaveRunQueries

Defined in:
lib/rspec/sql_matcher/have_run_queries.rb

Class Method Summary collapse

Class Method Details

.evaluate_expectation(count, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/rspec/sql_matcher/have_run_queries.rb', line 6

def self.evaluate_expectation(count, options = {})
  condition = true
  condition &&= count >= options[:min] if options[:min]
  condition &&= count <= options[:max] if options[:max]
  condition &&= count == options[:exactly] if options[:exactly]

  condition
end

.failure_message(count, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rspec/sql_matcher/have_run_queries.rb', line 15

def self.failure_message(count, options = {})
  return "Expected { } to run #{options[:exactly]} queries, but there were #{count} instead." if options[:exactly]

  if options[:min] && options[:max]
    return "Expected { } to run a number of query between #{options[:min]} and #{options[:max]}, but there were #{count} instead."
  end

  if options[:min]
    return "Expected { } to run at least #{options[:min]} queries, but there were #{count} instead."
  end

  return "Expected { } to run at most #{options[:max]} queries, but there were #{count} instead." if options[:max]

  'Invalid expectation parameters. Please pass min, max or exactly.'
end

.failure_message_when_negated(_count, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rspec/sql_matcher/have_run_queries.rb', line 31

def self.failure_message_when_negated(_count, options = {})
  return "Expected { } not to execute #{options[:exactly]} queries, but it did." if options[:exactly]
  if options[:min] && options[:max]
    return "Expected { } not to run a number of query between #{options[:min]} and #{options[:max]}, but it did."
  end
  return "Expected { } not to run at least #{options[:min]} queries, but it did." if options[:min]

  return "Expected { } not to run at most #{options[:max]} queries, but it did." if options[:max]

  'Invalid expectation parameters. Please pass min, max or exactly.'
end