class TestDiff::RunDiff

Class used to calculate the tests than need to be run

Attributes

group[R]
groups_of[R]
tests_folder[R]

Public Class Methods

new(tests_folder, groups_of, group) click to toggle source
# File lib/test_diff/run_diff.rb, line 7
def initialize(tests_folder, groups_of, group)
  @tests_folder = tests_folder
  @tests_to_run = []
  @groups_of = groups_of
  @group = group
end

Public Instance Methods

run() click to toggle source
# File lib/test_diff/run_diff.rb, line 14
def run
  RunableTests.new(@tests_to_run, @tests_folder).add_changed_files
  remove_tests_that_do_not_exist
  remove_tests_in_wrong_folder
  select_test_group
  run_test_group
end

Private Instance Methods

remove_tests_in_wrong_folder() click to toggle source
# File lib/test_diff/run_diff.rb, line 43
def remove_tests_in_wrong_folder
  @tests_to_run.delete_if do |s|
    !s.filename.start_with?("#{tests_folder}/")
  end
end
remove_tests_that_do_not_exist() click to toggle source
# File lib/test_diff/run_diff.rb, line 37
def remove_tests_that_do_not_exist
  @tests_to_run.delete_if do |s|
    !File.exist?("#{Config.working_directory}/#{s.filename}")
  end
end
run_test_group() click to toggle source
# File lib/test_diff/run_diff.rb, line 24
def run_test_group
  Config.test_runner.run_tests(@tests_to_run.map(&:filename))
end
select_test_group() click to toggle source
# File lib/test_diff/run_diff.rb, line 28
def select_test_group
  return unless groups_of
  new_set_of_tests_to_run = []
  @tests_to_run.each_with_index do |test, i|
    new_set_of_tests_to_run << test if i % groups_of.to_i == group.to_i
  end
  @tests_to_run = new_set_of_tests_to_run
end