Skip to content

Commit

Permalink
add cucumber feature with examples to instrumentation specs
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jan 10, 2024
1 parent de794cb commit 46ce917
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
Then "failure" do
expect(1 + 1).to eq(3)
end

Then(/I add (-?\d+) and (-?\d+)/) do |n1, n2|
@res = n1.to_i + n2.to_i
end

Then(/the result should be (-?\d+)/) do |res|
expect(@res).to eq(res.to_i)
end
12 changes: 12 additions & 0 deletions spec/datadog/ci/contrib/cucumber/features/with_parameters.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Datadog integration for parametrized tests

Scenario Outline: scenario with examples
Given datadog
When I add <num1> and <num2>
Then the result should be <total>

Examples:
| num1 | num2 | total |
| -1 | 1 | 0 |
| 1 | 1 | 2 |
| 0 | 0 | 0 |
40 changes: 34 additions & 6 deletions spec/datadog/ci/contrib/cucumber/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
let(:integration_options) { {service_name: "jalapenos"} }
end

let(:cucumber_8_or_above) { Gem::Version.new("8.0.0") <= Datadog::CI::Contrib::Cucumber::Integration.version }
let(:cucumber_4_or_above) { Gem::Version.new("4.0.0") <= Datadog::CI::Contrib::Cucumber::Integration.version }

let(:run_id) { rand(1..2**64 - 1) }
let(:steps_file_definition_path) { "spec/datadog/ci/contrib/cucumber/features/step_definitions/steps.rb" }
let(:steps_file_for_run_path) do
Expand All @@ -35,12 +38,10 @@
let(:kernel) { double(:kernel) }

let(:cli) do
cucumber_8 = Gem::Version.new("8.0.0")

if Datadog::CI::Contrib::Cucumber::Integration.version < cucumber_8
Cucumber::Cli::Main.new(args, stdin, stdout, stderr, kernel)
else
if cucumber_8_or_above
Cucumber::Cli::Main.new(args, stdout, stderr, kernel)
else
Cucumber::Cli::Main.new(args, stdin, stdout, stderr, kernel)
end
end

Expand Down Expand Up @@ -202,14 +203,41 @@
end
end

context "executing a scenario with examples" do
let(:feature_file_to_run) { "with_parameters.feature" }

it "a single test suite with a test span for each example" do
expect(test_spans.count).to eq(3)
expect(test_suite_spans.count).to eq(1)

test_spans.each_with_index do |span, index|
# naming for scenarios changed since cucumber 4
if cucumber_4_or_above
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("scenario with examples")
else
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq(
"scenario with examples, Examples (##{index + 1})"
)
end
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq(
"spec/datadog/ci/contrib/cucumber/features/with_parameters.feature"
)
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID)).to eq(test_suite_span.id.to_s)
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::PASS
)
end
end
end

context "executing several features at once" do
let(:expected_test_run_code) { 2 }

let(:passing_test_suite) { test_suite_spans.find { |span| span.name =~ /passing/ } }
let(:failing_test_suite) { test_suite_spans.find { |span| span.name =~ /failing/ } }

it "creates a test suite span for each feature" do
expect(test_suite_spans.count).to eq(2)
expect(test_suite_spans.count).to eq(3)
expect(passing_test_suite.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::PASS
)
Expand Down

0 comments on commit 46ce917

Please sign in to comment.