Sha256: 224bd0a99272c1fe98d58d7d8629cce10bdeec8ed799828937be4a4a9454f428

Contents?: true

Size: 498 Bytes

Versions: 8

Compression:

Stored size: 498 Bytes

Contents

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

  failure_message_for_should 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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ledermann-rails-settings-2.3.0 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.2.1 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.2.0 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.1.0 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.0.3 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.0.2 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.0.1 spec/support/matchers/perform_queries.rb
ledermann-rails-settings-2.0.0 spec/support/matchers/perform_queries.rb