Sha256: 5be93588fc75957c02ae910c4bee74b353833462ee449e087b54f67b7a86a446

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

module Retest
  class Program
    attr_accessor :runner, :repository, :command
    def initialize(runner: nil, repository: nil, command: nil)
      @runner = runner
      @repository = repository
      @command = command
    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: /\.rb$/, 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

2 entries across 2 versions & 1 rubygems

Version Path
retest-1.3.0 lib/retest/program.rb
retest-1.3.0.pre lib/retest/program.rb