Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 3441f20

Browse files
committed
lazily instantiate profiler
1 parent 5369425 commit 3441f20

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

lib/rspec/core/formatters.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ def setup_default(output_stream, deprecation_stream)
121121
add DeprecationFormatter, deprecation_stream, output_stream
122122
end
123123

124-
return unless RSpec.configuration.profile_examples? && !existing_formatter_implements?(:dump_profile)
124+
return unless RSpec.configuration.profile_examples?
125+
126+
@reporter.setup_profiler
127+
128+
return if existing_formatter_implements?(:dump_profile)
125129

126130
add RSpec::Core::Formatters::ProfileFormatter, output_stream
127131
end

lib/rspec/core/reporter.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ def initialize(configuration)
1818
@failed_examples = []
1919
@pending_examples = []
2020
@duration = @start = @load_time = nil
21-
@profiler = Profiler.new
22-
register_listener @profiler, *Profiler::NOTIFICATIONS
2321
end
2422

2523
# @private
@@ -30,6 +28,13 @@ def reset
3028
@examples = []
3129
@failed_examples = []
3230
@pending_examples = []
31+
@profiler = Profiler.new if defined?(@profiler)
32+
end
33+
34+
# @private
35+
def setup_profiler
36+
@profiler = Profiler.new
37+
register_listener @profiler, *Profiler::NOTIFICATIONS
3338
end
3439

3540
# Registers a listener to a list of notifications. The reporter will send

spec/rspec/core/formatters_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ module RSpec::Core::Formatters
140140
context "without an existing profile formatter" do
141141
it "will add the profile formatter" do
142142
allow(reporter).to receive(:registered_listeners).with(:dump_profile) { [] }
143+
expect(reporter).to receive(:setup_profiler)
143144
setup_default
144145
expect(loader.formatters.last).to be_a ::RSpec::Core::Formatters::ProfileFormatter
145146
end
@@ -148,6 +149,7 @@ module RSpec::Core::Formatters
148149
context "when a formatter that implement #dump_profile is added" do
149150
it "wont add the profile formatter" do
150151
allow(reporter).to receive(:registered_listeners).with(:dump_profile) { [:json] }
152+
expect(reporter).to receive(:setup_profiler)
151153
setup_default
152154
expect(
153155
loader.formatters.map(&:class)

spec/rspec/core/reporter_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module RSpec::Core
2525
it "dumps the failure summary after the profile and deprecation summary so failures don't scroll off the screen and get missed" do
2626
config.profile_examples = 10
2727
formatter = instance_double("RSpec::Core::Formatter::ProgressFormatter")
28+
reporter.setup_profiler
2829
reporter.register_listener(formatter, :dump_summary, :dump_profile, :deprecation_summary)
2930

3031
expect(formatter).to receive(:deprecation_summary).ordered

spec/support/formatter_support.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def setup_reporter(*streams)
187187

188188
def setup_profiler
189189
config.profile_examples = true
190+
reporter.setup_profiler
190191
end
191192

192193
def formatter_output

0 commit comments

Comments
 (0)