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

Commit 0e7c8fd

Browse files
committed
Add reproduction-order flag for printing spec order in summary
1 parent c5ce1b2 commit 0e7c8fd

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

lib/rspec/core/configuration.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,14 @@ def exclude_pattern=(value)
327327
add_setting :default_color
328328

329329
# @macro add_setting
330-
# Color used when a pending example is fixed. Defaults to `:blue` but can
331-
# be set to one of the following: `[:black, :white, :red, :green,
332-
# :yellow, :blue, :magenta, :cyan]`
333-
# @return [Symbol]
330+
# Prints the reproduction order of the specs (default: `false`).
331+
add_setting :reproduction_order
332+
333+
# @macro add_setting
334+
# Color used when a pending example is fixed.
335+
# @param color [Symbol] defaults to `:blue` but can be set to one of the
336+
# following: `[:black, :white, :red, :green, :yellow, :blue, :magenta,
337+
# :cyan]`
334338
add_setting :fixed_color
335339

336340
# @macro add_setting
@@ -519,6 +523,7 @@ def initialize
519523
@fixed_color = :blue
520524
@detail_color = :cyan
521525
@profile_examples = false
526+
@reproduction_order = false
522527
@requires = []
523528
@libs = []
524529
@derived_metadata_blocks = FilterableItemRepository::QueryOptimized.new(:any?)

lib/rspec/core/notifications.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ def fully_formatted
297297
# the spec suite
298298
SummaryNotification = Struct.new(:duration, :examples, :failed_examples,
299299
:pending_examples, :load_time,
300-
:errors_outside_of_examples_count)
300+
:errors_outside_of_examples_count,
301+
:reproduction_order)
301302
class SummaryNotification
302303
# @api
303304
# @return [Fixnum] the number of examples run
@@ -386,6 +387,11 @@ def fully_formatted(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
386387
"(files took #{formatted_load_time} to load)\n" \
387388
"#{colorized_totals_line(colorizer)}\n"
388389

390+
if reproduction_order
391+
formatted << "\nReproduce this spec order with:\n" \
392+
"rspec --seed ordered #{examples.map(&:location).join(' ')}\n"
393+
end
394+
389395
unless failed_examples.empty?
390396
formatted += (colorized_rerun_commands(colorizer) + "\n")
391397
end

lib/rspec/core/option_parser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def parser(options)
129129
options[:deprecation_stream] = file
130130
end
131131

132+
parser.on('--reproduction-order', 'Print the order the specs ran in at the example level') do |_o|
133+
options[:reproduction_order] = true
134+
end
135+
132136
parser.on('-b', '--backtrace', 'Enable full backtrace.') do |_o|
133137
options[:full_backtrace] = true
134138
end

lib/rspec/core/reporter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ def finish
176176
end
177177
notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples,
178178
@pending_examples, @load_time,
179-
@non_example_exception_count)
179+
@non_example_exception_count,
180+
@configuration.reproduction_order))
180181
notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
181182
end
182183
end

0 commit comments

Comments
 (0)