Implement --order flag to match RSpec

This commit is contained in:
Michael Miller 2019-03-23 19:56:00 -06:00
parent b6453d135a
commit 7b1b65f553
2 changed files with 11 additions and 1 deletions

View File

@ -125,7 +125,7 @@ In no particular order, features that have been implemented and are planned:
- [X] Fail fast
- [ ] Test filtering - by name, context, and tags
- [X] Fail on no tests
- [ ] Randomize test order
- [X] Randomize test order
- [X] Dry run - for validation and checking formatted output
- [X] Config block in `spec_helper.cr`
- [X] Config file - `.spectator`

View File

@ -23,6 +23,16 @@ module Spectator
parser.on("-p", "--profile", "Display the 10 slowest specs") { raise NotImplementedError.new("-p") }
parser.on("-r", "--rand", "Randomize the execution order of tests") { builder.randomize }
parser.on("--seed INTEGER", "Set the seed for the random number generator (implies -r)") { |seed| builder.randomize; builder.seed = seed.to_i }
parser.on("--order ORDER", "Set the test execution order. ORDER should be one of: defined, rand, or rand:SEED") do |method|
case method.downcase
when "defined"
builder.randomize = false
when /^rand/
builder.randomize
parts = method.split(':', 2)
builder.seed = parts[1].to_i if parts.size > 1
end
end
parser.on("--location FILE:LINE", "Run the example at line 'LINE' in the file 'FILE', multiple allowed") { |location| raise NotImplementedError.new("--location") }
parser.on("--json", "Generate JSON output") { builder.formatter = Formatting::JsonFormatter.new }
parser.on("--junit_output OUTPUT_DIR", "Generate JUnit XML output") { |output_dir| builder.add_formatter(Formatting::JUnitFormatter.new(output_dir)) }