Skip to content

Commit

Permalink
clean up "CI mode activated" shared context and remove hacky access t…
Browse files Browse the repository at this point in the history
…o Core internals
  • Loading branch information
anmarchenko committed Sep 18, 2023
1 parent ebfad99 commit 003eb82
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
RSpec.describe "Cucumber formatter" do
extend ConfigurationHelpers

include_context "CI mode activated"
include_context "CI mode activated" do
let(:integration_name) { :cucumber }
let(:integration_options) { {service_name: "jalapenos"} }
end

# Cucumber runtime setup
let(:existing_runtime) { Cucumber::Runtime.new(runtime_options) }
Expand All @@ -27,12 +30,6 @@
end
end

before do
Datadog.configure do |c|
c.ci.instrument :cucumber, service_name: "jalapenos"
end
end

context "executing a test suite" do
let(:args) { ["spec/datadog/ci/contrib/cucumber/cucumber.features"] }

Expand Down
9 changes: 4 additions & 5 deletions spec/datadog/ci/contrib/minitest/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
require_relative "../support/spec_helper"

RSpec.describe "Minitest hooks" do
include_context "CI mode activated"
include_context "CI mode activated" do
let(:integration_name) { :minitest }
let(:integration_options) { {service_name: "ltest"} }
end

before do
# required to call .runnable_methods
Minitest.seed = 1

Datadog.configure do |c|
c.ci.instrument :minitest, service_name: "ltest"
end
end

it "creates span for test" do
Expand Down
9 changes: 3 additions & 6 deletions spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
require_relative "../support/spec_helper"

RSpec.describe "RSpec hooks" do
include_context "CI mode activated"

before do
Datadog.configure do |c|
c.ci.instrument :rspec, service_name: "lspec"
end
include_context "CI mode activated" do
let(:integration_name) { :rspec }
let(:integration_options) { {service_name: "lspec"} }
end

# Yields to a block in a new RSpec global context. All RSpec
Expand Down
23 changes: 9 additions & 14 deletions spec/datadog/ci/contrib/support/mode_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
RSpec.shared_context "CI mode activated" do
let(:settings) do
Datadog::Core::Configuration::Settings.new.tap do |settings|
settings.ci.enabled = true
end
end

let(:components) { Datadog::Core::Configuration::Components.new(settings) }
let(:integration_name) { :override_me }
let(:integration_options) { {} }

before do
# TODO: this is a very hacky way that messes with Core's internals
allow_any_instance_of(Datadog::Core::Configuration).to receive(:configuration).and_return(settings)

allow(Datadog::Tracing)
.to receive(:tracer)
.and_return(components.tracer)
Datadog.configure do |c|
c.ci.enabled = true
c.ci.instrument integration_name, integration_options
end
end

after { components.shutdown! }
after do
::Datadog::Tracing.shutdown!
end
end

0 comments on commit 003eb82

Please sign in to comment.