File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
- # rubocop:todo all
3
2
4
3
module Mongoid
5
4
module Expectations
6
5
def expect_query ( number )
7
6
if %i[ sharded load-balanced ] . include? ( ClusterConfig . instance . topology ) && number > 0
8
7
skip 'This spec requires replica set or standalone topology'
9
8
end
10
- rv = nil
9
+
11
10
RSpec ::Mocks . with_temporary_scope do
11
+ klass = Mongo ::Server ::ConnectionBase
12
+
12
13
if number > 0
13
- expect_any_instance_of ( Mongo ::Server ::ConnectionBase ) . to receive ( :command_started ) . exactly ( number ) . times . and_call_original
14
+ # Due to changes in Ruby 3.3, RSpec's #and_call_original (which wraps the target
15
+ # method) causes infinite recursion. We can achieve the same behavior with #bind.
16
+ original_method = klass . instance_method ( :command_started )
17
+ expect_any_instance_of ( klass ) . to receive ( :command_started ) . exactly ( number ) . times do |*args , **kwargs |
18
+ instance = args . shift
19
+ original_method . bind ( instance ) . call ( *args , **kwargs )
20
+ end
14
21
else
15
- expect_any_instance_of ( Mongo :: Server :: ConnectionBase ) . not_to receive ( :command_started )
22
+ expect_any_instance_of ( klass ) . not_to receive ( :command_started )
16
23
end
17
- rv = yield
24
+
25
+ yield
18
26
end
19
- rv
20
27
end
21
28
22
29
def expect_no_queries ( &block )
You can’t perform that action at this time.
0 commit comments