Sha256: e40e90f2dce06398d6e5a85ca693d31e778d95966dea6683f14dc614ea4805df

Contents?: true

Size: 556 Bytes

Versions: 5

Compression:

Stored size: 556 Bytes

Contents

# Derived from http://stackoverflow.com/a/13423584/153896. Updated for RSpec 3.
RSpec::Matchers.define :exceed_query_limit do |expected|
  supports_block_expectations

  match do |block|
    query_count(&block) > expected
  end

  failure_message_when_negated do |actual|
    "Expected to run maximum #{expected} queries, got #{@counter.query_count}"
  end

  def query_count(&block)
    @counter = ActiveRecord::QueryCounter.new
    ActiveSupport::Notifications.subscribed(@counter.to_proc, 'sql.active_record', &block)
    @counter.query_count
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
closure_tree-6.6.0 spec/support/exceed_query_limit.rb
closure_tree-6.5.0 spec/support/exceed_query_limit.rb
closure_tree-6.4.0 spec/support/exceed_query_limit.rb
closure_tree-6.3.0 spec/support/exceed_query_limit.rb
closure_tree-6.2.0 spec/support/exceed_query_limit.rb