Class: Testcube::Tracker

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/testcube/tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTracker

Returns a new instance of Tracker.



10
11
12
# File 'lib/testcube/tracker.rb', line 10

def initialize
  set_defaults
end

Instance Attribute Details

#current_exceptionObject



40
41
42
43
# File 'lib/testcube/tracker.rb', line 40

def current_exception
  # can be nil
  @current_exception
end

#current_line_numberObject



35
36
37
38
# File 'lib/testcube/tracker.rb', line 35

def current_line_number
  raise("current_line_number needs to be set") unless @current_line_number
  @current_line_number
end

#current_test_pathObject



30
31
32
33
# File 'lib/testcube/tracker.rb', line 30

def current_test_path
  raise("current_test_path needs to be set") unless @current_test_path
  @current_test_path.sub(/^\.\//, '')
end

#test_files_with_timeObject (readonly)

Returns the value of attribute test_files_with_time.



7
8
9
# File 'lib/testcube/tracker.rb', line 7

def test_files_with_time
  @test_files_with_time
end

Instance Method Details

#num_specsObject



49
50
51
# File 'lib/testcube/tracker.rb', line 49

def num_specs
  test_files_with_time.length
end

#start_timerObject



14
15
16
# File 'lib/testcube/tracker.rb', line 14

def start_timer
  @start_time = now_without_mock_time.to_f
end

#stop_timerObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/testcube/tracker.rb', line 18

def stop_timer
  execution_time = @start_time ? now_without_mock_time.to_f - @start_time : 0.0
  @test_files_with_time.push({
    test_file: current_test_path,
    line_number: current_line_number,
    status: current_exception ? :fail : :pass,
    # TODO: we could have a better way to filter the backtrace
    backtrace: current_exception ? current_exception.backtrace.select { |s| s !~ /gems\/.*(rspec|bin)/ } : nil,
    execution_time: execution_time
  })
end

#total_timeObject



45
46
47
# File 'lib/testcube/tracker.rb', line 45

def total_time
  test_files_with_time.map { |res| res[:execution_time] }.sum
end