Module: Ace::TestRunner::Atoms::TestFolderDetector

Defined in:
lib/ace/test_runner/atoms/test_folder_detector.rb

Overview

Detects test folder location from test file paths and calculates report directory

Class Method Summary collapse

Class Method Details

.detect_report_dir(test_files) ⇒ Object

Given test file paths, find the test folder and calculate report directory Returns the parent directory of the test folder + “/test-reports”

Example:

files = ["ace-task/test/commands/tasks_command_test.rb"]
detect_report_dir(files) # => "ace-task/test-reports"


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ace/test_runner/atoms/test_folder_detector.rb', line 16

def detect_report_dir(test_files)
  return nil if test_files.nil? || test_files.empty?

  # Get the first test file and find its test folder
  first_file = test_files.first
  test_folder = find_test_folder(first_file)

  return nil unless test_folder

  # Get parent directory and append test-reports
  parent_dir = File.dirname(test_folder)
  File.join(parent_dir, "test-reports")
end

.find_test_folder(file_path) ⇒ Object

Find the test folder in a given file path Looks for “/test/” in the path and returns the path up to and including “test”

Example:

find_test_folder("ace-task/test/commands/tasks_command_test.rb")
# => "ace-task/test"


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ace/test_runner/atoms/test_folder_detector.rb', line 36

def find_test_folder(file_path)
  # Remove line number suffix if present (file:line format)
  file_path = file_path.sub(/:\d+$/, "")

  # Split path into parts
  parts = file_path.split("/")

  # Find index of "test" directory
  test_index = parts.index("test")
  return nil unless test_index

  # Return path up to and including test directory
  parts[0..test_index].join("/")
end