Class: Tryouts::CLI::TestRunState
- Inherits:
-
Object
- Object
- Tryouts::CLI::TestRunState
- Defined in:
- lib/tryouts/cli/formatters/test_run_state.rb
Overview
Immutable state tracking for test runs using modern Ruby Data.define
Class Method Summary collapse
Instance Method Summary collapse
- #completion_percentage ⇒ Object
-
#elapsed_time ⇒ Object
Computed properties.
- #files_remaining ⇒ Object
- #has_issues? ⇒ Boolean
- #issues_count ⇒ Object
- #passed_count ⇒ Object
- #tests_run? ⇒ Boolean
-
#update_from_event(event_type, *args, **_kwargs) ⇒ Object
Update state based on formatter events using pattern matching.
Class Method Details
.empty ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 19 def self.empty new( total_tests: 0, passed: 0, failed: 0, errors: 0, files_completed: 0, total_files: 0, current_file: nil, current_test: nil, start_time: nil, ) end |
.initial(total_files: 0) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 33 def self.initial(total_files: 0) empty.with( total_files: total_files, start_time: Time.now, ) end |
Instance Method Details
#completion_percentage ⇒ Object
117 118 119 120 121 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 117 def completion_percentage return 0 if total_files == 0 (files_completed.to_f / total_files * 100).round(1) end |
#elapsed_time ⇒ Object
Computed properties
93 94 95 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 93 def elapsed_time start_time ? Time.now - start_time : 0 end |
#files_remaining ⇒ Object
113 114 115 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 113 def files_remaining total_files - files_completed end |
#has_issues? ⇒ Boolean
105 106 107 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 105 def has_issues? issues_count > 0 end |
#issues_count ⇒ Object
97 98 99 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 97 def issues_count failed + errors end |
#passed_count ⇒ Object
101 102 103 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 101 def passed_count total_tests - issues_count end |
#tests_run? ⇒ Boolean
109 110 111 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 109 def tests_run? total_tests > 0 end |
#update_from_event(event_type, *args, **_kwargs) ⇒ Object
Update state based on formatter events using pattern matching
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tryouts/cli/formatters/test_run_state.rb', line 41 def update_from_event(event_type, *args, **_kwargs) case event_type in :phase_header _, file_count, level = args if level == 0 && file_count with(total_files: file_count, start_time: Time.now) else self end in :file_start file_path = args[0] pretty_path = Console.pretty_path(file_path) with(current_file: pretty_path) in :file_end with( files_completed: files_completed + 1, current_file: nil, ) in :test_start test_case = args[0] desc = test_case.description.to_s desc = "test #{args[1]}" if desc.empty? with(current_test: desc) in :test_end with(current_test: nil) in :test_result result_packet = args[0] updated_state = with(total_tests: total_tests + 1) case result_packet.status when :passed updated_state.with(passed: passed + 1) when :failed updated_state.with(failed: failed + 1) when :error updated_state.with(errors: errors + 1) else updated_state end else # Unknown event, return unchanged state self end end |