Class: KnapsackPro::Formatters::TimeTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/knapsack_pro/formatters/time_tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_output) ⇒ TimeTracker

Returns a new instance of TimeTracker.



16
17
18
19
20
21
22
23
24
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 16

def initialize(_output)
  @output = StringIO.new
  @time_each = nil
  @time_all = nil
  @before_all = 0.0
  @group = {}
  @paths = {}
  @suite_started = now
end

Instance Attribute Details

#outputObject (readonly)

RSpec < v3.10.2



14
15
16
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 14

def output
  @output
end

Instance Method Details

#batchObject



65
66
67
68
69
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 65

def batch
  @paths.values.map do |example|
    example.transform_keys(&:to_s)
  end
end

#durationObject



71
72
73
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 71

def duration
  now - @suite_started
end

#example_finished(notification) ⇒ Object



36
37
38
39
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 36

def example_finished(notification)
  record_example(@group, notification.example, @time_each)
  @time_all = now
end

#example_group_finished(notification) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 41

def example_group_finished(notification)
  return unless top_level_group?(notification.group)

  after_all = @time_all.nil? ? 0.0 : now - @time_all
  add_hooks_time(@group, @before_all, after_all)
  @before_all = 0.0
  @paths = merge(@paths, @group)
  @group = {}
end

#example_group_started(notification) ⇒ Object



26
27
28
29
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 26

def example_group_started(notification)
  return unless top_level_group?(notification.group)
  @time_all = now
end

#example_started(_notification) ⇒ Object



31
32
33
34
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 31

def example_started(_notification)
  @before_all = now - @time_all if @before_all == 0.0
  @time_each = now
end

#queue(scheduled_paths) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 51

def queue(scheduled_paths)
  recorded_paths = @paths.values.map do |example|
    KnapsackPro::Adapters::RSpecAdapter.parse_file_path(example[:path])
  end

  missing = (scheduled_paths - recorded_paths).each_with_object({}) do |path, object|
    object[path] = { path: path, time_execution: 0.0 }
  end

  merge(@paths, missing).values.map do |example|
    example.transform_keys(&:to_s)
  end
end

#unexecuted_test_files(scheduled_paths) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 75

def unexecuted_test_files(scheduled_paths)
  pending_paths = @paths.values
    .filter { |example| example[:time_execution] == 0.0 }
    .map { |example| example[:path] }

  not_run_paths = scheduled_paths -
    @paths.values
    .map { |example| example[:path] }

  pending_paths + not_run_paths
end