Sha256: ffd916fc180b89bf55c94b9ef541a884f9262465ddd52d47484b29a1aca0199d

Contents?: true

Size: 1.96 KB

Versions: 4

Compression:

Stored size: 1.96 KB

Contents

module TestBoosters
  module Boosters
    class Base

      def initialize(file_pattern, split_configuration_path, command)
        @command = command
        @file_pattern = file_pattern
        @split_configuration_path = split_configuration_path
      end

      # :reek:TooManyStatements
      def run
        display_header

        before_job # execute some activities when the before the job starts

        distribution.display_info

        known, leftover = distribution.files_for(job_index)

        if cli_options[:dry_run]
          show_files_for_dry_run("known", known)
          show_files_for_dry_run("leftover", leftover)
          return 0
        end

        exit_status = TestBoosters::Job.run(@command, known, leftover)

        after_job # execute some activities when the job finishes

        exit_status
      end

      def show_files_for_dry_run(label, files)
        if files.empty?
          puts "[DRY RUN] No #{label} files."
          return
        end

        puts "\n[DRY RUN] Running tests for #{label} files:"
        puts files.map { |file| "- #{file}" }.join("\n")
      end

      def before_job
        # Do nothing
      end

      def after_job
        # Do nothing
      end

      def display_header
        version = "Test Booster v#{TestBoosters::VERSION}"
        job_info = "Job #{job_index + 1} out of #{job_count}"

        TestBoosters::Shell.display_title("#{version} - #{job_info}")
      end

      def distribution
        @distribution ||= TestBoosters::Files::Distributor.new(@split_configuration_path,
                                                               @file_pattern,
                                                               job_count)
      end

      def job_index
        @job_index ||= cli_options[:job_index] - 1
      end

      def job_count
        @job_count ||= cli_options[:job_count]
      end

      private

      def cli_options
        @cli_options ||= TestBoosters::CliParser.parse
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
treye-semaphore_test_boosters-2.5.2 lib/test_boosters/boosters/base.rb
semaphore_test_boosters-2.6.0 lib/test_boosters/boosters/base.rb
treye-semaphore_test_boosters-2.5.1 lib/test_boosters/boosters/base.rb
semaphore_test_boosters-2.5.0 lib/test_boosters/boosters/base.rb