Sha256: 26983a2fc4362e6f9ec0e4160e062837178a8a62ce04780c78cd00703531ba7d

Contents?: true

Size: 1009 Bytes

Versions: 4

Compression:

Stored size: 1009 Bytes

Contents

module Assert
  class Runner

    # a Runner runs a suite of tests.

    def initialize(suite, view)
      raise ArgumentError if !suite.kind_of?(Suite)
      @suite = suite
      @view = view
    end

    def run
      @view.fire(:on_start)
      @suite.setup

      benchmark { run_suite }

      @suite.teardown
      @view.fire(:on_finish)

      count(:failed) + count(:errored)
    end

    def count(type)
      @suite.count(type)
    end

    protected

    def tests_to_run
      # order tests randomly
      tests = @suite.tests
      srand @suite.runner_seed
      tests.sort.sort_by { rand tests.size }
    end

    private

    def benchmark
      @suite.start_time = Time.now
      yield if block_given?
      @suite.end_time = Time.now
    end

    def run_suite
      # TODO: parallel running
      tests_to_run.each do |test|
        @view.fire(:before_test, test)
        test.run {|result| @view.fire(:on_result, result)}
        @view.fire(:after_test, test)
      end
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
assert-1.1.0 lib/assert/runner.rb
assert-1.0.0 lib/assert/runner.rb
assert-0.8.1 lib/assert/runner.rb
assert-0.8.0 lib/assert/runner.rb