Sha256: b870a50eca57101d6a609f779bf4953ab8da66c2f9304d903fbd063172efb55d

Contents?: true

Size: 756 Bytes

Versions: 25

Compression:

Stored size: 756 Bytes

Contents

# frozen_string_literal: true
# encoding: utf-8

module Mongoid
  module Expectations

    def connection_class
      if defined?(Mongo::Server::ConnectionBase)
        Mongo::Server::ConnectionBase
      else
        # Pre-2.8 drivers
        Mongo::Server::Connection
      end
    end

    def expect_query(number)
      rv = nil
      RSpec::Mocks.with_temporary_scope do
        if number > 0
          expect_any_instance_of(connection_class).to receive(:command_started).exactly(number).times.and_call_original
        else
          expect_any_instance_of(connection_class).not_to receive(:command_started)
        end
        rv = yield
      end
      rv
    end

    def expect_no_queries(&block)
      expect_query(0, &block)
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
mongoid-7.3.5 spec/support/expectations.rb
mongoid-7.3.4 spec/support/expectations.rb
mongoid-7.1.11 spec/support/expectations.rb
mongoid-7.2.6 spec/support/expectations.rb
mongoid-7.3.3 spec/support/expectations.rb
mongoid-7.3.2 spec/support/expectations.rb
mongoid-7.2.5 spec/support/expectations.rb
mongoid-7.1.10 spec/support/expectations.rb
mongoid-7.1.9 spec/support/expectations.rb
mongoid-7.2.4 spec/support/expectations.rb
mongoid-7.3.1 spec/support/expectations.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/spec/support/expectations.rb
mongoid-7.3.0 spec/support/expectations.rb
mongoid-7.2.3 spec/support/expectations.rb
mongoid-7.1.8 spec/support/expectations.rb
mongoid-7.2.2 spec/support/expectations.rb
mongoid-7.2.1 spec/support/expectations.rb
mongoid-7.1.7 spec/support/expectations.rb
mongoid-7.2.0 spec/support/expectations.rb
mongoid-7.1.6 spec/support/expectations.rb