No release in over 3 years
Provides RSpec matchers that verify whether ActiveRecord queries or code blocks use specific database indexes by examining execution plans. Supports SQLite and PostgreSQL.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 1.0
~> 3.0
>= 2.1

Runtime

 Project Readme

RSpec Index Usage

RSpec matchers that check database index usage in ActiveRecord queries and code blocks.

Requirements

  • Ruby >= 2.7
  • ActiveRecord >= 6.0 (supports SQLite and PostgreSQL)

Installation

Add this line to your application's Gemfile:

gem 'rspec-index-usage'

And then execute:

$ bundle install

This will install the gem along with its runtime dependency on ActiveRecord >= 6.0.

Or install it yourself as:

$ gem install rspec-index-usage

Usage

Add to your Gemfile:

gem 'rspec-index-usage'

Then in your specs:

require 'rspec-index-usage'

# In your specs
# Using a query
expect(User.where(email: 'test@example.com')).to use_index('index_users_on_email')

# Using a block
expect { User.where(email: 'test@example.com').first }.to have_used_index('index_users_on_email')

# Using a block but specifying one particular database connection
# This is only needed when you have more than one database setup
expect { User.where(email: 'test@example.com').first }.to have_used_index('index_users_on_email').on_connection(OtherDb.connection)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/PedroSena/rspec-index-usage.

License

The gem is available as open source under the terms of the MIT License.