Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add execute_queries matcher #2818

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hugopeixoto
Copy link

This matcher is analog to the query assertions available since rails 7.0.

#2817

This matcher is analog to the query assertions available since rails
7.0.
@hugopeixoto hugopeixoto force-pushed the feature/add-execute-queries-matcher branch from 4eb5a1e to 80372b7 Compare December 2, 2024 08:23
@hugopeixoto
Copy link
Author

There are a bunch of checks failing, but they don't seem related to this PR. For example:

+Finished in 0.00374 seconds (files took 2.32 seconds to load)
+1 example, 1 failure
+
+Failed examples:
+
+rspec ./spec/lib/fixture_set_blob.rb:4 # blob creates a blob from a sample file

@hugopeixoto
Copy link
Author

Maybe I could do match_unless_raises and delegate it to the query assertions instead of reimplementing it. This would be better because I wouldn't be duplicating the SQLCounter query.

Also, I'm missing docs. The matcher should at least be added to the readme, and I need to figure out how those work in rspec.

# expect { Post.first }.to execute_no_queries
# expect { Post.first }.to execute_no_queries.matching(/SELECT/)
# expect { Post.columns }.to execute_no_queries.including_schema
def execute_no_queries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be leaning towards expect { }.not_to execute_queries, but an obvious use for this is compound expectations (and/or).

@pirj
Copy link
Member

pirj commented Dec 3, 2024

added to the readme

Check the /features directory for examples.

delegate it to the query assertions instead of reimplementing it

That’s how we do it for most other matchers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants