Sha256: ef5f0dd96c05966055b67e046c4e5c42a749d8c6abcdf5d7467fa106a9d2f28e

Contents?: true

Size: 934 Bytes

Versions: 3

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

require "rspec/matchers"

module WtActiverecordIndexSpy
  # This module defines the helper have_used_db_indexes to use in RSpec tests
  module TestHelpers
    extend RSpec::Matchers::DSL

    matcher :have_used_db_indexes do |only_certains: false|
      match do |actual|
        WtActiverecordIndexSpy.watch_queries(ignore_queries_originated_in_test_code: false) do
          actual.call
        end

        if only_certains
          WtActiverecordIndexSpy.certain_results.empty?
        else
          WtActiverecordIndexSpy.results.empty?
        end
      end

      failure_message do |_actual|
        "Some queries have not used indexes: #{WtActiverecordIndexSpy.results.to_h}"
      end

      failure_message_when_negated do |_actual|
        "All queries have used indexes and this was not expected"
      end

      def supports_block_expectations?
        true
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wt_activerecord_index_spy-0.4.1 lib/wt_activerecord_index_spy/test_helpers.rb
wt_activerecord_index_spy-0.4.0 lib/wt_activerecord_index_spy/test_helpers.rb
wt_activerecord_index_spy-0.3.0 lib/wt_activerecord_index_spy/test_helpers.rb