Skip to content

Commit a5c8c77

Browse files
committed
Calculate examples count when Reporter starts
1 parent 60fe67e commit a5c8c77

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/turbo_tests/reporter.rb

+17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def initialize(start_time, files, parallel_options)
3737
end
3838

3939
def add(name, outputs)
40+
custom_formatters = false
4041
outputs.each do |output|
4142
formatter_class =
4243
case name
@@ -45,11 +46,18 @@ def add(name, outputs)
4546
when "d", "documentation"
4647
RSpec::Core::Formatters::DocumentationFormatter
4748
else
49+
custom_formatters = true
4850
Kernel.const_get(name)
4951
end
5052

5153
@formatters << formatter_class.new(output)
5254
end
55+
56+
start if custom_formatters
57+
end
58+
59+
def start
60+
delegate_to_formatters(:start, RSpec::Core::Notifications::StartNotification.new(examples_count))
5361
end
5462

5563
def group_started(notification)
@@ -123,6 +131,15 @@ def seed_notification(seed, seed_used)
123131

124132
protected
125133

134+
def examples_count
135+
files = ParallelTests::RSpec::Runner.send(:find_tests, @files, @parallel_options)
136+
output_file = Tempfile.new("rspec-summary")
137+
`#{ENV.fetch("BUNDLE_BIN_PATH")} exec rspec --dry-run --format json --out='#{output_file.path}' #{files.join(" ")}`
138+
139+
json_summary = JSON.parse(output_file.read, symbolize_names: true)
140+
json_summary.dig(:summary, :example_count) || 0
141+
end
142+
126143
def delegate_to_formatters(method, *args)
127144
@formatters.each do |formatter|
128145
formatter.send(method, *args) if formatter.respond_to?(method)

0 commit comments

Comments
 (0)