Module: DTest::Stopwatch

Included in:
Test::CaseResult, Test::GlobalResult, Test::Result
Defined in:
lib/dtest/util.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#finishObject

Returns the value of attribute finish.



14
15
16
# File 'lib/dtest/util.rb', line 14

def finish
  @finish
end

#startObject

Returns the value of attribute start.



14
15
16
# File 'lib/dtest/util.rb', line 14

def start
  @start
end

Instance Method Details

#elapsedObject



23
24
25
26
27
28
29
# File 'lib/dtest/util.rb', line 23

def elapsed
  if @finish && @start
    sprintf('%f', (@finish - @start).to_f)
  else
    nil
  end
end

#timer(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dtest/util.rb', line 15

def timer(&block)
  begin
    @start = Time.now
    block.call
  ensure
    @finish = Time.now
  end

  def elapsed
    if @finish && @start
      sprintf('%f', (@finish - @start).to_f)
    else
      nil
    end
  end
end