2019-06-20 20:33:41 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-06-20 19:59:01 -05:00
|
|
|
module TurboTests
|
|
|
|
class Reporter
|
|
|
|
def self.from_config(formatter_config, start_time)
|
|
|
|
reporter = new(start_time)
|
|
|
|
|
|
|
|
formatter_config.each do |config|
|
|
|
|
name, outputs = config.values_at(:name, :outputs)
|
|
|
|
|
2023-01-09 06:10:19 -06:00
|
|
|
outputs.map! { |filename| filename == "-" ? STDOUT : File.open(filename, "w") }
|
2019-06-20 19:59:01 -05:00
|
|
|
|
|
|
|
reporter.add(name, outputs)
|
|
|
|
end
|
|
|
|
|
|
|
|
reporter
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :pending_examples
|
|
|
|
attr_reader :failed_examples
|
|
|
|
|
|
|
|
def initialize(start_time)
|
|
|
|
@formatters = []
|
|
|
|
@pending_examples = []
|
|
|
|
@failed_examples = []
|
|
|
|
@all_examples = []
|
|
|
|
@start_time = start_time
|
2020-06-23 00:34:58 -05:00
|
|
|
@messages = []
|
|
|
|
@errors_outside_of_examples_count = 0
|
2019-06-20 19:59:01 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def add(name, outputs)
|
|
|
|
outputs.each do |output|
|
|
|
|
formatter_class =
|
|
|
|
case name
|
2023-01-09 06:10:19 -06:00
|
|
|
when "p", "progress"
|
2019-06-20 19:59:01 -05:00
|
|
|
RSpec::Core::Formatters::ProgressFormatter
|
|
|
|
else
|
|
|
|
Kernel.const_get(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
@formatters << formatter_class.new(output)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def example_passed(example)
|
|
|
|
delegate_to_formatters(:example_passed, example.notification)
|
|
|
|
|
|
|
|
@all_examples << example
|
|
|
|
end
|
|
|
|
|
|
|
|
def example_pending(example)
|
|
|
|
delegate_to_formatters(:example_pending, example.notification)
|
|
|
|
|
|
|
|
@all_examples << example
|
|
|
|
@pending_examples << example
|
|
|
|
end
|
|
|
|
|
|
|
|
def example_failed(example)
|
|
|
|
delegate_to_formatters(:example_failed, example.notification)
|
|
|
|
|
|
|
|
@all_examples << example
|
|
|
|
@failed_examples << example
|
|
|
|
end
|
|
|
|
|
2020-06-23 00:34:58 -05:00
|
|
|
def message(message)
|
|
|
|
delegate_to_formatters(:message, RSpec::Core::Notifications::MessageNotification.new(message))
|
|
|
|
@messages << message
|
|
|
|
end
|
|
|
|
|
|
|
|
def error_outside_of_examples
|
|
|
|
@errors_outside_of_examples_count += 1
|
|
|
|
end
|
|
|
|
|
2019-06-20 19:59:01 -05:00
|
|
|
def finish
|
|
|
|
end_time = Time.now
|
|
|
|
|
2023-01-09 06:10:19 -06:00
|
|
|
delegate_to_formatters(:start_dump, RSpec::Core::Notifications::NullNotification)
|
|
|
|
delegate_to_formatters(
|
|
|
|
:dump_pending,
|
|
|
|
RSpec::Core::Notifications::ExamplesNotification.new(self),
|
2019-06-20 19:59:01 -05:00
|
|
|
)
|
2023-01-09 06:10:19 -06:00
|
|
|
delegate_to_formatters(
|
|
|
|
:dump_failures,
|
|
|
|
RSpec::Core::Notifications::ExamplesNotification.new(self),
|
2019-06-20 19:59:01 -05:00
|
|
|
)
|
2023-01-09 06:10:19 -06:00
|
|
|
delegate_to_formatters(
|
|
|
|
:dump_summary,
|
2019-06-20 19:59:01 -05:00
|
|
|
RSpec::Core::Notifications::SummaryNotification.new(
|
|
|
|
end_time - @start_time,
|
|
|
|
@all_examples,
|
|
|
|
@failed_examples,
|
|
|
|
@pending_examples,
|
|
|
|
0,
|
2023-01-09 06:10:19 -06:00
|
|
|
@errors_outside_of_examples_count,
|
|
|
|
),
|
2019-06-20 19:59:01 -05:00
|
|
|
)
|
2023-01-09 06:10:19 -06:00
|
|
|
delegate_to_formatters(:close, RSpec::Core::Notifications::NullNotification)
|
2019-06-20 19:59:01 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def delegate_to_formatters(method, *args)
|
|
|
|
@formatters.each do |formatter|
|
|
|
|
formatter.send(method, *args) if formatter.respond_to?(method)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|