Class: Reviewer::Tool::TestFileMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/tool/test_file_mapper.rb

Overview

Maps source files to their corresponding test files based on framework conventions.

Constant Summary collapse

FRAMEWORKS =
{
  minitest: { dir: 'test', suffix: '_test.rb', source_dirs: %w[app lib] },
  rspec: { dir: 'spec', suffix: '_spec.rb', source_dirs: %w[app lib] }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(framework) ⇒ TestFileMapper

Creates a mapper for the specified test framework

Parameters:

  • framework (Symbol, String, nil)

    the test framework (:minitest or :rspec)



16
17
18
# File 'lib/reviewer/tool/test_file_mapper.rb', line 16

def initialize(framework)
  @framework = framework&.to_sym
end

Instance Method Details

#map(files) ⇒ Array<String>

Maps source files to their corresponding test files

Parameters:

  • files (Array<String>)

    source files to map

Returns:

  • (Array<String>)

    mapped test files (only those that exist on disk)



24
25
26
27
28
# File 'lib/reviewer/tool/test_file_mapper.rb', line 24

def map(files)
  return files unless supported?

  files.map { |file| map_file(file) }.compact.uniq
end

#supported?Boolean

Checks if the framework is supported for mapping

Returns:

  • (Boolean)

    true if the framework is :minitest or :rspec



33
34
35
# File 'lib/reviewer/tool/test_file_mapper.rb', line 33

def supported?
  @framework && FRAMEWORKS.key?(@framework)
end