@@ -37,6 +37,7 @@ def initialize(start_time, files, parallel_options)
37
37
end
38
38
39
39
def add ( name , outputs )
40
+ custom_formatters = false
40
41
outputs . each do |output |
41
42
formatter_class =
42
43
case name
@@ -45,11 +46,18 @@ def add(name, outputs)
45
46
when "d" , "documentation"
46
47
RSpec ::Core ::Formatters ::DocumentationFormatter
47
48
else
49
+ custom_formatters = true
48
50
Kernel . const_get ( name )
49
51
end
50
52
51
53
@formatters << formatter_class . new ( output )
52
54
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 ) )
53
61
end
54
62
55
63
def group_started ( notification )
@@ -123,6 +131,15 @@ def seed_notification(seed, seed_used)
123
131
124
132
protected
125
133
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
+
126
143
def delegate_to_formatters ( method , *args )
127
144
@formatters . each do |formatter |
128
145
formatter . send ( method , *args ) if formatter . respond_to? ( method )
0 commit comments