Sha256: 5b5758dc42791f62e1737bb0a8f8b0beb768b73f559151d23a99f8517c4a6996

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

require 'thread'
require 'pork/report'

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

  module Stat::Imp
    attr_accessor :stop
    def initialize rt=Pork.report_class.new,
                   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, start, mutex,
        *to_a.drop(3).zip(stat.to_a.drop(3)).map{ |(a, b)| a + b })
    end
  end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pork-1.4.2 lib/pork/stat.rb
pork-1.4.1 lib/pork/stat.rb
pork-1.4.0 lib/pork/stat.rb