Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: use rspec matchers to simplify specs #121

Merged
merged 10 commits into from
Feb 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,13 @@
expect(test_module_span).not_to be_nil

# test session and module are failed
expect(test_session_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect(test_module_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect([test_session_span, test_module_span]).to all have_fail_status

# test suite spans are created for each test as for parallel execution
expect(test_suite_spans).to have(3).items
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS) }.sort).to eq(
[Datadog::CI::Ext::Test::Status::FAIL, Datadog::CI::Ext::Test::Status::PASS, Datadog::CI::Ext::Test::Status::PASS]
)
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE) }.sort).to eq(
expect(test_suite_spans).to have_tag_values_no_order(:status, ["pass", "pass", "fail"])
expect(test_suite_spans).to have_tag_values_no_order(
:suite,
[
"SomeTest at spec/datadog/ci/contrib/ci_queue_minitest/fake_test.rb (test_fail concurrently)",
"SomeTest at spec/datadog/ci/contrib/ci_queue_minitest/fake_test.rb (test_pass concurrently)",
Expand All @@ -63,13 +57,10 @@
# there is test span for every test case
expect(test_spans).to have(3).items
# each test span has its own test suite
expect(test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID) }.uniq).to have(3).items
expect(test_spans).to have_unique_tag_values_count(:test_suite_id, 3)

# every test span is connected to test module and test session
test_spans.each do |test_span|
[Datadog::CI::Ext::Test::TAG_TEST_MODULE_ID, Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID].each do |tag|
expect(test_span.get_tag(tag)).not_to be_nil
end
end
expect(test_spans).to all have_test_tag(:test_module_id)
expect(test_spans).to all have_test_tag(:test_session_id)
end
end
22 changes: 8 additions & 14 deletions spec/datadog/ci/contrib/ci_queue_rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,16 @@ def with_new_rspec_environment
expect(test_module_span).not_to be_nil

# test session and module are failed
expect(test_session_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect(test_module_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
expect([test_session_span, test_module_span]).to all have_fail_status

# test suite spans are created for each test as for parallel execution
expect(test_suite_spans).to have(2).items
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS) }.sort).to eq(
expect(test_suite_spans).to have_tag_values_no_order(
:status,
[Datadog::CI::Ext::Test::Status::FAIL, Datadog::CI::Ext::Test::Status::PASS]
)
expect(test_suite_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE) }.sort).to eq(
expect(test_suite_spans).to have_tag_values_no_order(
:suite,
[
"SomeTest at ./spec/datadog/ci/contrib/ci_queue_rspec/suite_under_test/some_test_rspec.rb (ci-queue running example [nested fails])",
"SomeTest at ./spec/datadog/ci/contrib/ci_queue_rspec/suite_under_test/some_test_rspec.rb (ci-queue running example [nested foo])"
Expand All @@ -81,13 +78,10 @@ def with_new_rspec_environment
# there is test span for every test case
expect(test_spans).to have(2).items
# each test span has its own test suite
expect(test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID) }.uniq).to have(2).items
expect(test_spans).to have_unique_tag_values_count(:test_suite_id, 2)

# every test span is connected to test module and test session
test_spans.each do |test_span|
[Datadog::CI::Ext::Test::TAG_TEST_MODULE_ID, Datadog::CI::Ext::Test::TAG_TEST_SESSION_ID].each do |tag|
expect(test_span.get_tag(tag)).not_to be_nil
end
end
expect(test_spans).to all have_test_tag(:test_module_id)
expect(test_spans).to all have_test_tag(:test_session_id)
end
end
Loading
Loading