Skip to content

Commit e5301d3

Browse files
comandeo-mongojohnnyshieldsjamiscomandeo
authored
Fix CI (#5990)
Co-authored-by: Johnny Shields <27655+johnnyshields@users.noreply.github.com> Co-authored-by: Jamis Buck <jamis.buck@mongodb.com> Co-authored-by: Dmitry Rybakov <dmitry@rybakov.eu>
1 parent a6c4478 commit e5301d3

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

gemfiles/standard.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ def standard_dependencies
4949
end
5050

5151
if ENV['FLE'] == 'helper'
52-
gem 'libmongocrypt-helper', '~> 1.8.0'
52+
gem 'libmongocrypt-helper', '~> 1.14.0'
5353
end
5454
end

spec/support/expectations.rb

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
module Mongoid
54
module Expectations
6-
7-
def connection_class
8-
if defined?(Mongo::Server::ConnectionBase)
9-
Mongo::Server::ConnectionBase
10-
else
11-
# Pre-2.8 drivers
12-
Mongo::Server::Connection
5+
# Previously this method used RSpec::Mocks with .exactly.times(n).and_call_original,
6+
# which stopped working reliably in Ruby 3.3. Now we directly wrap the target method.
7+
def expect_query(number)
8+
if %i[ sharded load-balanced ].include?(ClusterConfig.instance.topology) && number > 0
9+
skip 'This spec requires replica set or standalone topology'
1310
end
14-
end
1511

16-
def expect_query(number)
17-
rv = nil
18-
RSpec::Mocks.with_temporary_scope do
19-
if number > 0
20-
expect_any_instance_of(connection_class).to receive(:command_started).exactly(number).times.and_call_original
21-
else
22-
expect_any_instance_of(connection_class).not_to receive(:command_started)
12+
klass = Mongo::Server::ConnectionBase
13+
original_method = klass.instance_method(:command_started)
14+
query_count = 0
15+
16+
begin
17+
klass.define_method(:command_started) do |*args, **kwargs|
18+
query_count += 1
19+
original_method.bind_call(self, *args, **kwargs)
2320
end
24-
rv = yield
21+
22+
result = yield
23+
expect(query_count).to eq(number)
24+
result
25+
ensure
26+
klass.remove_method(:command_started)
27+
klass.define_method(:command_started, original_method)
2528
end
26-
rv
2729
end
2830

2931
def expect_no_queries(&block)

0 commit comments

Comments
 (0)