Class: KnapsackPro::TestFileFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/knapsack_pro/test_file_finder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_file_pattern, test_file_list_enabled) ⇒ TestFileFinder

Returns a new instance of TestFileFinder.



44
45
46
47
# File 'lib/knapsack_pro/test_file_finder.rb', line 44

def initialize(test_file_pattern, test_file_list_enabled)
  @test_file_pattern = test_file_pattern
  @test_file_list_enabled = test_file_list_enabled
end

Class Method Details

.call(test_file_pattern, test_file_list_enabled: true) ⇒ Object



3
4
5
# File 'lib/knapsack_pro/test_file_finder.rb', line 3

def self.call(test_file_pattern, test_file_list_enabled: true)
  new(test_file_pattern, test_file_list_enabled).call
end

.select_test_files_that_can_be_run(adapter_class, test_file_entities_to_run) ⇒ Object

Args:

test_file_entities_to_run - it can be list of slow test files that you want to run

Return:

subset of test_file_entities_to_run that are present on disk and it is subset of tests matching pattern KNAPSACK_PRO_TEST_FILE_PATTERN
Thanks to that we can select only slow test files that are within list of test file pattern we want to run tests for


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/knapsack_pro/test_file_finder.rb', line 27

def self.select_test_files_that_can_be_run(adapter_class, test_file_entities_to_run)
  test_file_pattern = KnapsackPro::TestFilePattern.call(adapter_class)
  test_file_entities = call(test_file_pattern)

  test_file_paths_existing_on_disk = KnapsackPro::TestFilePresenter.paths(test_file_entities)

  selected_test_files = []

  test_file_entities_to_run.each do |test_file_entity|
    if test_file_paths_existing_on_disk.include?(test_file_entity.fetch('path'))
      selected_test_files << test_file_entity
    end
  end

  selected_test_files
end

.slow_test_files_by_pattern(adapter_class) ⇒ Object

finds slow test files on disk based on ENV patterns returns example: [{ ‘path’ => ‘a_spec.rb’ }]



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/knapsack_pro/test_file_finder.rb', line 9

def self.slow_test_files_by_pattern(adapter_class)
  raise 'KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN is not defined' unless KnapsackPro::Config::Env.slow_test_file_pattern

  test_file_pattern = KnapsackPro::TestFilePattern.call(adapter_class)
  test_file_entities = call(test_file_pattern)

  slow_test_file_entities = call(KnapsackPro::Config::Env.slow_test_file_pattern, test_file_list_enabled: false)

  # slow test files (KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN)
  # should be subset of test file pattern (KNAPSACK_PRO_TEST_FILE_PATTERN)
  slow_test_file_entities & test_file_entities
end

Instance Method Details

#callObject



49
50
51
52
53
54
55
# File 'lib/knapsack_pro/test_file_finder.rb', line 49

def call
  test_file_hashes = []
  test_files.each do |test_file_path|
    test_file_hashes << test_file_hash_for(test_file_path)
  end
  test_file_hashes
end