Sha256: ea1b23b1151d459355f20119a0659dae7ab94f2ae003feb1f71b5e3968df6849

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

require 'yaml'

module LearnTest
  class Runner
    attr_reader :repo, :options

    def initialize(repo, options = {})
      @repo = repo
      @options = options
      die unless strategy
    end

    def run
      strategy.check_dependencies
      strategy.configure
      strategy.run
      if options[:debug] || options[:sync]
        report_and_clean
      else
        Process.detach(Process.fork do
          report_and_clean
        end)
      end
    end

    def files
      @files ||= Dir.entries('.')
    end

    def keep_results?
      @keep_results ||= options[:keep] || !!options.delete('--keep')
    end

    def strategy
      @strategy ||= strategies.map { |s| s.new(self) }.detect(&:detect)
    end

    private

    def report_and_clean
      require_relative 'reporter'

      if !help_option_present? && strategy.push_results? && !local_test_run?
        LearnTest::Reporter.report(strategy, options)
      end

      strategy.cleanup unless keep_results?
    end

    def strategies
      [
        LearnTest::Strategies::CSharpNunit,
        LearnTest::Strategies::Rspec,
        LearnTest::Strategies::Karma,
        LearnTest::Strategies::Protractor,
        LearnTest::Strategies::JavaJunit,
        LearnTest::Strategies::Mocha,
        LearnTest::Strategies::Pytest,
        LearnTest::Strategies::None
      ]
    end

    def help_option_present?
      options.include?('-h') || options.include?('--help')
    end

    def local_test_run?
      options.include?('-h') || options.include?('--local')
    end

    def die
      puts "This directory doesn't appear to have any specs in it."
      exit
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
learn-test-3.2.3 lib/learn_test/runner.rb
learn-test-3.2.2 lib/learn_test/runner.rb