Sha256: 3464f5a8c86b32d22832a274f3fd87484f4d6d70bedb950756c31602d7ae7bbf

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'thread'
require 'pork/report'

module Pork
  Stat = Struct.new(:reporter, :protected_exceptions, :start, :mutex,
                    :tests, :assertions, :skips, :failures, :errors,
                    :exceptions)

  module Stat::Imp
    attr_accessor :stop
    def initialize rt=Pork.report_class.new,
                   protected_exceptions=[Pork::Error, StandardError],
                   st=Time.now, mu=Mutex.new,
                   t=0, a=0, s=0, f=0, e=0, x=[]
      super
    end

    def incr_assertions; mutex.synchronize{ self.assertions += 1 }; end
    def incr_tests     ; mutex.synchronize{ self.tests      += 1 }; end
    def incr_skips     ; mutex.synchronize{ self.skips      += 1 }; end

    def add_failure err
      mutex.synchronize do
        self.failures += 1
        exceptions << err
      end
    end

    def add_error err
      mutex.synchronize do
        self.errors += 1
        exceptions << err
      end
    end

    def passed?; exceptions.size == 0                        ; end
    def numbers; [tests, assertions, failures, errors, skips]; end

    def velocity
      time_spent = stop - start
      [time_spent.round(6),
       (tests / time_spent).round(4),
       (assertions / time_spent).round(4)]
    end

    def report
      self.stop = Time.now
      reporter.report(self)
    end

    def merge stat
      self.class.new(reporter, protected_exceptions, start, mutex,
        *to_a.drop(4).zip(stat.to_a.drop(4)).map{ |(a, b)| a + b })
    end
  end

  Stat.__send__(:include, Stat::Imp)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pork-1.4.3 lib/pork/stat.rb