Class: KnapsackPro::Formatters::TimeTracker
- Inherits:
-
Object
- Object
- KnapsackPro::Formatters::TimeTracker
- Defined in:
- lib/knapsack_pro/formatters/time_tracker.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
RSpec < v3.10.2.
Instance Method Summary collapse
- #batch ⇒ 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
A new instance of TimeTracker.
- #queue ⇒ Object
- #scheduled_paths=(scheduled_paths) ⇒ Object
- #unexecuted_test_files ⇒ Object
Constructor Details
#initialize(_output) ⇒ TimeTracker
Returns a new instance of TimeTracker.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 18 def initialize(_output) @output = StringIO.new @time_each = nil @time_all = nil @time_all_by_group_id_path = Hash.new(0) @group = {} @paths = {} @suite_started = now @scheduled_paths = [] @split_by_test_example_file_paths = Set.new end |
Instance Attribute Details
#output ⇒ Object (readonly)
RSpec < v3.10.2
16 17 18 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 16 def output @output end |
Instance Method Details
#batch ⇒ Object
80 81 82 83 84 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 80 def batch @paths.values.map do |example| example.transform_keys(&:to_s) end end |
#duration ⇒ Object
86 87 88 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 86 def duration now - @suite_started end |
#example_finished(notification) ⇒ Object
50 51 52 53 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 50 def example_finished(notification) record_example(@group, notification.example, @time_each) @time_all = now end |
#example_group_finished(notification) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 55 def example_group_finished(notification) record_time_all(notification.group, @time_all_by_group_id_path, @time_all) @time_all = now return unless top_level_group?(notification.group) add_hooks_time(@group, @time_all_by_group_id_path) @time_all_by_group_id_path = Hash.new(0) @paths = merge(@paths, @group) @group = {} end |
#example_group_started(notification) ⇒ Object
40 41 42 43 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 40 def example_group_started(notification) record_time_all(notification.group.parent_groups[1], @time_all_by_group_id_path, @time_all) @time_all = now end |
#example_started(notification) ⇒ Object
45 46 47 48 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 45 def example_started(notification) record_time_all(notification.example.example_group, @time_all_by_group_id_path, @time_all) @time_each = now end |
#queue ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 66 def queue 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 |
#scheduled_paths=(scheduled_paths) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 30 def scheduled_paths=(scheduled_paths) @scheduled_paths = scheduled_paths @scheduled_paths.each do |path| if KnapsackPro::Adapters::RSpecAdapter.id_path?(path) file_path = KnapsackPro::Adapters::RSpecAdapter.parse_file_path(path) @split_by_test_example_file_paths << file_path end end end |
#unexecuted_test_files ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/knapsack_pro/formatters/time_tracker.rb', line 90 def unexecuted_test_files 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 |