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

Commit 1079539

Browse files
committed
perform profiling all the time to allow dynamically changing profile_examples option
1 parent 5006031 commit 1079539

File tree

5 files changed

+8
-40
lines changed

5 files changed

+8
-40
lines changed

lib/rspec/core/configuration.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -827,18 +827,6 @@ def profile_examples
827827
end
828828
end
829829

830-
# @private
831-
def profiler
832-
@profiler ||=
833-
begin
834-
if value_for(:profile_examples) { @profile_examples }
835-
Profiler.new
836-
else
837-
NoProfiler
838-
end
839-
end
840-
end
841-
842830
# @private
843831
def files_or_directories_to_run=(*files)
844832
files = files.flatten

lib/rspec/core/profiler.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
module RSpec
22
module Core
3-
# @private
4-
class NoProfiler
5-
def self.notifications
6-
[]
7-
end
8-
9-
def self.example_groups
10-
{}
11-
end
12-
end
13-
143
# @private
154
class Profiler
165
NOTIFICATIONS = [:example_group_started, :example_group_finished, :example_started]
@@ -21,10 +10,6 @@ def initialize
2110

2211
attr_reader :example_groups
2312

24-
def notifications
25-
NOTIFICATIONS
26-
end
27-
2813
def example_group_started(notification)
2914
@example_groups[notification.group.id][:start] = Time.now
3015
@example_groups[notification.group.id][:description] = notification.group.top_level_description

lib/rspec/core/reporter.rb

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

2425
# @private
@@ -151,7 +152,7 @@ def finish
151152
unless mute_profile_output?
152153
notify :dump_profile, Notifications::ProfileNotification.new(@duration, @examples,
153154
@configuration.profile_examples,
154-
@configuration.profiler)
155+
@profiler)
155156
end
156157
notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples,
157158
@pending_examples, @load_time)

spec/rspec/core/profiler_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
require 'rspec/core/profiler'
22

3-
RSpec.describe 'RSpec::Core::NoProfiler' do
4-
let(:no_profiler) { RSpec::Core::NoProfiler }
5-
6-
it 'has an empty hash of example_groups' do
7-
expect(no_profiler.example_groups).to be_empty.and be_a Hash
8-
end
9-
end
10-
113
RSpec.describe 'RSpec::Core::Profiler' do
124
let(:profiler) { RSpec::Core::Profiler.new }
135

spec/support/formatter_support.rb

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

188188
def setup_profiler
189189
config.profile_examples = true
190-
config.profiler
191190
end
192191

193192
def formatter_output
@@ -225,6 +224,7 @@ def new_example(metadata = {})
225224
instance_double(RSpec::Core::Example,
226225
:description => "Example",
227226
:full_description => "Example",
227+
:example_group => group,
228228
:execution_result => result,
229229
:location => "",
230230
:location_rerun_argument => "",
@@ -239,7 +239,9 @@ def examples(n)
239239
end
240240

241241
def group
242-
class_double "RSpec::Core::ExampleGroup", :description => "Group"
242+
group = class_double "RSpec::Core::ExampleGroup", :description => "Group", id: 1
243+
allow(group).to receive(:parent_groups) { [group] }
244+
group
243245
end
244246

245247
def start_notification(count)
@@ -279,7 +281,7 @@ def summary_notification(duration, examples, failed, pending, time)
279281
end
280282

281283
def profile_notification(duration, examples, number)
282-
::RSpec::Core::Notifications::ProfileNotification.new duration, examples, number, config.profiler
284+
::RSpec::Core::Notifications::ProfileNotification.new duration, examples, number, reporter.instance_variable_get('@profiler')
283285
end
284286

285287
end

0 commit comments

Comments
 (0)