Class: Busted::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/busted/counter.rb

Instance Method Summary collapse

Constructor Details

#initialize(stack = Stack.new) ⇒ Counter

Returns a new instance of Counter.



7
8
9
10
# File 'lib/busted/counter.rb', line 7

def initialize(stack = Stack.new)
  @stack = stack
  @lock = Monitor.new
end

Instance Method Details

#finishObject



16
17
18
# File 'lib/busted/counter.rb', line 16

def finish
  lock.synchronize { stack.finished = counts }
end

#reportObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/busted/counter.rb', line 20

def report
  lock.synchronize do
    started = stack.started
    finished = stack.finished

    [:method, :constant].each_with_object({}) do |counter, result|
      result[counter] = finished[counter] - started[counter]
    end
  end
end

#startObject



12
13
14
# File 'lib/busted/counter.rb', line 12

def start
  lock.synchronize { stack.started = counts }
end