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



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

def initialize
  set_defaults
end

Instance Attribute Details

#current_descriptionObject



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

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

#current_exceptionObject



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

def current_exception
  # can be nil
  @current_exception
end

#current_line_numberObject



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

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

#current_test_pathObject



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

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



55
56
57
# File 'lib/testcube/tracker.rb', line 55

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
29
# 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,
    description: current_description,
    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



51
52
53
# File 'lib/testcube/tracker.rb', line 51

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