Class: KnapsackPro::BaseAllocatorBuilder

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

Direct Known Subclasses

AllocatorBuilder, QueueAllocatorBuilder

Constant Summary collapse

TEST_RUNNER_MAP =
{
  KnapsackPro::Adapters::RSpecAdapter => 'rspec',
  KnapsackPro::Adapters::CucumberAdapter => 'cucumber',
  KnapsackPro::Adapters::MinitestAdapter => 'minitest',
  KnapsackPro::Adapters::SpinachAdapter => 'spinach',
  KnapsackPro::Adapters::TestUnitAdapter => 'test-unit',
}

Instance Method Summary collapse

Constructor Details

#initialize(adapter_class) ⇒ BaseAllocatorBuilder

Returns a new instance of BaseAllocatorBuilder.



13
14
15
16
# File 'lib/knapsack_pro/base_allocator_builder.rb', line 13

def initialize(adapter_class)
  @adapter_class = adapter_class
  ENV['KNAPSACK_PRO_TEST_RUNNER'] = TEST_RUNNER_MAP[adapter_class]
end

Instance Method Details

#allocatorObject

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/knapsack_pro/base_allocator_builder.rb', line 18

def allocator
  raise NotImplementedError
end

#fallback_mode_test_filesObject

In Fallback Mode, we always want to run whole test files (not split by test cases) to guarantee that each test will be executed at least once across parallel CI nodes.



29
30
31
# File 'lib/knapsack_pro/base_allocator_builder.rb', line 29

def fallback_mode_test_files
  all_test_files_to_run
end

#fast_and_slow_test_files_to_runObject

Detect test files present on the disk that should be run. This may include fast test files + slow test files split by test cases.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/knapsack_pro/base_allocator_builder.rb', line 35

def fast_and_slow_test_files_to_run
  test_files_to_run = all_test_files_to_run

  if adapter_class.split_by_test_cases_enabled?
    slow_test_files = get_slow_test_files
    return test_files_to_run if slow_test_files.empty?

    test_file_cases = adapter_class.test_file_cases_for(slow_test_files)

    return KnapsackPro::TestFilesWithTestCasesComposer.call(test_files_to_run, slow_test_files, test_file_cases)
  end

  test_files_to_run
end

#test_dirObject



22
23
24
# File 'lib/knapsack_pro/base_allocator_builder.rb', line 22

def test_dir
  KnapsackPro::Config::Env.test_dir || TestFilePattern.test_dir(adapter_class)
end