diff --git a/lib/turbo_tests/reporter.rb b/lib/turbo_tests/reporter.rb index 4e79b5a..5bc99ce 100644 --- a/lib/turbo_tests/reporter.rb +++ b/lib/turbo_tests/reporter.rb @@ -37,6 +37,7 @@ def initialize(start_time, files, parallel_options) end def add(name, outputs) + custom_formatters = false outputs.each do |output| formatter_class = case name @@ -45,11 +46,18 @@ def add(name, outputs) when "d", "documentation" RSpec::Core::Formatters::DocumentationFormatter else + custom_formatters = true Kernel.const_get(name) end @formatters << formatter_class.new(output) end + + start if custom_formatters + end + + def start + delegate_to_formatters(:start, RSpec::Core::Notifications::StartNotification.new(examples_count)) end def group_started(notification) @@ -123,6 +131,15 @@ def seed_notification(seed, seed_used) protected + def examples_count + files = ParallelTests::RSpec::Runner.send(:find_tests, @files, @parallel_options) + output_file = Tempfile.new("rspec-summary") + `#{ENV.fetch("BUNDLE_BIN_PATH")} exec rspec --dry-run --format json --out='#{output_file.path}' #{files.join(" ")}` + + json_summary = JSON.parse(output_file.read, symbolize_names: true) + json_summary.dig(:summary, :example_count) || 0 + end + def delegate_to_formatters(method, *args) @formatters.each do |formatter| formatter.send(method, *args) if formatter.respond_to?(method)