diff --git a/sig/datadog/ci/worker.rbs b/sig/datadog/ci/worker.rbs index 21b86c17..a762cb24 100644 --- a/sig/datadog/ci/worker.rbs +++ b/sig/datadog/ci/worker.rbs @@ -1,8 +1,8 @@ module Datadog module CI class Worker < Datadog::Core::Worker - include Datadog::Core::Workers::Async::Thread::PrependedMethods include Datadog::Core::Workers::Async::Thread + include Datadog::Core::Workers::Async::Thread::PrependedMethods DEFAULT_SHUTDOWN_TIMEOUT: 60 diff --git a/spec/datadog/ci/contrib/minitest/instrumentation_spec.rb b/spec/datadog/ci/contrib/minitest/instrumentation_spec.rb index e5ee8fb9..8bbe37ed 100644 --- a/spec/datadog/ci/contrib/minitest/instrumentation_spec.rb +++ b/spec/datadog/ci/contrib/minitest/instrumentation_spec.rb @@ -504,9 +504,7 @@ def test_pass_other # expect that background thread is covered test_span = test_spans.find { |span| span.get_tag("test.name") == "test_pass_other" } cov_event = find_coverage_for_test(test_span) - expect(cov_event.coverage.keys).to include( - File.expand_path(File.join(__dir__, "helpers/addition_helper.rb")) - ) + expect(cov_event.coverage.keys).to include(absolute_path("helpers/addition_helper.rb")) end context "when ITR skips tests" do @@ -935,7 +933,7 @@ def test_with_background_thread # expect that background thread is not covered cov_event = find_coverage_for_test(first_test_span) expect(cov_event.coverage.keys).not_to include( - File.expand_path(File.join(__dir__, "helpers/addition_helper.rb")) + absolute_path("helpers/addition_helper.rb") ) end end diff --git a/spec/datadog/ci/itr/coverage/event_spec.rb b/spec/datadog/ci/itr/coverage/event_spec.rb index bb1ccbf0..ad17bef6 100644 --- a/spec/datadog/ci/itr/coverage/event_spec.rb +++ b/spec/datadog/ci/itr/coverage/event_spec.rb @@ -86,7 +86,7 @@ context "when file paths are absolute" do let(:coverage) do { - File.expand_path(File.join(__dir__, "./project/file.rb")) => true + absolute_path("./project/file.rb") => true } end diff --git a/spec/ddcov/ddcov_spec.rb b/spec/ddcov/ddcov_spec.rb index 70873407..4f0cc68a 100644 --- a/spec/ddcov/ddcov_spec.rb +++ b/spec/ddcov/ddcov_spec.rb @@ -6,10 +6,6 @@ require_relative "calculator/code_with_❤️" RSpec.describe Datadog::CI::ITR::Coverage::DDCov do - def absolute_path(path) - File.expand_path(File.join(__dir__, path)) - end - let(:ignored_path) { nil } let(:threading_mode) { :multi } subject { described_class.new(root: root, ignored_path: ignored_path, threading_mode: threading_mode) } diff --git a/spec/ddcov/ddcov_with_symlinks_spec.rb b/spec/ddcov/ddcov_with_symlinks_spec.rb index c6bb0583..3b382216 100644 --- a/spec/ddcov/ddcov_with_symlinks_spec.rb +++ b/spec/ddcov/ddcov_with_symlinks_spec.rb @@ -5,10 +5,6 @@ require "datadog_cov.#{RUBY_VERSION}_#{RUBY_PLATFORM}" RSpec.describe Datadog::CI::ITR::Coverage::DDCov do - def absolute_path(path) - File.expand_path(File.join(__dir__, path)) - end - before do # create a symlink to the calculator_with_symlinks/operations folder in vendor/gems FileUtils.ln_s( diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fb652ca0..7bbe6ca7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,6 +14,7 @@ require_relative "support/span_helpers" require_relative "support/platform_helpers" require_relative "support/synchronization_helpers" +require_relative "support/file_helpers" # shared contexts require_relative "support/contexts/ci_mode" @@ -63,6 +64,7 @@ def self.load_plugins config.include TracerHelpers config.include SpanHelpers config.include SynchronizationHelpers + config.include FileHelpers # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" diff --git a/spec/support/file_helpers.rb b/spec/support/file_helpers.rb new file mode 100644 index 00000000..f7ec679d --- /dev/null +++ b/spec/support/file_helpers.rb @@ -0,0 +1,11 @@ +require "datadog/ci" + +module FileHelpers + # this helper returns the absolute path of a file when given + # path relative to the current __dir__ + def absolute_path(path) + callstack_top = caller_locations(1, 1)[0] + caller_dir = File.dirname(callstack_top.absolute_path) + File.join(caller_dir, path) + end +end