method

assert_queries_match

assert_queries_match(match, count: nil, include_schema: false, &block)
public

Asserts that the SQL queries executed in the given block match expected pattern.

# Check for exact number of queries
assert_queries_match(/LIMIT \?/, count: 1) { Post.first }

# Check for any number of queries
assert_queries_match(/LIMIT \?/) { Post.first }

If the :include_schema option is provided, any queries (including schema related) that match the matcher are considered.

assert_queries_match(/FROM pg_attribute/i, include_schema: true) { Post.columns }