Class: TurboTests::Reporter
- Inherits:
-
Object
- Object
- TurboTests::Reporter
- Defined in:
- lib/turbo_tests/reporter.rb
Instance Attribute Summary collapse
-
#failed_examples ⇒ Object
readonly
Returns the value of attribute failed_examples.
-
#load_time ⇒ Object
writeonly
Sets the attribute load_time.
-
#pending_examples ⇒ Object
readonly
Returns the value of attribute pending_examples.
Class Method Summary collapse
Instance Method Summary collapse
- #add(name, outputs) ⇒ Object
- #error_outside_of_examples(error_message) ⇒ Object
- #example_failed(example) ⇒ Object
- #example_passed(example) ⇒ Object
- #example_pending(example) ⇒ Object
- #finish ⇒ Object
- #group_finished ⇒ Object
- #group_started(notification) ⇒ Object
-
#initialize(start_time, seed, seed_used, files, parallel_options) ⇒ Reporter
constructor
A new instance of Reporter.
- #message(message) ⇒ Object
-
#report(example_groups) ⇒ Object
Borrowed from RSpec::Core::Reporter github.com/rspec/rspec-core/blob/5699fcdc4723087ff6139af55bd155ad9ad61a7b/lib/rspec/core/reporter.rb#L71.
- #report_number_of_tests(groups) ⇒ Object
- #start(example_groups, time = RSpec::Core::Time.now) ⇒ Object
Constructor Details
#initialize(start_time, seed, seed_used, files, parallel_options) ⇒ Reporter
Returns a new instance of Reporter.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/turbo_tests/reporter.rb', line 26 def initialize(start_time, seed, seed_used, files, ) @formatters = [] @pending_examples = [] @failed_examples = [] @all_examples = [] @messages = [] @start_time = start_time @seed = seed @seed_used = seed_used @load_time = 0 @errors_outside_of_examples_count = 0 @files = files @parallel_options = end |
Instance Attribute Details
#failed_examples ⇒ Object (readonly)
Returns the value of attribute failed_examples.
6 7 8 |
# File 'lib/turbo_tests/reporter.rb', line 6 def failed_examples @failed_examples end |
#load_time=(value) ⇒ Object (writeonly)
Sets the attribute load_time
5 6 7 |
# File 'lib/turbo_tests/reporter.rb', line 5 def load_time=(value) @load_time = value end |
#pending_examples ⇒ Object (readonly)
Returns the value of attribute pending_examples.
6 7 8 |
# File 'lib/turbo_tests/reporter.rb', line 6 def pending_examples @pending_examples end |
Class Method Details
.from_config(formatter_config, start_time, seed, seed_used, files, parallel_options) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/turbo_tests/reporter.rb', line 9 def from_config(formatter_config, start_time, seed, seed_used, files, ) reporter = new(start_time, seed, seed_used, files, ) formatter_config.each do |config| name, outputs = config.values_at(:name, :outputs) outputs.map! do |filename| (filename == "-") ? $stdout : File.open(filename, "w") end reporter.add(name, outputs) end reporter end |
Instance Method Details
#add(name, outputs) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/turbo_tests/reporter.rb', line 41 def add(name, outputs) outputs.each do |output| formatter_class = case name when "p", "progress" RSpec::Core::Formatters::ProgressFormatter when "d", "documentation" RSpec::Core::Formatters::DocumentationFormatter else Kernel.const_get(name) end @formatters << formatter_class.new(output) end end |
#error_outside_of_examples(error_message) ⇒ Object
125 126 127 128 |
# File 'lib/turbo_tests/reporter.rb', line 125 def error_outside_of_examples() @errors_outside_of_examples_count += 1 () end |
#example_failed(example) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/turbo_tests/reporter.rb', line 113 def example_failed(example) delegate_to_formatters(:example_failed, example.notification) @all_examples << example @failed_examples << example end |
#example_passed(example) ⇒ Object
100 101 102 103 104 |
# File 'lib/turbo_tests/reporter.rb', line 100 def example_passed(example) delegate_to_formatters(:example_passed, example.notification) @all_examples << example end |
#example_pending(example) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/turbo_tests/reporter.rb', line 106 def example_pending(example) delegate_to_formatters(:example_pending, example.notification) @all_examples << example @pending_examples << example end |
#finish ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/turbo_tests/reporter.rb', line 130 def finish end_time = RSpec::Core::Time.now @duration = end_time - @start_time delegate_to_formatters(:stop, RSpec::Core::Notifications::ExamplesNotification.new(self)) delegate_to_formatters(:start_dump, RSpec::Core::Notifications::NullNotification) delegate_to_formatters( :dump_pending, RSpec::Core::Notifications::ExamplesNotification.new( self, ), ) delegate_to_formatters( :dump_failures, RSpec::Core::Notifications::ExamplesNotification.new( self, ), ) delegate_to_formatters( :dump_summary, RSpec::Core::Notifications::SummaryNotification.new( end_time - @start_time, @all_examples, @failed_examples, @pending_examples, @load_time, @errors_outside_of_examples_count, ), ) delegate_to_formatters( :seed, RSpec::Core::Notifications::SeedNotification.new( @seed, @seed_used, ), ) ensure delegate_to_formatters(:close, RSpec::Core::Notifications::NullNotification) end |
#group_finished ⇒ Object
96 97 98 |
# File 'lib/turbo_tests/reporter.rb', line 96 def group_finished delegate_to_formatters(:example_group_finished, nil) end |
#group_started(notification) ⇒ Object
92 93 94 |
# File 'lib/turbo_tests/reporter.rb', line 92 def group_started(notification) delegate_to_formatters(:example_group_started, notification) end |
#message(message) ⇒ Object
120 121 122 123 |
# File 'lib/turbo_tests/reporter.rb', line 120 def () delegate_to_formatters(:message, RSpec::Core::Notifications::MessageNotification.new()) @messages << end |
#report(example_groups) ⇒ Object
Borrowed from RSpec::Core::Reporter github.com/rspec/rspec-core/blob/5699fcdc4723087ff6139af55bd155ad9ad61a7b/lib/rspec/core/reporter.rb#L71
59 60 61 62 63 64 65 66 |
# File 'lib/turbo_tests/reporter.rb', line 59 def report(example_groups) start(example_groups) begin yield self ensure finish end end |
#report_number_of_tests(groups) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/turbo_tests/reporter.rb', line 82 def report_number_of_tests(groups) name = ParallelTests::RSpec::Runner.test_file_name num_processes = groups.size num_tests = groups.map(&:size).sum tests_per_process = ((num_processes == 0) ? 0 : num_tests.to_f / num_processes).round puts "#{num_processes} processes for #{num_tests} #{name}s, ~ #{tests_per_process} #{name}s per process" end |
#start(example_groups, time = RSpec::Core::Time.now) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/turbo_tests/reporter.rb', line 68 def start(example_groups, time = RSpec::Core::Time.now) @start = time @load_time = (@start - @start_time).to_f report_number_of_tests(example_groups) expected_example_count = example_groups.flatten(1).count delegate_to_formatters(:seed, RSpec::Core::Notifications::SeedNotification.new(@seed, @seed_used)) delegate_to_formatters( :start, RSpec::Core::Notifications::StartNotification.new(expected_example_count, @load_time), ) end |