Sha256: b57950efbdecd6a3da1ac0a082097ee71a54e75581a05c004485e3b7985a6466
Contents?: true
Size: 1.41 KB
Versions: 16
Compression:
Stored size: 1.41 KB
Contents
require_relative 'matching_options/path' module Retest class MatchingOptions def self.for(path, files: [], limit: nil) new(path, files: files, limit: limit).filtered_results end attr_reader :path, :files, :test_directories def initialize(path, files: [], limit: 5, test_directories: nil) @path = Path.new(path) @files = files @limit = limit || 5 @test_directories = (test_directories || %w[spec test]) + %w[.] # add root file as a valid test directory end def filtered_results if path.test?(test_directories: test_directories) [path] elsif (screened_tests = screen_namespaces(possible_tests)).any? screened_tests else possible_tests end.map(&:to_s) end private def possible_tests @possible_tests ||= files .select { |file| path.possible_test?(file) } .sort_by { |file| [-path.similarity_score(file), file] } .first(@limit) end def screen_namespaces(files) test_files = files .map { |file| Path.new(file) } .select { |path| (path.reversed_dirnames & test_directories).any? } path .reversed_dirnames .each .with_index .with_object(test_files) do |(dirname, index), tests| break tests if tests.count <= 1 tests.keep_if { |test| test.reversed_dirnames[index] == dirname } end end end end
Version data entries
16 entries across 16 versions & 1 rubygems