Sha256: 01f3cfd89bfa54256ce06c97e64cce36d1551e43a3b8a764ad885776f1f147c1

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module Retest
  class Program
    attr_accessor :runner, :repository, :command, :extension
    def initialize(runner: nil, repository: nil, command: nil, extension: /\.rb$/)
      @runner = runner
      @repository = repository
      @command = command
      @extension = extension
    end

    def start
      puts "Launching Retest..."
      build.start
      puts "Ready to refactor! You can make file changes now"
    end

    def diff(branch)
      raise "Git not installed" unless VersionControl::Git.installed?
      test_files = repository.find_tests VersionControl::Git.diff_files(branch)

      puts "Tests found:"
      test_files.each { |test_file| puts "  - #{test_file}" }

      puts "Running tests..."
      command.run_all *test_files, runner: runner
    end

    private

    def build
      Listen.to('.', only: extension, relative: true) do |modified, added, removed|
        begin
          repository.add(added)
          repository.remove(removed)
          runner.remove(removed)
          system('clear 2>/dev/null') || system('cls 2>/dev/null')

          runner.run test_file_to_run(modified + added)
        rescue => e
          puts "Something went wrong: #{e.message}"
        end
      end
    end

    def test_file_to_run(changed_files)
      repository.find_test changed_files.first if runner.matching?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
retest-1.4.0 lib/retest/program.rb