Sha256: 722b12da07603707bb3f4309a1ef8555b32e5fbd3cd903afa7a104322aeabb33

Contents?: true

Size: 652 Bytes

Versions: 20

Compression:

Stored size: 652 Bytes

Contents

class QueryCountMatcher
  def initialize(num)
    @expected_count = num
  end

  def matches?(block)
    run(block)

    if @expected_count.respond_to? :include?
      @expected_count.include? @count
    else
      @count == @expected_count
    end
  end

  def run(block)
    $query_count = 0
    $query_sql = []
    block.call
  ensure
    @queries = $query_sql.dup
    @count = $query_count
  end

  def performed_queries
    @queries
  end

  def failure_message
    "expected #{@expected_count} queries, got #{@count}\n#{@queries.join("\n")}"
  end

  def negative_failure_message
    "expected query count not to be #{@expected_count}"
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
will_paginate-3.3.1 spec/matchers/query_count_matcher.rb
will_paginate-3.3.0 spec/matchers/query_count_matcher.rb
will_paginate-3.2.1 spec/matchers/query_count_matcher.rb
will_paginate-3.2.0 spec/matchers/query_count_matcher.rb
will_paginate-3.1.8 spec/matchers/query_count_matcher.rb
will_paginate-3.1.7 spec/matchers/query_count_matcher.rb
will_paginate-3.1.6 spec/matchers/query_count_matcher.rb
will_paginate-3.0.12 spec/matchers/query_count_matcher.rb
will_paginate-3.1.5 spec/matchers/query_count_matcher.rb
will_paginate-3.0.11 spec/matchers/query_count_matcher.rb
will_paginate-3.1.3 spec/matchers/query_count_matcher.rb
will_paginate-3.0.10 spec/matchers/query_count_matcher.rb
will_paginate-3.0.9 spec/matchers/query_count_matcher.rb
will_paginate-3.1.2 spec/matchers/query_count_matcher.rb
will_paginate-3.1.1 spec/matchers/query_count_matcher.rb
will_paginate-3.0.8 spec/matchers/query_count_matcher.rb
will_paginate-3.1.0 spec/matchers/query_count_matcher.rb
will_paginate_seo-3.0.4 spec/matchers/query_count_matcher.rb
will_paginate-3.0.7 spec/matchers/query_count_matcher.rb
will_paginate-3.0.6 spec/matchers/query_count_matcher.rb