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

Commit 3eb42de

Browse files
committed
switch to passing in example_groups from the profiler to the notification rather than the profiler itself
1 parent 7bba07b commit 3eb42de

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

lib/rspec/core/notifications.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,17 @@ def duplicate_rerun_locations
496496
# @attr duration [Float] the time taken (in seconds) to run the suite
497497
# @attr examples [Array<RSpec::Core::Example>] the examples run
498498
# @attr number_of_examples [Fixnum] the number of examples to profile
499-
# @attr profiler [RSpec::Core::Profiler] the profiler used to capture examples
500-
ProfileNotification = Struct.new(:duration, :examples, :number_of_examples, :profiler)
499+
# @attr example_groups [Array<RSpec::Core::Profiler>] example groups run
501500
class ProfileNotification
501+
502+
def initialize(duration, examples, number_of_examples, example_groups)
503+
@duration = duration
504+
@examples = examples
505+
@number_of_examples = number_of_examples
506+
@example_groups = example_groups
507+
end
508+
attr_reader :duration, :examples, :number_of_examples
509+
502510
# @return [Array<RSpec::Core::Example>] the slowest examples
503511
def slowest_examples
504512
@slowest_examples ||=
@@ -532,16 +540,14 @@ def slowest_groups
532540
private
533541

534542
def calculate_slowest_groups
535-
example_groups = profiler.example_groups
536-
537543
# stop if we've only one example group
538-
return {} if example_groups.keys.length <= 1
544+
return {} if @example_groups.keys.length <= 1
539545

540-
example_groups.each_value do |hash|
546+
@example_groups.each_value do |hash|
541547
hash[:average] = hash[:total_time].to_f / hash[:count]
542548
end
543549

544-
example_groups.sort_by { |_, hash| -hash[:average] }.first(number_of_examples)
550+
@example_groups.sort_by { |_, hash| -hash[:average] }.first(number_of_examples)
545551
end
546552
end
547553

lib/rspec/core/reporter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def finish
152152
unless mute_profile_output?
153153
notify :dump_profile, Notifications::ProfileNotification.new(@duration, @examples,
154154
@configuration.profile_examples,
155-
@profiler)
155+
@profiler.example_groups)
156156
end
157157
notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples,
158158
@pending_examples, @load_time)

spec/support/formatter_support.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def summary_notification(duration, examples, failed, pending, time)
281281
end
282282

283283
def profile_notification(duration, examples, number)
284-
::RSpec::Core::Notifications::ProfileNotification.new duration, examples, number, reporter.instance_variable_get('@profiler')
284+
::RSpec::Core::Notifications::ProfileNotification.new duration, examples, number, reporter.instance_variable_get('@profiler').example_groups
285285
end
286286

287287
end

0 commit comments

Comments
 (0)