Sha256: e99008364219523e852dd3a0cbf97666c686f3c9563f6b1330c26d337e072b20

Contents?: true

Size: 1.61 KB

Versions: 9

Compression:

Stored size: 1.61 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
      ]
    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

9 entries across 9 versions & 1 rubygems

Version Path
learn-test-3.2.1 lib/learn_test/runner.rb
learn-test-3.2.1.pre.7 lib/learn_test/runner.rb
learn-test-3.2.1.pre.6 lib/learn_test/runner.rb
learn-test-3.2.1.pre.5 lib/learn_test/runner.rb
learn-test-3.2.1.pre.4 lib/learn_test/runner.rb
learn-test-3.2.1.pre.3 lib/learn_test/runner.rb
learn-test-3.2.1.pre.2 lib/learn_test/runner.rb
learn-test-3.2.1.pre.1 lib/learn_test/runner.rb
learn-test-3.2.0 lib/learn_test/runner.rb