Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1k
Open
Description
Rails 7 added support for a few query assertions:
assert_queries_count(1){Post.first}assert_queries_count{Post.first}assert_queries_count(1,include_schema: true){Post.columns}assert_no_queries{post.comments}assert_no_queries(include_schema: true){Post.columns}assert_queries_match(/LIMIT \?/,count: 1){Post.first}assert_queries_match(/LIMIT \?/){Post.first}assert_queries_match(/FROM pg_attribute/i,include_schema: true){Post.columns}assert_no_queries_match(/SELECT/i){post.comments}assert_no_queries_match(/FROM pg_attribute/i,include_schema: true){Post.columns}Does an equivalent matcher belong in rspec-rails?
I've found these rails assertions useful to ensure performance issues (like N+1 queries) don't appear and to make regression tests for when they do.
In projects that use rspec-rails, a matcher that allows to test for the number of queries executed would be helpful.
I have implemented a custom matcher that supports a subset of these:
expect{Post.first}.toexecute_queries(1)expect{Post.first}.toexecute_no_queriesThese could be expanded to support matching, no count, and include_schema:
expect{Post.first}.toexecute_queriesexpect{Post.first}.toexecute_queries(1).matching(/LIMIT \?/)expect{Post.first}.toexecute_no_queries.including_schemaI'm working on making a PR to rspec-rails to support these, opening an issue now to iterate on the syntax and to check if it belongs here.
artur and benoittgt
Metadata
Metadata
Assignees
Labels
No labels