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

Commit b9ee1ef

Browse files
committed
switch to passing in example_groups from the profiler to the notification rather than the profiler itself
1 parent 680ed04 commit b9ee1ef

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

lib/rspec/core/notifications.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,16 @@ def duplicate_rerun_locations
400400
# @attr duration [Float] the time taken (in seconds) to run the suite
401401
# @attr examples [Array<RSpec::Core::Example>] the examples run
402402
# @attr number_of_examples [Fixnum] the number of examples to profile
403-
# @attr profiler [RSpec::Core::Profiler] the profiler used to capture examples
404-
ProfileNotification = Struct.new(:duration, :examples, :number_of_examples, :profiler)
403+
# @attr example_groups [Array<RSpec::Core::Profiler>] example groups run
405404
class ProfileNotification
405+
def initialize(duration, examples, number_of_examples, example_groups)
406+
@duration = duration
407+
@examples = examples
408+
@number_of_examples = number_of_examples
409+
@example_groups = example_groups
410+
end
411+
attr_reader :duration, :examples, :number_of_examples
412+
406413
# @return [Array<RSpec::Core::Example>] the slowest examples
407414
def slowest_examples
408415
@slowest_examples ||=
@@ -436,16 +443,14 @@ def slowest_groups
436443
private
437444

438445
def calculate_slowest_groups
439-
example_groups = profiler.example_groups
440-
441446
# stop if we've only one example group
442-
return {} if example_groups.keys.length <= 1
447+
return {} if @example_groups.keys.length <= 1
443448

444-
example_groups.each_value do |hash|
449+
@example_groups.each_value do |hash|
445450
hash[:average] = hash[:total_time].to_f / hash[:count]
446451
end
447452

448-
example_groups.sort_by { |_, hash| -hash[:average] }.first(number_of_examples)
453+
@example_groups.sort_by { |_, hash| -hash[:average] }.first(number_of_examples)
449454
end
450455
end
451456

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)