Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ buildvariants:
driver: ["current"]
topology: '*'
mongodb-version: ['6.0']
os: debian11
os: ubuntu-22.04
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
tasks:
- name: "test"
Expand All @@ -646,7 +646,7 @@ buildvariants:
driver: ["current"]
topology: '*'
mongodb-version: ['latest']
os: debian11
os: ubuntu-22.04
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
tasks:
- name: "test"
Expand Down Expand Up @@ -690,7 +690,7 @@ buildvariants:
ruby: ["ruby-3.2"]
mongodb-version: "6.0"
topology: ['replica-set', 'sharded-cluster']
os: debian11
os: ubuntu-22.04
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
tasks:
- name: "test"
Expand Down
6 changes: 3 additions & 3 deletions .evergreen/config/variants.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildvariants:
driver: ["current"]
topology: '*'
mongodb-version: ['6.0']
os: debian11
os: ubuntu-22.04
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
tasks:
- name: "test"
Expand All @@ -16,7 +16,7 @@ buildvariants:
driver: ["current"]
topology: '*'
mongodb-version: ['latest']
os: debian11
os: ubuntu-22.04
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
tasks:
- name: "test"
Expand Down Expand Up @@ -60,7 +60,7 @@ buildvariants:
ruby: ["ruby-3.2"]
mongodb-version: "6.0"
topology: ['replica-set', 'sharded-cluster']
os: debian11
os: ubuntu-22.04
display_name: "${ruby}, ${driver}, ${mongodb-version}, ${topology}"
tasks:
- name: "test"
Expand Down
37 changes: 20 additions & 17 deletions spec/support/expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,30 @@

module Mongoid
module Expectations

def connection_class
if defined?(Mongo::Server::ConnectionBase)
Mongo::Server::ConnectionBase
else
# Pre-2.8 drivers
Mongo::Server::Connection
# Previously this method used RSpec::Mocks with .exactly.times(n).and_call_original,
# which stopped working reliably in Ruby 3.3. Now we directly wrap the target method.
def expect_query(number)
if %i[ sharded load-balanced ].include?(ClusterConfig.instance.topology) && number > 0
skip 'This spec requires replica set or standalone topology'
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)
klass = Mongo::Server::ConnectionBase
original_method = klass.instance_method(:command_started)
query_count = 0

begin
klass.define_method(:command_started) do |*args, **kwargs|
query_count += 1
original_method.bind_call(self, *args, **kwargs)
end
rv = yield

result = yield
expect(query_count).to eq(number)
result
ensure
klass.remove_method(:command_started)
klass.define_method(:command_started, original_method)
end
rv
end

def expect_no_queries(&block)
Expand Down
Loading