class FlakeySpecCatcher::CliOverride
CliOverride
class
Captures command line arguments for manual re-runs
Attributes
break_on_first_failure[R]
dry_run[R]
enable_runs[R]
output_file[R]
repeat_factor[R]
rerun_patterns[R]
rerun_usage[R]
split_index[R]
split_nodes[R]
test_options[R]
use_parent[R]
verbose[R]
Public Class Methods
new()
click to toggle source
# File lib/flakey_spec_catcher/cli_override.rb, line 13 def initialize @dry_run = false @enable_runs = true @excluded_tags = [] @use_parent = false @verbose = false @test_options = [] parse_command_line_args validate_arguments end
Private Instance Methods
parse_command_line_args()
click to toggle source
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength
# File lib/flakey_spec_catcher/cli_override.rb, line 27 def parse_command_line_args OptionParser.new do |opts| opts.banner = 'Usage: flakey_spec_catcher [OPTIONS]' opts.on('--use-parent', 'Use the parent of commit for git diff instead of the Head of SCM') do @use_parent = true end opts.on('-t', '--test=TEST_NAME', 'Specify one or more specs in comma separated list ' \ 'as `<path/to/file:line_number>, <path/to/file:line_number>...`') do |test| @rerun_patterns = remove_formatter_quotes(test) end opts.on('-u', '--usage=USAGE', 'Specify a re-run usage for the manual re-run') do |usage| @rerun_usage = remove_formatter_quotes(usage) end opts.on('--node-total=SPLIT_NODES', 'Specify now many nodes the run is being split into') do |nodes| @split_nodes = remove_formatter_quotes(nodes).to_i end opts.on('--node-index=SPLIT_INDEX', 'Specify the index this node represents in a split run') do |index| @split_index = remove_formatter_quotes(index).to_i end opts.on('-r', '--repeat=REPEAT_FACTOR', 'Specify a repeat factor for the manual re-run(s)') do |repeat| @repeat_factor = remove_formatter_quotes(repeat).to_i end opts.on('--break-on-first-failure', 'Break on first failure') do |break_on_first_failure| @break_on_first_failure = break_on_first_failure end opts.on('-e', '--excluded-tags=EXCLUDED_TAGS', 'Specify tags to exclude in a comma separated list') do |tags| @excluded_tags = parse_tags(tags) end opts.on('-o', '--output=PATH_TO_OUTPUT', 'Direct all re-run output to a specific file') do |file| @output_file = remove_formatter_quotes(file) end opts.on('-v', '--version', 'Prints current flakey_spec_catcher_version') do puts "flakey_spec_catcher Version: #{FlakeySpecCatcher::VERSION}" @enable_runs = false end opts.on('-d', '--dry-run', "Performs all setup but doesn't run any tests") do @dry_run = true end opts.on('--dry-run-quiet', 'Prints list of tests to be run') do @enable_runs = false @dry_run = true end opts.on('--verbose', 'Send all output from running tests to stdout') do @verbose = true end opts.on('-h', '--help', 'Displays available flakey_spec_catcher cli overrides') do puts opts @enable_runs = false end opts.on("--rspec-options '[OPTIONS]'", 'execute default usage with rspec options') do |arg| @test_options = arg.split(/[ ](?=(?:[^"]*"[^"]*")*[^"]*$)(?=(?:[^']*'[^']*')*[^']*$)/) end end.parse! end
remove_formatter_quotes(env_var)
click to toggle source
rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength
# File lib/flakey_spec_catcher/cli_override.rb, line 118 def remove_formatter_quotes(env_var) env_var.tr('\'\"', '') end
validate_arguments()
click to toggle source
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# File lib/flakey_spec_catcher/cli_override.rb, line 103 def validate_arguments if !@rerun_usage.nil? && @rerun_patterns.nil? raise ArgumentError, 'rerun usage can only be specified with rerun patterns' end raise ArgumentError, 'repeat factor must be positive' if !@repeat_factor.nil? && @repeat_factor.negative? raise ArgumentError, 'split index and split nodes must be specified together' if @split_nodes.nil? != @split_index.nil? splitting = !@split_nodes.nil? && !@split_index.nil? raise ArgumentError, 'split total must be positive' if splitting && @split_nodes.negative? raise ArgumentError, 'split index must be positive' if splitting && @split_index.negative? raise ArgumentError, 'split index must be less than split nodes' if splitting && @split_index >= @split_nodes end