Sha256: 4ba317bb2d1dc478f2d2a22b41d848d75b2496c375ca3ad76d7d23c8ed9fbcdc

Contents?: true

Size: 769 Bytes

Versions: 1

Compression:

Stored size: 769 Bytes

Contents

# frozen_string_literal: true

RSpec::Matchers.define :match_query do |regexp|
  match(notify_expectation_failures: true) do |block|
    include RSpec::SqlMatcher::Helpers
    @queries = collect_queries(&block).map do |data|
      query = data[:sql].dup
      data[:binds].each_with_index { |bind, index| query.gsub!("\$#{index + 1}", bind.value.inspect) }
      query
    end

    @queries.any? { |query| regexp =~ query }
  end

  supports_block_expectations

  failure_message do |_|
    "Expected { } to match query with #{regexp}, but it didn't. Current queries where:\n#{@queries.join("\n")}:"
  end

  failure_message_when_negated do |_|
    "Expected { } not to match query with #{regexp}, but it did. Current queries where:\n#{@queries.join("\n")}:"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec_sql_matcher-0.1.0 lib/rspec/sql_matcher/match_query.rb