Sha256: 8a5641b5a13f0a8a235cf4a9c8f0fcd76f15b4ae963767b013a3e57957e4ae1b

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'assert/config_helpers'
require 'assert/suite'

module Assert

  class Runner
    include Assert::ConfigHelpers

    attr_reader :config

    def initialize(config)
      @config = config
    end

    def run
      suite, view = @config.suite, @config.view
      raise ArgumentError if !suite.kind_of?(Suite)
      if tests?
        view.puts "Running tests in random order, seeded with \"#{runner_seed}\""
      end
      view.fire(:on_start)

      begin
        suite.setup

        suite.start_time = Time.now
        tests_to_run(suite).each do |test|
          view.fire(:before_test, test)
          test.run{ |result| view.fire(:on_result, result) }
          view.fire(:after_test, test)
        end
        suite.end_time = Time.now

        suite.teardown
      rescue Interrupt => err
        view.fire(:on_interrupt, err)
        raise(err)
      end

      view.fire(:on_finish)
      suite.count(:failed) + suite.count(:errored)
    end

    private

    def tests_to_run(suite)
      srand self.config.runner_seed
      suite.tests.sort.sort_by{ rand suite.tests.size }
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
assert-2.15.0 lib/assert/runner.rb