百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

db-query-matchers

> 后端框架
开源

用于数据库查询的 RSpec 匹配器

319 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

用于数据库查询的 RSpec 匹配器

db-query-matchers

RSpec matchers for database queries made by ActiveRecord.

Installation

Add this line to your application's Gemfile, preferably in your test group:

ruby
gem 'db-query-matchers'

And then execute:

bash
bundle

Or install it yourself as:

bash
gem install db-query-matchers

Usage

…

Configuration

To exclude certain types of queries from being counted, specify an ignores configuration consisting of an array of regular expressions. If a query matches one of the patterns in this array, it will not be counted in the make_database_queries matcher.

To exclude queries previously cached by ActiveRecord from being counted, add ignore_cached to the configuration.

To exclude SCHEMA queries, add schemaless to the configuration. This will help avoid failing specs due to ActiveRecord load order.

To log more about the queries being made, you can set the log_backtrace option to true. And to control what parts of the backtrace is logged, you can use backtrace_filter.

ruby
DBQueryMatchers.configure do |config|
  config.ignores = [/SHOW TABLES LIKE/]
  config.ignore_cached = true
  config.schemaless = true

  # the payload argument is described here:
  # http://edgeguides.rubyonrails.org/active_support_instrumentation.html#sql-active-record
  config.on_query_counted do |payload|
    # do something arbitrary with the query
  end

  config.log_backtrace = true
  config.backtrace_filter = Proc.new do |backtrace|
    backtrace.select { |line| line.start_with?(Rails.root.to_s) }
  end
end

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubybackend

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架