Sha256: 703ea6425c859deb4ea0334302f795c67c1299f4d552b5569872feb665b3f7a5

Contents?: true

Size: 727 Bytes

Versions: 2

Compression:

Stored size: 727 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)
      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
        yield
      end
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-7.1.0 spec/support/expectations.rb
mongoid-7.1.0.rc0 spec/support/expectations.rb