I am creating a REST API in rails. I’m using RSpec. I’d like to minimize the number of database calls, so I would like to add an automatic test that verifies the number of database calls being executed as part of a certain action.
Is there a simple way to add that to my test?
What I’m looking for is some way to monitor/record the calls that are being made to the database as a result of a single API call.
If this can’t be done with RSpec but can be done with some other testing tool, that’s also great.
I am creating a REST API in rails. I’m using RSpec. I’d like to
Share
The easiest thing in Rails 3 is probably to hook into the notifications api.
This subscriber
will print every executed sql statement to the console and count them. You could then write specs such as
You’ll probably want to filter out some statements, such as ones starting/committing transactions or the ones active record emits to determine the structures of tables.