Skip to content

RSpec test ids are relative to the working directory, not SimpleCov.root #1322

Closed

Description

@sferik

track_tests builds an RSpec example's id from RSpec's location metadata (and, since #1319, example.id), which RSpec makes relative to the directory rspec runs from. Everything else treats test ids as relative to SimpleCov.root:

  • Minitest ids strip SimpleCov.root from the test's source_location.
  • TestTracker#test_file_loading records a spec file's loading relative to SimpleCov.root.
  • Contexts#deleted_test? checks whether a test still exists with File.expand_path(file, SimpleCov.root).
  • simplecov affected checks test paths and starts --run at the root.

When rspec runs from a directory other than SimpleCov.root, say engines/foo with the root at the repository root, the example is recorded as spec/b_spec.rb:5 while its file's loading is recorded as engines/foo/spec/b_spec.rb. Then:

  • One spec file gets two unrelated contexts, so at granularity: :file its loading and its examples are never merged.
  • Contexts#deleted_test? finds no spec/b_spec.rb under the root and drops the example from the carried-forward map on every merge.
  • simplecov affected --run passes spec/b_spec.rb:5 to rspec started at the root, where that path does not exist.

A spec file outside the working directory is worse, since RSpec leaves its path absolute.

The fix is probably to build RSpec ids from the absolute path (absolute_file_path) relative to SimpleCov.root, the way Minitest ids are built, in the one place that already normalizes them, TestTracker.rspec_path (added in #1320).

CC: @meganemura

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions