Sha256: 271cee6b297d0beca8d2860090d2d228583a9e5a2176bd4fe88cf66fb1b1d154

Contents?: true

Size: 1.64 KB

Versions: 7

Compression:

Stored size: 1.64 KB

Contents

require 'yaml'

module LearnTest
  class Runner
    attr_reader :repo, :options

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

    def run
      strategy.check_dependencies
      strategy.configure
      strategy.run
      if options[:debug]
        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::Jasmine,
        LearnTest::Strategies::GreenOnion,
        LearnTest::Strategies::Rspec,
        LearnTest::Strategies::Karma,
        LearnTest::Strategies::Protractor,
        LearnTest::Strategies::JavaJunit,
        LearnTest::Strategies::Mocha,
        LearnTest::Strategies::PythonUnittest,
      ]
    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

7 entries across 7 versions & 1 rubygems

Version Path
learn-test-2.5.4 lib/learn_test/runner.rb
learn-test-2.5.3 lib/learn_test/runner.rb
learn-test-2.5.2 lib/learn_test/runner.rb
learn-test-2.5.1 lib/learn_test/runner.rb
learn-test-2.5.0 lib/learn_test/runner.rb
learn-test-2.5.0.rc2 lib/learn_test/runner.rb
learn-test-2.5.0.rc1 lib/learn_test/runner.rb