Skip to content

Commit

Permalink
ensure that integration works for Minitest::Spec
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Aug 17, 2023
1 parent 52e14e9 commit e4194e7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .standard_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Remove from this list as you refactor files.
---
ignore:
- lib/datadog/ci/contrib/minitest/integration.rb:
- Style/SafeNavigation
- lib/datadog/ci/contrib/cucumber/integration.rb:
- Style/SafeNavigation
- lib/datadog/ci/contrib/rspec/integration.rb:
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/contrib/minitest/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Integration
register_as :minitest, auto_patch: true

def self.version
Gem.loaded_specs["minitest"]&.version
Gem.loaded_specs["minitest"] && Gem.loaded_specs["minitest"].version
end

def self.loaded?
Expand Down
48 changes: 48 additions & 0 deletions spec/datadog/ci/contrib/minitest/instrumentation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
require "time"
require "minitest"
require "minitest/spec"

require_relative "../support/spec_helper"

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

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

Datadog.configure do |c|
c.ci.instrument :minitest, service_name: "ltest"
end
Expand Down Expand Up @@ -60,6 +65,49 @@ def self.name
expect(spans).to have(num_tests).items
end

it "creates span for spec" do
klass = Class.new(Minitest::Spec) do
def self.name
"SomeSpec"
end

it "does not fail" do
end
end

method_name = klass.runnable_methods.first
klass.new(method_name).run

expect(span.span_type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST)
expect(span.resource).to eq("SomeSpec##{method_name}")
expect(span.service).to eq("ltest")
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("SomeSpec##{method_name}")
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq(
"spec/datadog/ci/contrib/minitest/instrumentation_spec.rb"
)
end

it "creates spans for several specs" do
num_specs = 20

klass = Class.new(Minitest::Spec) do
def self.name
"SomeSpec"
end

num_specs.times do |i|
it "does fail #{}" do
end
end
end

klass.runnable_methods.each do |method_name|
klass.new(method_name).run
end

expect(spans).to have(num_specs).items
end

it "creates spans for example with instrumentation" do
klass = Class.new(Minitest::Test) do
def self.name
Expand Down

0 comments on commit e4194e7

Please sign in to comment.