Updated

spec/support / exceed_query_limit.rb

A
19 lines of codes
1 methods
6.5 complexity/method
1 churn
6.51 complexity
0 duplications
# From: https://gist.github.com/rsutphin/af06c9e3dadf658d2293 # 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