All Projects → civiccc → Db Query Matchers

civiccc / Db Query Matchers

Licence: other
RSpec matchers for database queries

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Db Query Matchers

Crud
Build custom admin panels. Fast!
Stars: ✭ 2,144 (+993.88%)
Mutual labels:  backend
Sifrr
⚡️ Set of tiny, independent libraries for creating modern and fast webapps with javascript/typescript
Stars: ✭ 174 (-11.22%)
Mutual labels:  backend
Kotlin Multiplatform Template
Kotlin Multiplatform Template
Stars: ✭ 185 (-5.61%)
Mutual labels:  backend
Devmap
Карта развития веб-разработчика
Stars: ✭ 2,043 (+942.35%)
Mutual labels:  backend
Tus Ruby Server
Ruby server for tus resumable upload protocol
Stars: ✭ 172 (-12.24%)
Mutual labels:  backend
Software Engineer Interview Questions
A lot of questions and links to prepare yourself for an interview.
Stars: ✭ 176 (-10.2%)
Mutual labels:  backend
Olympus
An instant REST API for any AI model 🔥
Stars: ✭ 151 (-22.96%)
Mutual labels:  backend
Core
AdminArchitect - Active Admin for Laravel
Stars: ✭ 194 (-1.02%)
Mutual labels:  backend
Csgofloat Inspect
Source Code that Powers the CSGOFloat Inspect Link API
Stars: ✭ 172 (-12.24%)
Mutual labels:  backend
Mage2vuestorefront
Magento to Vue-storefront datapump - synchronizes Products, Categories and Product-to-category links between your Magento2 API and NoSQL database of vue-storefront
Stars: ✭ 183 (-6.63%)
Mutual labels:  backend
Express Graphql Typescript Boilerplate
A starter kit for building amazing GraphQL API's with TypeScript and express by @w3tecch
Stars: ✭ 163 (-16.84%)
Mutual labels:  backend
Trust Ray
☁️ API for the Trust Wallet. Project no longer supported and current version used as source of transactions and address tokens in Blockatlas https://github.com/trustwallet/blockatlas/blob/master/config.yml#L64
Stars: ✭ 172 (-12.24%)
Mutual labels:  backend
Stackoverflow Clone
Clone project of a famous Q/A website for developers which is stackoverflow built using MySQL-Express-React-Node 🌐
Stars: ✭ 182 (-7.14%)
Mutual labels:  backend
Crana
A CLI tool to create React + Node apps with just one command
Stars: ✭ 160 (-18.37%)
Mutual labels:  backend
Backend Interview Questions
Hiring is extremely hard, and figuring out if someone is a good fit within 45 minutes is a demanding task. Here are some simple questions to interview potential backend candidates.
Stars: ✭ 189 (-3.57%)
Mutual labels:  backend
Awesome Web You Should Know
🌎awesome web you should know
Stars: ✭ 154 (-21.43%)
Mutual labels:  backend
Lumber
Install Forest Admin in minutes.
Stars: ✭ 2,077 (+959.69%)
Mutual labels:  backend
Yii2 Angular Boilerplate
Yii2 REST API + Angular10 Boilerplate (Frontend/Backend)
Stars: ✭ 194 (-1.02%)
Mutual labels:  backend
Interviewguide
《大厂面试指北》——包括Java基础、JVM、数据库、mysql、redis、计算机网络、算法、数据结构、操作系统、设计模式、系统设计、框架原理。最佳阅读地址:http://notfound9.github.io/interviewGuide/
Stars: ✭ 3,117 (+1490.31%)
Mutual labels:  backend
Justchat
A chat application built with Django channels.
Stars: ✭ 183 (-6.63%)
Mutual labels:  backend

db-query-matchers

Gem Version Build Status Code Climate Dependency Status

RSpec matchers for database queries made by ActiveRecord.

Installation

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

gem 'db-query-matchers'

And then execute:

bundle

Or install it yourself as:

gem install db-query-matchers

Usage

describe 'MyCode' do
  context 'when we expect no queries' do
    it 'does not make database queries' do
      expect { subject.make_no_queries }.to_not make_database_queries
    end
  end

  context 'when we expect queries' do
    it 'makes database queries' do
      expect { subject.make_some_queries }.to make_database_queries
    end
  end

  context 'when we expect exactly 1 query' do
    it 'makes database queries' do
      expect { subject.make_one_query }.to make_database_queries(count: 1)
    end
  end

  context 'when we expect max 3 queries' do
    it 'makes database queries' do
      expect { subject.make_several_queries }.to make_database_queries(count: 0..3)
    end
  end

  context 'when we expect a possible range of queries' do
    it 'makes database queries' do
      expect { subject.make_several_queries }.to make_database_queries(count: 3..5)
    end
  end

  context 'when we only care about manipulative queries (INSERT, UPDATE, DELETE)' do
    it 'makes a destructive database query' do
      expect { subject.make_one_query }.to make_database_queries(manipulative: true)
    end
  end

  context 'when we only care about unscoped queries (SELECT without a WHERE or LIMIT clause))' do
    it 'makes an unscoped database query' do
      expect { subject.make_one_query }.to make_database_queries(unscoped: true)
    end
  end

  context 'when we only care about queries matching a certain pattern' do
    it 'makes a destructive database query' do
      expect { subject.make_special_queries }.to make_database_queries(matching: 'DELETE * FROM')
    end

    it 'makes a destructive database query matched with a regexp' do
      expect { subject.make_special_queries }.to make_database_queries(matching: /DELETE/)
    end
  end
end

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 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.

DBQueryMatchers.configure do |config|
  config.ignores = [/SHOW TABLES LIKE/]
  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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].