Have you ever wondered how many simultaneous queries your application sends to the database? A hundred, a thousand, or perhaps a million? Whatever your answer, we should be aware of the influence that this number has on the performance of our programme. I would like to introduce to you the rspec-query-limit gem (you can find the source code on our github in the monterail/rspec-query-limit repository): this gem is a rspec matcher that measures the numbers of queries being sent to the database in Ruby on Rails applications. The main goal of this gem is to prevent the so-called N+1 problem from occurring, and to make us realize how many different queries are subsequently being sent to the database. Rspec query limit measures queries using Active Support Instrumentation which allows us to measure certain actions in Rails.

You can use this gem wherever you wish in your tests - you can measure the number of queries in your controllers, services, use cases or models, or anywhere in your applications where you communicate with the database. I would like to show you an example use case that will hopefully be to your liking.

#rspec #ruby/rails #development

Rspec query limit matcher
1.90 GEEK