Module: Minitest::Assertions

Defined in:
lib/sequel/rails/minitest.rb

Instance Method Summary collapse

Instance Method Details

#assert_no_queries(&block) ⇒ Object



20
21
22
# File 'lib/sequel/rails/minitest.rb', line 20

def assert_no_queries(&block)
  assert_num_queries(0, &block)
end

#assert_num_queries(num, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sequel/rails/minitest.rb', line 3

def assert_num_queries(num, &block)
  before = ::Sequel::Rails::Railties::LogSubscriber.count
  res = yield
  after = ::Sequel::Rails::Railties::LogSubscriber.count

  case num
  when Range
    assert num.include?(after - before), "The number of database queries did not match expectations...\nExpected: #{num} (range)\n  Actual: #{after - before}"
  when Integer
    assert num == after - before, "The number of database queries did not match expectations...\nExpected: #{num}\n  Actual: #{after - before}"
  else
    raise ArgumentError, "Invalid argument passed to assert_num_queries: expected a Range or Integer value, but received #{num.inspect} instead."
  end

  res
end