Class: KnapsackPro::Formatters::TimeTracker
- Inherits:
-
Object
- Object
- KnapsackPro::Formatters::TimeTracker
- Defined in:
- lib/knapsack_pro/formatters/time_tracker.rb
Instance Method Summary collapse
- #batch ⇒ Object
- #batch_duration ⇒ Object
- #duration ⇒ Object
- #example_finished(notification) ⇒ Object
- #example_group_finished(notification) ⇒ Object
- #example_group_started(notification) ⇒ Object
- #example_started(_notification) ⇒ Object
-
#initialize(_output) ⇒ TimeTracker
constructor
Called at the beginning of each batch, but only the first instance of this class is used, so don’t rely on the initializer to reset values.
- #queue(scheduled_paths) ⇒ Object
-
#stop(_notification) ⇒ Object
Called at the end of each batch.
- #unexecuted_test_files(scheduled_paths) ⇒ Object
Constructor Details
#initialize(_output) ⇒ TimeTracker
Called at the beginning of each batch, but only the first instance of this class is used, so don’t rely on the initializer to reset values.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 16 def initialize(_output) @time_each = nil @time_all = nil @before_all = 0.0 @group = {} @batch = {} @queue = {} @suite_started = now @batch_started = now end |
Instance Method Details
#batch ⇒ Object
72 73 74 75 76 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 72 def batch @batch.values.map do |example| example.transform_keys(&:to_s) end end |
#batch_duration ⇒ Object
82 83 84 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 82 def batch_duration now - @batch_started end |
#duration ⇒ Object
78 79 80 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 78 def duration now - @suite_started end |
#example_finished(notification) ⇒ Object
37 38 39 40 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 37 def example_finished(notification) record_example(@group, notification.example, @time_each) @time_all = now end |
#example_group_finished(notification) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 42 def example_group_finished(notification) return unless top_level_group?(notification.group) add_hooks_time(@group, @before_all, now - @time_all) @batch = merge(@batch, @group) @before_all = 0.0 @group = {} end |
#example_group_started(notification) ⇒ Object
27 28 29 30 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 27 def example_group_started(notification) return unless top_level_group?(notification.group) @time_all = now end |
#example_started(_notification) ⇒ Object
32 33 34 35 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 32 def example_started(_notification) @before_all = now - @time_all if @before_all == 0.0 @time_each = now end |
#queue(scheduled_paths) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 58 def queue(scheduled_paths) recorded_paths = @queue.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(@queue, missing).values.map do |example| example.transform_keys(&:to_s) end end |
#stop(_notification) ⇒ Object
Called at the end of each batch
52 53 54 55 56 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 52 def stop(_notification) @queue = merge(@queue, @batch) @batch = {} @batch_started = now end |
#unexecuted_test_files(scheduled_paths) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 86 def unexecuted_test_files(scheduled_paths) pending_paths = (@queue.values + @batch.values) .filter { |example| example[:time_execution] == 0.0 } .map { |example| example[:path] } not_run_paths = scheduled_paths - (@queue.values + @batch.values) .map { |example| example[:path] } pending_paths + not_run_paths end |