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) ⇒ 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) ⇒ Reporter
Returns a new instance of Reporter.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/turbo_tests/reporter.rb', line 26 def initialize(start_time, seed, seed_used) @formatters = [] @pending_examples = [] @failed_examples = [] @all_examples = [] = [] @start_time = start_time @seed = seed @seed_used = seed_used @load_time = 0 @errors_outside_of_examples_count = 0 end |
Instance Attribute Details
#failed_examples ⇒ Object (readonly)
Returns the value of attribute failed_examples.
24 25 26 |
# File 'lib/turbo_tests/reporter.rb', line 24 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.
23 24 25 |
# File 'lib/turbo_tests/reporter.rb', line 23 def pending_examples @pending_examples end |
Class Method Details
.from_config(formatter_config, start_time, seed, seed_used) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/turbo_tests/reporter.rb', line 7 def self.from_config(formatter_config, start_time, seed, seed_used) reporter = new(start_time, seed, seed_used) 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/turbo_tests/reporter.rb', line 39 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
120 121 122 123 |
# File 'lib/turbo_tests/reporter.rb', line 120 def error_outside_of_examples() @errors_outside_of_examples_count += 1 end |
#example_failed(example) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/turbo_tests/reporter.rb', line 108 def example_failed(example) delegate_to_formatters(:example_failed, example.notification) @all_examples << example @failed_examples << example end |
#example_passed(example) ⇒ Object
95 96 97 98 99 |
# File 'lib/turbo_tests/reporter.rb', line 95 def example_passed(example) delegate_to_formatters(:example_passed, example.notification) @all_examples << example end |
#example_pending(example) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/turbo_tests/reporter.rb', line 101 def example_pending(example) delegate_to_formatters(:example_pending, example.notification) @all_examples << example @pending_examples << example end |
#finish ⇒ Object
125 126 127 128 129 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 |
# File 'lib/turbo_tests/reporter.rb', line 125 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
91 92 93 |
# File 'lib/turbo_tests/reporter.rb', line 91 def group_finished delegate_to_formatters(:example_group_finished, nil) end |
#group_started(notification) ⇒ Object
87 88 89 |
# File 'lib/turbo_tests/reporter.rb', line 87 def group_started(notification) delegate_to_formatters(:example_group_started, notification) end |
#message(message) ⇒ Object
115 116 117 118 |
# File 'lib/turbo_tests/reporter.rb', line 115 def () delegate_to_formatters(:message, RSpec::Core::Notifications::MessageNotification.new()) << end |
#report(example_groups) ⇒ Object
Borrowed from RSpec::Core::Reporter github.com/rspec/rspec-core/blob/5699fcdc4723087ff6139af55bd155ad9ad61a7b/lib/rspec/core/reporter.rb#L71
57 58 59 60 61 62 63 64 |
# File 'lib/turbo_tests/reporter.rb', line 57 def report(example_groups) start(example_groups) begin yield self ensure finish end end |
#report_number_of_tests(groups) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/turbo_tests/reporter.rb', line 77 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
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/turbo_tests/reporter.rb', line 66 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 |