{"id":13521050,"url":"https://github.com/sds/db-query-matchers","last_synced_at":"2026-03-17T22:31:36.439Z","repository":{"id":15797672,"uuid":"18537075","full_name":"sds/db-query-matchers","owner":"sds","description":"RSpec matchers for database queries","archived":false,"fork":false,"pushed_at":"2024-11-13T05:52:07.000Z","size":114,"stargazers_count":313,"open_issues_count":1,"forks_count":46,"subscribers_count":54,"default_branch":"main","last_synced_at":"2025-05-11T15:15:20.660Z","etag":null,"topics":["backend"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sds.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-04-07T22:38:13.000Z","updated_at":"2025-04-11T07:01:26.000Z","dependencies_parsed_at":"2022-08-28T05:31:09.257Z","dependency_job_id":"1eb460d0-42b7-4ffd-922f-f7f662990593","html_url":"https://github.com/sds/db-query-matchers","commit_stats":null,"previous_names":["brigade/db-query-matchers","civiccc/db-query-matchers"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sds%2Fdb-query-matchers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sds%2Fdb-query-matchers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sds%2Fdb-query-matchers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sds%2Fdb-query-matchers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sds","download_url":"https://codeload.github.com/sds/db-query-matchers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101616,"owners_count":22014909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend"],"created_at":"2024-08-01T06:00:27.300Z","updated_at":"2025-12-18T03:46:56.202Z","avatar_url":"https://github.com/sds.png","language":"Ruby","funding_links":[],"categories":["Ruby","Matchers"],"sub_categories":[],"readme":"# db-query-matchers\n\n[![Gem Version](https://badge.fury.io/rb/db-query-matchers.svg)](https://badge.fury.io/rb/db-query-matchers)\n[![Build Status](https://github.com/civiccc/db-query-matchers/actions/workflows/ci.yaml/badge.svg)](https://github.com/civiccc/db-query-matchers/actions)\n\nRSpec matchers for database queries made by ActiveRecord.\n\n## Installation\n\nAdd this line to your application's Gemfile, preferably in your `test` group:\n\n```ruby\ngem 'db-query-matchers'\n```\n\nAnd then execute:\n\n```bash\nbundle\n```\n\nOr install it yourself as:\n\n```bash\ngem install db-query-matchers\n```\n\n## Usage\n\n```ruby\ndescribe 'MyCode' do\n  context 'when we expect no queries' do\n    it 'does not make database queries' do\n      expect { subject.make_no_queries }.to_not make_database_queries\n    end\n  end\n\n  context 'when we expect queries' do\n    it 'makes database queries' do\n      expect { subject.make_some_queries }.to make_database_queries\n    end\n  end\n\n  context 'when we expect exactly 1 query' do\n    it 'makes database queries' do\n      expect { subject.make_one_query }.to make_database_queries(count: 1)\n    end\n  end\n\n  context 'when we expect max 3 queries' do\n    it 'makes database queries' do\n      expect { subject.make_several_queries }.to make_database_queries(count: 0..3)\n    end\n  end\n\n  context 'when we expect a possible range of queries' do\n    it 'makes database queries' do\n      expect { subject.make_several_queries }.to make_database_queries(count: 3..5)\n    end\n  end\n\n  context 'when we only care about manipulative queries (INSERT, UPDATE, DELETE)' do\n    it 'makes a destructive database query' do\n      expect { subject.make_one_query }.to make_database_queries(manipulative: true)\n    end\n  end\n\n  context 'when we only care about unscoped queries (SELECT without a WHERE or LIMIT clause))' do\n    it 'makes an unscoped database query' do\n      expect { subject.make_one_query }.to make_database_queries(unscoped: true)\n    end\n  end\n\n  context 'when we only care about queries matching a certain pattern' do\n    it 'makes a destructive database query' do\n      expect { subject.make_special_queries }.to make_database_queries(matching: 'DELETE * FROM')\n    end\n\n    it 'makes a destructive database query matched with a regexp' do\n      expect { subject.make_special_queries }.to make_database_queries(matching: /DELETE/)\n    end\n  end\nend\n```\n\n## Configuration\n\nTo exclude certain types of queries from being counted, specify an\n`ignores` configuration consisting of an array of regular expressions. If\na query matches one of the patterns in this array, it will not be\ncounted in the `make_database_queries` matcher.\n\nTo exclude queries previously cached by ActiveRecord from being counted,\nadd `ignore_cached` to the configuration.\n\nTo exclude SCHEMA queries, add `schemaless` to the configuration. This will\nhelp avoid failing specs due to ActiveRecord load order.\n\nTo log more about the queries being made, you can set the `log_backtrace`\noption to `true`. And to control what parts of the backtrace is logged,\nyou can use `backtrace_filter`.\n\n```ruby\nDBQueryMatchers.configure do |config|\n  config.ignores = [/SHOW TABLES LIKE/]\n  config.ignore_cached = true\n  config.schemaless = true\n\n  # the payload argument is described here:\n  # http://edgeguides.rubyonrails.org/active_support_instrumentation.html#sql-active-record\n  config.on_query_counted do |payload|\n    # do something arbitrary with the query\n  end\n\n  config.log_backtrace = true\n  config.backtrace_filter = Proc.new do |backtrace|\n    backtrace.select { |line| line.start_with?(Rails.root.to_s) }\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsds%2Fdb-query-matchers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsds%2Fdb-query-matchers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsds%2Fdb-query-matchers/lists"}