From ed1de556ff31d2395c6840cf38e6a560d457be22 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Thu, 9 Apr 2026 16:43:10 -0600 Subject: [PATCH 01/11] appease Layout/MultilineBlockLayout --- .rubocop_todo.yml | 6 ------ lib/mongo/crypt/handle.rb | 21 +++++++-------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index edf1abd0b4..142e452a70 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -Layout/MultilineBlockLayout: - Exclude: - - 'lib/mongo/crypt/handle.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). Layout/RescueEnsureAlignment: diff --git a/lib/mongo/crypt/handle.rb b/lib/mongo/crypt/handle.rb index 36c6f3eb74..67193b316a 100644 --- a/lib/mongo/crypt/handle.rb +++ b/lib/mongo/crypt/handle.rb @@ -288,8 +288,7 @@ def do_rsaes_pkcs_signature(key_binary_p, input_binary_p, # Every crypto binding ignores its first argument, which is an option # mongocrypt_ctx_t object and is not required to use crypto hooks. def set_crypto_hooks - @aes_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, - output_binary_p, response_length_p, status_p| + @aes_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p| do_aes( key_binary_p, iv_binary_p, @@ -300,8 +299,7 @@ def set_crypto_hooks ) end - @aes_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, - output_binary_p, response_length_p, status_p| + @aes_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p| do_aes( key_binary_p, iv_binary_p, @@ -319,13 +317,11 @@ def set_crypto_hooks end end - @hmac_sha_512 = proc do |_, key_binary_p, input_binary_p, - output_binary_p, status_p| + @hmac_sha_512 = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p| do_hmac_sha('SHA512', key_binary_p, input_binary_p, output_binary_p, status_p) end - @hmac_sha_256 = proc do |_, key_binary_p, input_binary_p, - output_binary_p, status_p| + @hmac_sha_256 = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p| do_hmac_sha('SHA256', key_binary_p, input_binary_p, output_binary_p, status_p) end @@ -347,8 +343,7 @@ def set_crypto_hooks @hmac_hash ) - @aes_ctr_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, - output_binary_p, response_length_p, status_p| + @aes_ctr_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p| do_aes( key_binary_p, iv_binary_p, @@ -360,8 +355,7 @@ def set_crypto_hooks ) end - @aes_ctr_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, - output_binary_p, response_length_p, status_p| + @aes_ctr_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p| do_aes( key_binary_p, iv_binary_p, @@ -380,8 +374,7 @@ def set_crypto_hooks @aes_ctr_decrypt ) - @rsaes_pkcs_signature_cb = proc do |_, key_binary_p, input_binary_p, - output_binary_p, status_p| + @rsaes_pkcs_signature_cb = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p| do_rsaes_pkcs_signature(key_binary_p, input_binary_p, output_binary_p, status_p) end From 55108e146d3c89a2646a2200e0925324097da691 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Thu, 9 Apr 2026 16:45:37 -0600 Subject: [PATCH 02/11] appease Layout/RescueEnsureAlignment --- .rubocop_todo.yml | 7 ------- spec/mongo/collection/view/change_stream_spec.rb | 4 +++- spec/mongo/collection/view/readable_spec.rb | 3 ++- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 142e452a70..84d577aee7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,13 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Layout/RescueEnsureAlignment: - Exclude: - - 'spec/mongo/collection/view/change_stream_spec.rb' - - 'spec/mongo/collection/view/readable_spec.rb' - # Offense count: 8 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: RequireParenthesesForMethodChains. diff --git a/spec/mongo/collection/view/change_stream_spec.rb b/spec/mongo/collection/view/change_stream_spec.rb index 5153efcc3e..0d4ac4a121 100644 --- a/spec/mongo/collection/view/change_stream_spec.rb +++ b/spec/mongo/collection/view/change_stream_spec.rb @@ -227,7 +227,9 @@ end let!(:operation_result) do - change_stream; rescue StandardError => e; e + change_stream + rescue StandardError => e + e end let(:session) do diff --git a/spec/mongo/collection/view/readable_spec.rb b/spec/mongo/collection/view/readable_spec.rb index e3ae8adea8..2c0a105d3e 100644 --- a/spec/mongo/collection/view/readable_spec.rb +++ b/spec/mongo/collection/view/readable_spec.rb @@ -366,7 +366,8 @@ end let(:operation) do - view.map_reduce(map, reduce).to_a; rescue StandardError + view.map_reduce(map, reduce).to_a + rescue StandardError end let(:command) do From e9db22eb90b2ff5b9a3d1f682e6979af4377d8c4 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Thu, 9 Apr 2026 16:52:24 -0600 Subject: [PATCH 03/11] appease Lint/AmbiguousRange --- .rubocop_todo.yml | 8 -------- spec/integration/sdam_events_spec.rb | 6 +++--- spec/mongo/server/description/features_spec.rb | 4 ++-- spec/runners/unified.rb | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 84d577aee7..6de5cbf28b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 8 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: RequireParenthesesForMethodChains. -Lint/AmbiguousRange: - Exclude: - - 'spec/integration/sdam_events_spec.rb' - - 'spec/mongo/server/description/features_spec.rb' - - 'spec/runners/unified.rb' # Offense count: 190 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/spec/integration/sdam_events_spec.rb b/spec/integration/sdam_events_spec.rb index 611604aeff..3d4b910a80 100644 --- a/spec/integration/sdam_events_spec.rb +++ b/spec/integration/sdam_events_spec.rb @@ -78,7 +78,7 @@ succeeded_events = subscriber.select_succeeded_events(Mongo::Monitoring::Event::ServerHeartbeatSucceeded) started_events.length.should - (succeeded_events.length..succeeded_events.length + 1).should include(started_events.length) + (succeeded_events.length..(succeeded_events.length + 1)).should include(started_events.length) end end @@ -128,9 +128,9 @@ # There may be in-flight hellos that don't complete, both # regular and awaited. started_awaited.length.should - (succeeded_awaited.length..succeeded_awaited.length + 1).should include(started_awaited.length) + (succeeded_awaited.length..(succeeded_awaited.length + 1)).should include(started_awaited.length) started_regular.length.should - (succeeded_regular.length..succeeded_regular.length + 1).should include(started_regular.length) + (succeeded_regular.length..(succeeded_regular.length + 1)).should include(started_regular.length) end end end diff --git a/spec/mongo/server/description/features_spec.rb b/spec/mongo/server/description/features_spec.rb index c4147d45d3..ff32656f52 100644 --- a/spec/mongo/server/description/features_spec.rb +++ b/spec/mongo/server/description/features_spec.rb @@ -20,7 +20,7 @@ context 'when the server wire version range min is higher' do let(:wire_versions) do - described_class::DRIVER_WIRE_VERSIONS.max + 1..described_class::DRIVER_WIRE_VERSIONS.max + 2 + (described_class::DRIVER_WIRE_VERSIONS.max + 1)..(described_class::DRIVER_WIRE_VERSIONS.max + 2) end it 'raises an exception' do @@ -62,7 +62,7 @@ context 'when the server wire version range max is lower' do let(:wire_versions) do - described_class::DRIVER_WIRE_VERSIONS.min - 2..described_class::DRIVER_WIRE_VERSIONS.min - 1 + (described_class::DRIVER_WIRE_VERSIONS.min - 2)..(described_class::DRIVER_WIRE_VERSIONS.min - 1) end it 'raises an exception' do diff --git a/spec/runners/unified.rb b/spec/runners/unified.rb index 0de8af62dd..7e1272426d 100644 --- a/spec/runners/unified.rb +++ b/spec/runners/unified.rb @@ -11,7 +11,7 @@ def define_unified_spec_tests(base_path, paths, expect_failure: false) config_override :validate_update_replace, true paths.each do |path| - basename = path[base_path.length + 1...path.length] + basename = path[(base_path.length + 1)...path.length] context basename do group = Unified::TestGroup.new(path) From 95d8540cb1c6ff67f6294b5dd857d006703bf992 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Thu, 9 Apr 2026 16:55:04 -0600 Subject: [PATCH 04/11] appease Lint/DuplicateMethods --- .rubocop_todo.yml | 6 ------ spec/runners/auth.rb | 2 +- spec/runners/cmap.rb | 2 -- spec/support/spec_config.rb | 2 +- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6de5cbf28b..f175fa8c35 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -42,12 +42,6 @@ Lint/DuplicateBranch: - 'spec/runners/sdam.rb' - 'spec/support/client_registry.rb' -# Offense count: 3 -Lint/DuplicateMethods: - Exclude: - - 'spec/runners/auth.rb' - - 'spec/runners/cmap.rb' - - 'spec/support/spec_config.rb' # Offense count: 8 # Configuration parameters: AllowComments, AllowEmptyLambdas. diff --git a/spec/runners/auth.rb b/spec/runners/auth.rb index b8ded94932..efbdf44e1e 100644 --- a/spec/runners/auth.rb +++ b/spec/runners/auth.rb @@ -42,7 +42,7 @@ module Mongo module Auth class Spec - attr_reader :description, :tests + attr_reader :description def initialize(test_path) @spec = ::Utils.load_spec_yaml_file(test_path) diff --git a/spec/runners/cmap.rb b/spec/runners/cmap.rb index 49080d0b1c..d53f927bc2 100644 --- a/spec/runners/cmap.rb +++ b/spec/runners/cmap.rb @@ -48,8 +48,6 @@ def initialize(test_path) process_run_on end - attr_reader :pool - def setup(server, client, subscriber) @subscriber = subscriber @client = client diff --git a/spec/support/spec_config.rb b/spec/support/spec_config.rb index 61ecbacd3d..21976eacd2 100644 --- a/spec/support/spec_config.rb +++ b/spec/support/spec_config.rb @@ -53,7 +53,7 @@ def initialize end end - attr_reader :uri_options, :ruby_options, :connect_options + attr_reader :uri_options, :ruby_options def addresses @addresses ||= if @mongodb_uri From 4a6d1fabaf453247b28ee4d7caa74343aa4c1ecd Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Thu, 9 Apr 2026 16:57:32 -0600 Subject: [PATCH 05/11] appease Lint/EmptyConditionalBody --- .rubocop_todo.yml | 7 ------- spec/runners/transactions.rb | 8 +------- spec/spec_tests/uri_options_spec.rb | 3 --- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f175fa8c35..59070a5573 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -54,13 +54,6 @@ Lint/EmptyBlock: - 'spec/mongo/server/round_trip_time_calculator_spec.rb' - 'spec/mongo/uri/srv_protocol_spec.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowComments. -Lint/EmptyConditionalBody: - Exclude: - - 'spec/runners/transactions.rb' - - 'spec/spec_tests/uri_options_spec.rb' # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/spec/runners/transactions.rb b/spec/runners/transactions.rb index d21fde15a6..7f7ea2d841 100644 --- a/spec/runners/transactions.rb +++ b/spec/runners/transactions.rb @@ -25,7 +25,7 @@ def define_transactions_spec_tests(test_paths, expectations_bson_types: true) spec = Mongo::Transactions::Spec.new(file) context(spec.description) do - define_spec_tests_with_requirements(spec) do |req| + define_spec_tests_with_requirements(spec) do |_req| spec.tests(expectations_bson_types: expectations_bson_types).each do |test| context(test.description) do before(:all) do @@ -45,12 +45,6 @@ def define_transactions_spec_tests(test_paths, expectations_bson_types: true) test.setup_test end - if test.skip_reason - end - - unless req.satisfied? - end - after(:all) do test.teardown_test end diff --git a/spec/spec_tests/uri_options_spec.rb b/spec/spec_tests/uri_options_spec.rb index 7bd768dc81..aac267bcc9 100644 --- a/spec/spec_tests/uri_options_spec.rb +++ b/spec/spec_tests/uri_options_spec.rb @@ -55,9 +55,6 @@ end end - if opts['compressors'] && opts['compressors'].include?('zstd') - end - it 'creates a client with the correct options' do mapped = Mongo::URI::OptionsMapper.new.ruby_to_smc(test.client.options) expected = Mongo::ConnectionString.adjust_expected_mongo_client_options( From 62d72babe263b4b911a1eddc917b2eda86cc2c57 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Fri, 10 Apr 2026 08:02:13 -0600 Subject: [PATCH 06/11] appease Lint/NoReturnInBeginEndBlocks --- .rubocop_todo.yml | 5 ----- lib/mongo/socket/ocsp_verifier.rb | 4 ++-- spec/runners/change_streams/test.rb | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 59070a5573..9da0d4d205 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -94,11 +94,6 @@ Lint/NextWithoutAccumulator: Exclude: - 'lib/mongo/operation/shared/result/aggregatable.rb' -# Offense count: 2 -Lint/NoReturnInBeginEndBlocks: - Exclude: - - 'lib/mongo/socket/ocsp_verifier.rb' - - 'spec/runners/change_streams/test.rb' # Offense count: 1 Lint/NonLocalExitFromIterator: diff --git a/lib/mongo/socket/ocsp_verifier.rb b/lib/mongo/socket/ocsp_verifier.rb index d7ac57ee56..68d80db633 100644 --- a/lib/mongo/socket/ocsp_verifier.rb +++ b/lib/mongo/socket/ocsp_verifier.rb @@ -167,9 +167,9 @@ def verify_one_responder(uri) redirect_count = 0 http_response = nil loop do - http_response = begin + begin uri = URI(uri) - Net::HTTP.start(uri.hostname, uri.port) do |http| + http_response = Net::HTTP.start(uri.hostname, uri.port) do |http| path = uri.path path = '/' if path.empty? http.post(path, @serialized_req, diff --git a/spec/runners/change_streams/test.rb b/spec/runners/change_streams/test.rb index f6dda2c578..2df3d70d8f 100644 --- a/spec/runners/change_streams/test.rb +++ b/spec/runners/change_streams/test.rb @@ -98,8 +98,8 @@ def teardown_test end def run - change_stream = begin - @target.watch(@pipeline, ::Utils.snakeize_hash(@options)) + begin + change_stream = @target.watch(@pipeline, ::Utils.snakeize_hash(@options)) rescue Mongo::Error::OperationFailure::Family => e return { result: { From e14c20a3e8269f847fa7bd4b91e161f584af8cd1 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Fri, 10 Apr 2026 08:17:05 -0600 Subject: [PATCH 07/11] appease Lint/ConstantDefinitionInBlock --- .rubocop_todo.yml | 10 ----- spec/integration/heartbeat_events_spec.rb | 4 +- spec/mongo/id_spec.rb | 48 ++++++++++++----------- spec/mongo/operation/result_spec.rb | 14 +++---- spec/mongo/server/connection_spec.rb | 4 +- spec/spec_tests/sdam_spec.rb | 26 ++++++------ 6 files changed, 48 insertions(+), 58 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9da0d4d205..49b20a620c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -13,16 +13,6 @@ Lint/AssignmentInCondition: Enabled: false -# Offense count: 10 -# Configuration parameters: AllowedMethods. -# AllowedMethods: enums -Lint/ConstantDefinitionInBlock: - Exclude: - - 'spec/integration/heartbeat_events_spec.rb' - - 'spec/mongo/id_spec.rb' - - 'spec/mongo/operation/result_spec.rb' - - 'spec/mongo/server/connection_spec.rb' - - 'spec/spec_tests/sdam_spec.rb' # Offense count: 16 # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch. diff --git a/spec/integration/heartbeat_events_spec.rb b/spec/integration/heartbeat_events_spec.rb index 15354495e3..97957348e9 100644 --- a/spec/integration/heartbeat_events_spec.rb +++ b/spec/integration/heartbeat_events_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' -describe 'Heartbeat events' do - class HeartbeatEventsSpecTestException < StandardError; end +class HeartbeatEventsSpecTestException < StandardError; end +describe 'Heartbeat events' do # 4.4 has two monitors and thus issues heartbeats multiple times max_server_version '4.2' diff --git a/spec/mongo/id_spec.rb b/spec/mongo/id_spec.rb index 4ffc2856c0..77cb44f33a 100644 --- a/spec/mongo/id_spec.rb +++ b/spec/mongo/id_spec.rb @@ -2,36 +2,38 @@ require 'lite_spec_helper' +module IdSpecHelpers + class IdA + include Mongo::Id + end + + class IdB + include Mongo::Id + end + + class IdC + include Mongo::Id + end + + class IdD + include Mongo::Id + end +end + describe Mongo::Id do it 'starts with ID 1' do - class IdA - include Mongo::Id - end - - expect(IdA.next_id).to eq(1) + expect(IdSpecHelpers::IdA.next_id).to eq(1) end it 'increases each subsequent ID' do - class IdB - include Mongo::Id - end - - expect(IdB.next_id).to eq(1) - expect(IdB.next_id).to eq(2) + expect(IdSpecHelpers::IdB.next_id).to eq(1) + expect(IdSpecHelpers::IdB.next_id).to eq(2) end it 'correctly generates independent IDs for separate classes' do - class IdC - include Mongo::Id - end - - class IdD - include Mongo::Id - end - - expect(IdC.next_id).to eq(1) - expect(IdD.next_id).to eq(1) - expect(IdC.next_id).to eq(2) - expect(IdD.next_id).to eq(2) + expect(IdSpecHelpers::IdC.next_id).to eq(1) + expect(IdSpecHelpers::IdD.next_id).to eq(1) + expect(IdSpecHelpers::IdC.next_id).to eq(2) + expect(IdSpecHelpers::IdD.next_id).to eq(2) end end diff --git a/spec/mongo/operation/result_spec.rb b/spec/mongo/operation/result_spec.rb index cbd9004d56..c868645cff 100644 --- a/spec/mongo/operation/result_spec.rb +++ b/spec/mongo/operation/result_spec.rb @@ -2,6 +2,12 @@ require 'spec_helper' +class Result + def get_result(client) + client.database.command(ping: 1) + end +end + describe Mongo::Operation::Result do let(:description) do Mongo::Server::Description.new( @@ -294,14 +300,6 @@ new_local_client(SpecConfig.instance.addresses, SpecConfig.instance.test_options) end - before do - class Result - def get_result(client) - client.database.command(ping: 1) - end - end - end - let(:result) do Result.new.get_result(client) end diff --git a/spec/mongo/server/connection_spec.rb b/spec/mongo/server/connection_spec.rb index c7d1980f60..fc6e6e4f40 100644 --- a/spec/mongo/server/connection_spec.rb +++ b/spec/mongo/server/connection_spec.rb @@ -2,10 +2,10 @@ require 'spec_helper' +class ConnectionSpecTestException < Exception; end + # fails intermittently in evergreen describe Mongo::Server::Connection do - class ConnectionSpecTestException < Exception; end - clean_slate_for_all let(:generation_manager) do diff --git a/spec/spec_tests/sdam_spec.rb b/spec/spec_tests/sdam_spec.rb index 510fa8e7ee..ea83c7dbee 100644 --- a/spec/spec_tests/sdam_spec.rb +++ b/spec/spec_tests/sdam_spec.rb @@ -5,24 +5,24 @@ require 'runners/sdam' require 'runners/sdam/verifier' -describe 'Server Discovery and Monitoring' do - include Mongo::SDAM +class SDAMSpecExecutor + include Mongo::Operation::Executable - class Executor - include Mongo::Operation::Executable - - def session - nil - end + def session + nil end +end + +describe 'Server Discovery and Monitoring' do + include Mongo::SDAM SERVER_DISCOVERY_TESTS.each do |file| spec = Mongo::SDAM::Spec.new(file) context("#{spec.description} (#{file.sub(%r{.*/data/sdam/}, '')})") do before(:all) do - class Mongo::Server::Monitor - alias run_saved! run! + Mongo::Server::Monitor.class_eval do + alias_method :run_saved!, :run! # Replace run! method to do nothing, to avoid races between # the background thread started by Server.new and our mocking. @@ -33,8 +33,8 @@ def run!; end end after(:all) do - class Mongo::Server::Monitor - alias run! run_saved! + Mongo::Server::Monitor.class_eval do + alias_method :run!, :run_saved! end @client && @client.close end @@ -56,7 +56,7 @@ def raise_application_error(error, connection = nil) when :command result = error.result allow(connection).to receive(:generation).and_return(error.generation) if error.generation - Executor.new.send(:process_result_for_sdam, result, connection) + SDAMSpecExecutor.new.send(:process_result_for_sdam, result, connection) else raise NotImplementedError, "Error type #{error.type} is not implemented" end From 6b26c0359351d6ab6ceaa295515d08ac50ceaccc Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Fri, 10 Apr 2026 08:25:52 -0600 Subject: [PATCH 08/11] appease Lint/EmptyBlock --- .rubocop_todo.yml | 10 ---------- spec/integration/cursor_memory_leak_spec.rb | 4 ++-- spec/mongo/auth/user_spec.rb | 3 +-- spec/mongo/cursor_spec.rb | 3 +-- spec/mongo/server/description_spec.rb | 3 --- spec/mongo/server/round_trip_time_calculator_spec.rb | 6 ++---- spec/mongo/uri/srv_protocol_spec.rb | 3 --- 7 files changed, 6 insertions(+), 26 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 49b20a620c..cd5f0ef1a8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -33,16 +33,6 @@ Lint/DuplicateBranch: - 'spec/support/client_registry.rb' -# Offense count: 8 -# Configuration parameters: AllowComments, AllowEmptyLambdas. -Lint/EmptyBlock: - Exclude: - - 'spec/integration/cursor_memory_leak_spec.rb' - - 'spec/mongo/auth/user_spec.rb' - - 'spec/mongo/cursor_spec.rb' - - 'spec/mongo/server/description_spec.rb' - - 'spec/mongo/server/round_trip_time_calculator_spec.rb' - - 'spec/mongo/uri/srv_protocol_spec.rb' # Offense count: 4 diff --git a/spec/integration/cursor_memory_leak_spec.rb b/spec/integration/cursor_memory_leak_spec.rb index 302ec2fc9d..f1b5b9d5fb 100644 --- a/spec/integration/cursor_memory_leak_spec.rb +++ b/spec/integration/cursor_memory_leak_spec.rb @@ -22,7 +22,7 @@ it 'does not leak Mongo::Client objects when batch_size < limit' do # Warm up: run once so any one-time initialization clients are created # before we start counting. - collection.find(nil, batch_size: 2, limit: 3).each {} + collection.find(nil, batch_size: 2, limit: 3).to_a GC.start GC.start @@ -32,7 +32,7 @@ client_count_before = ObjectSpace.each_object(Mongo::Client).count 10.times do - collection.find(nil, batch_size: 2, limit: 3).each {} + collection.find(nil, batch_size: 2, limit: 3).to_a end # Give the GC and the periodic cursor reaper time to process finalizers diff --git a/spec/mongo/auth/user_spec.rb b/spec/mongo/auth/user_spec.rb index 1dc50588bf..0fabd8e04b 100644 --- a/spec/mongo/auth/user_spec.rb +++ b/spec/mongo/auth/user_spec.rb @@ -129,8 +129,7 @@ end describe '#auth_key' do - let(:nonce) do - end + let(:nonce) { nil } let(:expected) do Digest::MD5.hexdigest("#{nonce}#{user.name}#{user.hashed_password}") diff --git a/spec/mongo/cursor_spec.rb b/spec/mongo/cursor_spec.rb index 168ab8cb02..a574f433e5 100644 --- a/spec/mongo/cursor_spec.rb +++ b/spec/mongo/cursor_spec.rb @@ -175,8 +175,7 @@ it 'raises the error' do expect do - cursor.each do |doc| - end + cursor.to_a end.to raise_error(Mongo::Error::SocketError) end end diff --git a/spec/mongo/server/description_spec.rb b/spec/mongo/server/description_spec.rb index 27786f640d..5362040c55 100644 --- a/spec/mongo/server/description_spec.rb +++ b/spec/mongo/server/description_spec.rb @@ -264,9 +264,6 @@ it 'normalizes the addresses to lowercase' do expect(description.passives).to eq([ 'server:27017' ]) end - - it 'normalizes the addresses to lowercase' do - end end end diff --git a/spec/mongo/server/round_trip_time_calculator_spec.rb b/spec/mongo/server/round_trip_time_calculator_spec.rb index 0deaf7951b..1c91a34d79 100644 --- a/spec/mongo/server/round_trip_time_calculator_spec.rb +++ b/spec/mongo/server/round_trip_time_calculator_spec.rb @@ -84,14 +84,12 @@ context 'block does not raise' do it 'updates average rtt' do expect(calculator).to receive(:update_average_round_trip_time) - calculator.measure do - end + calculator.measure { nil } end it 'updates minimum rtt' do expect(calculator).to receive(:update_minimum_round_trip_time) - calculator.measure do - end + calculator.measure { nil } end end diff --git a/spec/mongo/uri/srv_protocol_spec.rb b/spec/mongo/uri/srv_protocol_spec.rb index 98801c9d7e..ba8d7738bd 100644 --- a/spec/mongo/uri/srv_protocol_spec.rb +++ b/spec/mongo/uri/srv_protocol_spec.rb @@ -1190,9 +1190,6 @@ end describe '#validate_srv_hostname' do - let(:valid_hostname) do - end - let(:dummy_uri) do Mongo::URI::SRVProtocol.new('mongodb+srv://test1.test.build.10gen.cc/') end From d872d526c707a0733f16848e9555229f213621fa Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Fri, 10 Apr 2026 08:33:04 -0600 Subject: [PATCH 09/11] appease Lint/InheritException --- .rubocop_todo.yml | 9 --------- lib/mongo/error/raise_original_error.rb | 2 +- spec/mongo/server/connection_spec.rb | 2 +- spec/mongo/socket_spec.rb | 4 ++-- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cd5f0ef1a8..566930c4ed 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -49,15 +49,6 @@ Lint/IneffectiveAccessModifier: - 'lib/mongo/protocol/message.rb' - 'lib/mongo/uri/options_mapper.rb' -# Offense count: 4 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: standard_error, runtime_error -Lint/InheritException: - Exclude: - - 'lib/mongo/error/raise_original_error.rb' - - 'spec/mongo/server/connection_spec.rb' - - 'spec/mongo/socket_spec.rb' # Offense count: 31 # Configuration parameters: AllowedParentClasses. diff --git a/lib/mongo/error/raise_original_error.rb b/lib/mongo/error/raise_original_error.rb index 9a63383945..a05de9ce70 100644 --- a/lib/mongo/error/raise_original_error.rb +++ b/lib/mongo/error/raise_original_error.rb @@ -24,7 +24,7 @@ class Error # @note This class must not derive from Error. # # @api private - class RaiseOriginalError < Exception + class RaiseOriginalError < Exception # rubocop:disable Lint/InheritException end end end diff --git a/spec/mongo/server/connection_spec.rb b/spec/mongo/server/connection_spec.rb index fc6e6e4f40..85453ebd19 100644 --- a/spec/mongo/server/connection_spec.rb +++ b/spec/mongo/server/connection_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -class ConnectionSpecTestException < Exception; end +class ConnectionSpecTestException < StandardError; end # fails intermittently in evergreen describe Mongo::Server::Connection do diff --git a/spec/mongo/socket_spec.rb b/spec/mongo/socket_spec.rb index 2fa1c9fc55..a8fc946992 100644 --- a/spec/mongo/socket_spec.rb +++ b/spec/mongo/socket_spec.rb @@ -96,7 +96,7 @@ context 'with WaitReadable' do let(:exception_class) do - Class.new(Exception) do + Class.new(StandardError) do include IO::WaitReadable end end @@ -106,7 +106,7 @@ context 'with WaitWritable' do let(:exception_class) do - Class.new(Exception) do + Class.new(StandardError) do include IO::WaitWritable end end From fd7676aa19cde4cd993d6f366956e3146b313e82 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Fri, 10 Apr 2026 08:43:11 -0600 Subject: [PATCH 10/11] appease Lint/IneffectiveAccessModifier --- .rubocop_todo.yml | 6 -- .../operation/shared/polymorphic_result.rb | 4 +- lib/mongo/protocol/message.rb | 99 ++++++++++--------- lib/mongo/uri/options_mapper.rb | 41 ++++---- 4 files changed, 76 insertions(+), 74 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 566930c4ed..22c05437ff 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -42,12 +42,6 @@ Lint/IncompatibleIoSelectWithFiberScheduler: - 'lib/mongo/socket/ssl.rb' - 'lib/mongo/socket/tcp.rb' -# Offense count: 7 -Lint/IneffectiveAccessModifier: - Exclude: - - 'lib/mongo/operation/shared/polymorphic_result.rb' - - 'lib/mongo/protocol/message.rb' - - 'lib/mongo/uri/options_mapper.rb' # Offense count: 31 diff --git a/lib/mongo/operation/shared/polymorphic_result.rb b/lib/mongo/operation/shared/polymorphic_result.rb index 433e79c5a1..36dfef14a5 100644 --- a/lib/mongo/operation/shared/polymorphic_result.rb +++ b/lib/mongo/operation/shared/polymorphic_result.rb @@ -26,12 +26,12 @@ module Operation module PolymorphicResult include PolymorphicLookup - private - def self.included(base) base.extend ClassMethods end + private + module ClassMethods attr_accessor :result_class end diff --git a/lib/mongo/protocol/message.rb b/lib/mongo/protocol/message.rb index 60b1385a4d..85d426ce7e 100644 --- a/lib/mongo/protocol/message.rb +++ b/lib/mongo/protocol/message.rb @@ -320,64 +320,19 @@ def number_returned 0 end - private - - # A method for getting the fields for a message class - # - # @return [Integer] the fields for the message class - def fields - self.class.fields - end - # A class method for getting the fields for a message class # # @return [Integer] the fields for the message class + # @api private def self.fields @fields ||= [] end - # Serializes message fields into a buffer - # - # @param buffer [String] buffer to receive the field - # @return [String] buffer with serialized field - def serialize_fields(buffer, max_bson_size = nil) - fields.each do |field| - value = instance_variable_get(field[:name]) - if field[:multi] - value.each do |item| - if field[:type].respond_to?(:size_limited?) - field[:type].serialize(buffer, item, max_bson_size) - else - field[:type].serialize(buffer, item) - end - end - elsif field[:type].respond_to?(:size_limited?) - field[:type].serialize(buffer, value, max_bson_size) - else - field[:type].serialize(buffer, value) - end - end - end - - # Serializes the header of the message consisting of 4 32bit integers - # - # The integers represent a message length placeholder (calculation of - # the actual length is deferred) the request id, the response to id, - # and the op code for the message - # - # Currently uses hardcoded 0 for request id and response to as their - # values are irrelevent to the server - # - # @param buffer [String] Buffer to receive the header - # @return [String] Serialized header - def serialize_header(buffer) - Header.serialize(buffer, [ 0, request_id, 0, op_code ]) - end - # Deserializes the header of the message # # @param io [IO] Stream containing the header. # @return [Array] Deserialized header. + # @api private def self.deserialize_header(io) Header.deserialize(io) end @@ -397,6 +352,7 @@ def self.deserialize_header(io) # fields that use the number. # # @return [NilClass] + # @api private def self.field(name, type, multi = false) fields << { name: :"@#{name}", @@ -422,6 +378,7 @@ def self.field(name, type, multi = false) # each of the elements in this array using BSON types wherever possible. # # @return [Message] Message with deserialized array. + # @api private def self.deserialize_array(message, io, field, options = {}) elements = [] count = message.instance_variable_get(field[:multi]) @@ -440,12 +397,60 @@ def self.deserialize_array(message, io, field, options = {}) # this field using BSON types wherever possible. # # @return [Message] Message with deserialized field. + # @api private def self.deserialize_field(message, io, field, options = {}) message.instance_variable_set( field[:name], field[:type].deserialize(io, options) ) end + + private + + # A method for getting the fields for a message class + # + # @return [Integer] the fields for the message class + def fields + self.class.fields + end + + # Serializes message fields into a buffer + # + # @param buffer [String] buffer to receive the field + # @return [String] buffer with serialized field + def serialize_fields(buffer, max_bson_size = nil) + fields.each do |field| + value = instance_variable_get(field[:name]) + if field[:multi] + value.each do |item| + if field[:type].respond_to?(:size_limited?) + field[:type].serialize(buffer, item, max_bson_size) + else + field[:type].serialize(buffer, item) + end + end + elsif field[:type].respond_to?(:size_limited?) + field[:type].serialize(buffer, value, max_bson_size) + else + field[:type].serialize(buffer, value) + end + end + end + + # Serializes the header of the message consisting of 4 32bit integers + # + # The integers represent a message length placeholder (calculation of + # the actual length is deferred) the request id, the response to id, + # and the op code for the message + # + # Currently uses hardcoded 0 for request id and response to as their + # values are irrelevent to the server + # + # @param buffer [String] Buffer to receive the header + # @return [String] Serialized header + def serialize_header(buffer) + Header.serialize(buffer, [ 0, request_id, 0, op_code ]) + end end end end diff --git a/lib/mongo/uri/options_mapper.rb b/lib/mongo/uri/options_mapper.rb index 4e0fae9396..b9aa6f25ea 100644 --- a/lib/mongo/uri/options_mapper.rb +++ b/lib/mongo/uri/options_mapper.rb @@ -185,6 +185,28 @@ def ruby_to_string(opts) rv end + # Hash for storing map of URI option parameters to conversion strategies + # @api private + URI_OPTION_MAP = {} + + # @return [ Hash ] Map from lowercased to canonical URI + # option names. + # @api private + URI_OPTION_CANONICAL_NAMES = {} + + # Simple internal dsl to register a MongoDB URI option in the URI_OPTION_MAP. + # + # @param [ String ] uri_key The MongoDB URI option to register. + # @param [ Symbol ] name The name of the option in the driver. + # @param [ Hash ] extra Extra options. + # * :group [ Symbol ] Nested hash where option will go. + # * :type [ Symbol ] Name of function to transform value. + # @api private + def self.uri_option(uri_key, name, **extra) + URI_OPTION_MAP[uri_key.downcase] = { name: name }.update(extra) + URI_OPTION_CANONICAL_NAMES[uri_key.downcase] = uri_key + end + private # Applies URI value transformation by either using the default cast @@ -224,25 +246,6 @@ def merge_uri_option(target, value, name) end end - # Hash for storing map of URI option parameters to conversion strategies - URI_OPTION_MAP = {} - - # @return [ Hash ] Map from lowercased to canonical URI - # option names. - URI_OPTION_CANONICAL_NAMES = {} - - # Simple internal dsl to register a MongoDB URI option in the URI_OPTION_MAP. - # - # @param [ String ] uri_key The MongoDB URI option to register. - # @param [ Symbol ] name The name of the option in the driver. - # @param [ Hash ] extra Extra options. - # * :group [ Symbol ] Nested hash where option will go. - # * :type [ Symbol ] Name of function to transform value. - def self.uri_option(uri_key, name, **extra) - URI_OPTION_MAP[uri_key.downcase] = { name: name }.update(extra) - URI_OPTION_CANONICAL_NAMES[uri_key.downcase] = uri_key - end - # Replica Set Options uri_option 'replicaSet', :replica_set From 21fc732c951fad2ee14c3f29df247a48b3c70ef2 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Fri, 10 Apr 2026 08:45:46 -0600 Subject: [PATCH 11/11] tidy whitespace --- .rubocop_todo.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 22c05437ff..2a3d353ac9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,14 +6,12 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. - # Offense count: 190 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowSafeAssignment. Lint/AssignmentInCondition: Enabled: false - # Offense count: 16 # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch. Lint/DuplicateBranch: @@ -32,9 +30,6 @@ Lint/DuplicateBranch: - 'spec/runners/sdam.rb' - 'spec/support/client_registry.rb' - - - # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). Lint/IncompatibleIoSelectWithFiberScheduler: @@ -42,8 +37,6 @@ Lint/IncompatibleIoSelectWithFiberScheduler: - 'lib/mongo/socket/ssl.rb' - 'lib/mongo/socket/tcp.rb' - - # Offense count: 31 # Configuration parameters: AllowedParentClasses. Lint/MissingSuper: @@ -59,7 +52,6 @@ Lint/NextWithoutAccumulator: Exclude: - 'lib/mongo/operation/shared/result/aggregatable.rb' - # Offense count: 1 Lint/NonLocalExitFromIterator: Exclude: