From 9d2e9aed9ae097714c70dc5d7d1d3bea60c08394 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 24 Nov 2025 11:58:13 -0500 Subject: [PATCH 1/2] extract instance_double_agent_settings_with_stubs --- spec/datadog/di/component_spec.rb | 7 ++----- .../di/integration/everything_from_remote_config_spec.rb | 7 +------ spec/datadog/di/integration/instrumentation_spec.rb | 9 ++++----- spec/datadog/di/spec_helper.rb | 9 +++++++++ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/datadog/di/component_spec.rb b/spec/datadog/di/component_spec.rb index 96465563019..d7c75d066a0 100644 --- a/spec/datadog/di/component_spec.rb +++ b/spec/datadog/di/component_spec.rb @@ -23,11 +23,8 @@ context 'when dynamic instrumentation is enabled' do let(:dynamic_instrumentation_enabled) { true } - before do - allow(agent_settings).to receive(:hostname) - allow(agent_settings).to receive(:port) - allow(agent_settings).to receive(:timeout_seconds).and_return(1) - allow(agent_settings).to receive(:ssl) + let(:agent_settings) do + instance_double_agent_settings_with_stubs end context 'when remote config is enabled' do diff --git a/spec/datadog/di/integration/everything_from_remote_config_spec.rb b/spec/datadog/di/integration/everything_from_remote_config_spec.rb index 32d3f1b7300..ac2cb1b986a 100644 --- a/spec/datadog/di/integration/everything_from_remote_config_spec.rb +++ b/spec/datadog/di/integration/everything_from_remote_config_spec.rb @@ -98,12 +98,7 @@ def target_method end let(:agent_settings) do - instance_double_agent_settings.tap do |agent_settings| - allow(agent_settings).to receive(:hostname) - allow(agent_settings).to receive(:port) - allow(agent_settings).to receive(:timeout_seconds).and_return(1) - allow(agent_settings).to receive(:ssl) - end + instance_double_agent_settings_with_stubs end let(:stringified_probe_spec) do diff --git a/spec/datadog/di/integration/instrumentation_spec.rb b/spec/datadog/di/integration/instrumentation_spec.rb index 5dd02583a23..435469a57db 100644 --- a/spec/datadog/di/integration/instrumentation_spec.rb +++ b/spec/datadog/di/integration/instrumentation_spec.rb @@ -140,14 +140,13 @@ def exception_method context 'log probe' do before do - allow(agent_settings).to receive(:hostname) - allow(agent_settings).to receive(:port) - allow(agent_settings).to receive(:timeout_seconds).and_return(1) - allow(agent_settings).to receive(:ssl) - allow(Datadog::DI).to receive(:current_component).and_return(component) end + let(:agent_settings) do + instance_double_agent_settings_with_stubs + end + context 'method probe' do context 'basic probe' do let(:probe) do diff --git a/spec/datadog/di/spec_helper.rb b/spec/datadog/di/spec_helper.rb index 0e460017a16..b163887b217 100644 --- a/spec/datadog/di/spec_helper.rb +++ b/spec/datadog/di/spec_helper.rb @@ -100,6 +100,15 @@ def deep_stringify_keys(hash) def instance_double_agent_settings instance_double(Datadog::Core::Configuration::AgentSettings) end + + def instance_double_agent_settings_with_stubs + instance_double_agent_settings.tap do |agent_settings| + allow(agent_settings).to receive(:hostname) + allow(agent_settings).to receive(:port) + allow(agent_settings).to receive(:timeout_seconds).and_return(1) + allow(agent_settings).to receive(:ssl) + end + end end end From 78eea149c5054ae51108a4651e9497ff60e118d3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev <156273877+p-datadog@users.noreply.github.com> Date: Wed, 26 Nov 2025 09:16:53 -0500 Subject: [PATCH 2/2] Update spec/datadog/di/spec_helper.rb Co-authored-by: Sergey Fedorov --- spec/datadog/di/spec_helper.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/spec/datadog/di/spec_helper.rb b/spec/datadog/di/spec_helper.rb index b163887b217..c14b122daf2 100644 --- a/spec/datadog/di/spec_helper.rb +++ b/spec/datadog/di/spec_helper.rb @@ -102,12 +102,10 @@ def instance_double_agent_settings end def instance_double_agent_settings_with_stubs - instance_double_agent_settings.tap do |agent_settings| - allow(agent_settings).to receive(:hostname) - allow(agent_settings).to receive(:port) - allow(agent_settings).to receive(:timeout_seconds).and_return(1) - allow(agent_settings).to receive(:ssl) - end + instance_double( + Datadog::Core::Configuration::AgentSettings, + hostname: "test-host", port: 9000, timeout_seconds: 1, ssl: false + ) end end end