diff --git a/README.md b/README.md index e457c08..4cd6c50 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/src/spectator/command_line_arguments_config_source.cr b/src/spectator/command_line_arguments_config_source.cr index a815096..532d5fc 100644 --- a/src/spectator/command_line_arguments_config_source.cr +++ b/src/spectator/command_line_arguments_config_source.cr @@ -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)) }