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

Add 'reproduction-order' flag for printing spec order in summary #2555

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ def exclude_pattern=(value)
# @return [Symbol]
add_setting :default_color

# @macro add_setting
# Prints the reproduction order of the specs (default: `false`).
add_setting :reproduction_order

# @macro add_setting
# Color used when a pending example is fixed. Defaults to `:blue` but can
# be set to one of the following: `[:black, :white, :red, :green,
Expand Down Expand Up @@ -519,6 +523,7 @@ def initialize
@fixed_color = :blue
@detail_color = :cyan
@profile_examples = false
@reproduction_order = false
@requires = []
@libs = []
@derived_metadata_blocks = FilterableItemRepository::QueryOptimized.new(:any?)
Expand Down
8 changes: 7 additions & 1 deletion lib/rspec/core/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ def fully_formatted
# the spec suite
SummaryNotification = Struct.new(:duration, :examples, :failed_examples,
:pending_examples, :load_time,
:errors_outside_of_examples_count)
:errors_outside_of_examples_count,
:reproduction_order)
class SummaryNotification
# @api
# @return [Fixnum] the number of examples run
Expand Down Expand Up @@ -386,6 +387,11 @@ def fully_formatted(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
"(files took #{formatted_load_time} to load)\n" \
"#{colorized_totals_line(colorizer)}\n"

if reproduction_order
formatted << "\nReproduce this spec order with:\n" \
"rspec --seed ordered #{examples.map(&:location).join(' ')}\n"
end

unless failed_examples.empty?
formatted += (colorized_rerun_commands(colorizer) + "\n")
end
Expand Down
4 changes: 4 additions & 0 deletions lib/rspec/core/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def parser(options)
options[:deprecation_stream] = file
end

parser.on('--reproduction-order', 'Print the order the specs ran in at the example level') do |_o|
options[:reproduction_order] = true
end

parser.on('-b', '--backtrace', 'Enable full backtrace.') do |_o|
options[:full_backtrace] = true
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rspec/core/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def finish
end
notify :dump_summary, Notifications::SummaryNotification.new(@duration, @examples, @failed_examples,
@pending_examples, @load_time,
@non_example_exception_count)
@non_example_exception_count,
@configuration.reproduction_order)
notify :seed, Notifications::SeedNotification.new(@configuration.seed, seed_used?)
end
end
Expand Down