Sha256: 51cc03e0492131fddd2680cf3b371521fb8ff0a54ca33735e468d35895a12530

Contents?: true

Size: 538 Bytes

Versions: 13

Compression:

Stored size: 538 Bytes

Contents

RSpec::Matchers.define :perform_queries do |expected|
  match do |block|
    query_count(&block) == expected
  end

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

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

    @counter.query_count
  end

  def supports_block_expectations?
    true
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
ledermann-rails-settings-2.5.0 spec/support/matchers/perform_queries.rb
rails-properties-3.4.3 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.4.3 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.4.2 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.4.1 spec/support/matchers/perform_queries.rb
unread-0.7.0 spec/support/matchers/perform_queries.rb
unread-0.6.3 spec/support/matchers/perform_queries.rb
unread-0.6.2 spec/support/matchers/perform_queries.rb
unread-0.6.1 spec/support/matchers/perform_queries.rb
unread-0.6.0 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.4.0 spec/support/matchers/perform_queries.rb
unread-0.5.0 spec/support/matchers/perform_queries.rb
unread-0.4.0 spec/support/matchers/perform_queries.rb