Sha256: 0fb220a113b2f24c9ad7050af1fe673571409e56282c525bd59b1c0a756fbf43

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

# TestDiff module
module TestDiff
  # Class used to calculate the tests than need to be run
  class RunDiff
    attr_reader :tests_folder, :groups_of, :group

    def initialize(tests_folder, groups_of, group)
      @tests_folder = tests_folder
      @tests_to_run = []
      @groups_of = groups_of
      @group = group
    end

    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

    def run_test_group
      Config.test_runner.run_tests(@tests_to_run.map(&:filename))
    end

    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

    def remove_tests_that_do_not_exist
      @tests_to_run.delete_if do |s|
        !File.exist?("#{Config.working_directory}/#{s.filename}")
      end
    end

    def remove_tests_in_wrong_folder
      @tests_to_run.delete_if do |s|
        !s.filename.start_with?("#{tests_folder}/")
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
test_diff-0.6.0 lib/test_diff/run_diff.rb
test_diff-0.5.0 lib/test_diff/run_diff.rb
test_diff-0.4.2 lib/test_diff/run_diff.rb
test_diff-0.4.1 lib/test_diff/run_diff.rb
test_diff-0.4.0 lib/test_diff/run_diff.rb
test_diff-0.3.4 lib/test_diff/run_diff.rb
test_diff-0.3.3 lib/test_diff/run_diff.rb
test_diff-0.3.2 lib/test_diff/run_diff.rb
test_diff-0.3.1 lib/test_diff/run_diff.rb