Skip to content

Commit

Permalink
add automated test to check that context hooks are not called when al…
Browse files Browse the repository at this point in the history
…l tests are skipped by test impact analysis
  • Loading branch information
anmarchenko committed Dec 3, 2024
1 parent 6ffe55c commit ee04f6a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RSpec.describe "RSpec instrumentation" do
let(:integration) { Datadog::CI::Contrib::Instrumentation.fetch_integration(:rspec) }
let(:before_all_spy) { spy(:before_all, call: nil) }

before do
# expect that public manual API isn't used
Expand Down Expand Up @@ -36,9 +37,14 @@ def rspec_session_run(
flaky_test_that_fails_once_passes = 0

current_let_value = 0
before_all_spy_local = before_all_spy

with_new_rspec_environment do
spec = RSpec.describe "SomeTest", suite_meta do
before(:all) do
before_all_spy_local.call
end

context "nested", context_meta do
let(:let_value) { current_let_value += 1 }

Expand Down Expand Up @@ -150,7 +156,7 @@ def rspec_session_run(
:source_file,
"spec/datadog/ci/contrib/rspec/instrumentation_spec.rb"
)
expect(first_test_span).to have_test_tag(:source_start, "123")
expect(first_test_span).to have_test_tag(:source_start, "129")
expect(first_test_span).to have_test_tag(
:codeowners,
"[\"@DataDog/ruby-guild\", \"@DataDog/ci-app-libraries\"]"
Expand Down Expand Up @@ -580,7 +586,7 @@ def expect_failure
:source_file,
"spec/datadog/ci/contrib/rspec/instrumentation_spec.rb"
)
expect(first_test_suite_span).to have_test_tag(:source_start, "41")
expect(first_test_suite_span).to have_test_tag(:source_start, "43")
expect(first_test_suite_span).to have_test_tag(
:codeowners,
"[\"@DataDog/ruby-guild\", \"@DataDog/ci-app-libraries\"]"
Expand Down Expand Up @@ -785,6 +791,12 @@ def rspec_skipped_session_run
expect(test_session_span).to have_test_tag(:itr_test_skipping_count, 2)
end

it "does not run context hooks" do
rspec_session_run(with_failed_test: true)

expect(before_all_spy).not_to have_received(:call)
end

context "but some tests are unskippable" do
context "when a test is unskippable" do
it "runs the test and adds forced run tag" do
Expand Down

0 comments on commit ee04f6a

Please sign in to comment.