class CukeCommander::CLGenerator
The object responsible for generating Cucumber command lines.
Public Instance Methods
generate_command_line(options = {})
click to toggle source
Generates a Cucumber command line.
Most option values are either an Array or a boolean value. In the case of the former, a String can be used instead of an Array when only a single value is needed. Some option values come in pairs (e.g. formatters and their output locations). These option values are taken as a Hash where a key is the first part of the pair and the key’s value is the second part.
@param options [Hash] the Cucumber options that the command line should include.
# File lib/cuke_commander/cl_generator.rb, line 15 def generate_command_line(options = {}) validate_options(options) command_line = 'cucumber' append_options(command_line, wrap_options(options[:profiles]), flag_for(:profiles, options[:long_flags])) if options[:profiles] append_options(command_line, wrap_options(options[:names]), flag_for(:names, options[:long_flags])) if options[:names] append_options(command_line, wrap_options(options[:tags]), flag_for(:tags, options[:long_flags])) if options[:tags] append_options(command_line, wrap_options(options[:file_paths])) if options[:file_paths] append_options(command_line, wrap_options(options[:excludes]), flag_for(:excludes, options[:long_flags])) if options[:excludes] append_options(command_line, wrap_options(options[:requires]), flag_for(:requires, options[:long_flags])) if options[:requires] append_option(command_line, flag_for(:no_source, options[:long_flags])) if options[:no_source] if options[:formatters] options[:formatters].each do |format, output_location| append_option(command_line, format, flag_for(:format, options[:long_flags])) append_option(command_line, output_location,flag_for(:output, options[:long_flags])) unless output_location.to_s.empty? end end append_option(command_line, flag_for(:no_color,options[:long_flags])) if options[:no_color] append_option(command_line, flag_for(:color,options[:long_flags])) if options[:color] append_option(command_line, flag_for(:backtrace,options[:long_flags])) if options[:backtrace] append_option(command_line, flag_for(:dry_run,options[:long_flags])) if options[:dry_run] append_option(command_line, flag_for(:no_profile,options[:long_flags])) if options[:no_profile] append_option(command_line, flag_for(:guess,options[:long_flags])) if options[:guess] append_option(command_line, flag_for(:wip,options[:long_flags])) if options[:wip] append_option(command_line, flag_for(:quiet,options[:long_flags])) if options[:quiet] append_option(command_line, flag_for(:verbose,options[:long_flags])) if options[:verbose] append_option(command_line, flag_for(:version,options[:long_flags])) if options[:version] append_option(command_line, flag_for(:help,options[:long_flags])) if options[:help] append_option(command_line, flag_for(:expand,options[:long_flags])) if options[:expand] append_option(command_line, flag_for(:strict,options[:long_flags])) if options[:strict] append_options(command_line, wrap_options(options[:options])) if options[:options] command_line end
Private Instance Methods
append_option(command, option, flag= nil)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 95 def append_option(command, option, flag= nil) command << " #{flag}" if flag command << " #{option}" end
append_options(command, option_set, flag= nil)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 89 def append_options(command, option_set, flag= nil) option_set.each do |option| append_option(command, option, flag) end end
flag_for(option, long_flags)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 212 def flag_for(option, long_flags) case option when :tags long_flags ? '--tags' : '-t' when :profiles long_flags ? '--profile' : '-p' when :names long_flags ? '--name' : '-n' when :excludes long_flags ? '--exclude' : '-e' when :requires long_flags ? '--require' : '-r' when :backtrace long_flags ? '--backtrace' : '-b' when :color long_flags ? '--color' : '-c' when :no_color '--no-color' when :dry_run long_flags ? '--dry-run' : '-d' when :guess long_flags ? '--guess' : '-g' when :wip long_flags ? '--wip' : '-w' when :quiet long_flags ? '--quiet' : '-q' when :help long_flags ? '--help' : '-h' when :verbose long_flags ? '--verbose' : '-v' when :version '--version' when :strict long_flags ? '--strict' : '-S' when :expand long_flags ? '--expand' : '-x' when :no_source long_flags ? '--no-source' : '-s' when :no_profile long_flags ? '--no-profile' : '-P' when :format long_flags ? '--format' : '-f' when :output long_flags ? '--out' : '-o' end end
raise_invalid_error(option, valid_types, value_used)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 104 def raise_invalid_error(option, valid_types, value_used) raise(ArgumentError, "#{option} option must be #{valid_types}, got: #{value_used.class}") end
valid_backtrace?(backtrace)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 140 def valid_backtrace?(backtrace) valid_boolean_value?(backtrace) end
valid_boolean_value?(value)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 204 def valid_boolean_value?(value) value.nil? || (value == true) || (value == false) end
valid_color?(color)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 136 def valid_color?(color) valid_boolean_value?(color) end
valid_dry_run?(dry_run)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 180 def valid_dry_run?(dry_run) valid_boolean_value?(dry_run) end
valid_excludes?(excludes)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 124 def valid_excludes?(excludes) valid_string_array_value?(excludes) end
valid_expand?(expand)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 152 def valid_expand?(expand) valid_boolean_value?(expand) end
valid_file_paths?(file_paths)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 116 def valid_file_paths?(file_paths) valid_string_array_value?(file_paths) end
valid_formatters?(formatters)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 120 def valid_formatters?(formatters) valid_hash_value?(formatters) end
valid_guess?(guess)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 172 def valid_guess?(guess) valid_boolean_value?(guess) end
valid_hash_value?(value)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 208 def valid_hash_value?(value) value.nil? || value.is_a?(Hash) end
valid_help?(help)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 176 def valid_help?(help) valid_boolean_value?(help) end
valid_long_flags?(long_flag)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 196 def valid_long_flags?(long_flag) valid_boolean_value?(long_flag) end
valid_names?(names)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 184 def valid_names?(names) valid_string_array_value?(names) end
valid_no_color?(no_color)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 132 def valid_no_color?(no_color) valid_boolean_value?(no_color) end
valid_no_profile?(no_profile)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 148 def valid_no_profile?(no_profile) valid_boolean_value?(no_profile) end
valid_no_source?(no_source)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 128 def valid_no_source?(no_source) valid_boolean_value?(no_source) end
valid_options?(options)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 192 def valid_options?(options) valid_string_array_value?(options) end
valid_profiles?(profiles)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 108 def valid_profiles?(profiles) valid_string_array_value?(profiles) end
valid_quiet?(quiet)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 168 def valid_quiet?(quiet) valid_boolean_value?(quiet) end
valid_requires?(requires)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 188 def valid_requires?(requires) valid_string_array_value?(requires) end
valid_strict?(strict)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 156 def valid_strict?(strict) valid_boolean_value?(strict) end
valid_string_array_value?(value)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 200 def valid_string_array_value?(value) value.nil? || value.is_a?(Array) || value.is_a?(String) end
valid_verbose?(verbose)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 160 def valid_verbose?(verbose) valid_boolean_value?(verbose) end
valid_version?(version)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 164 def valid_version?(version) valid_boolean_value?(version) end
valid_wip?(wip)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 144 def valid_wip?(wip) valid_boolean_value?(wip) end
validate_options(options)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 57 def validate_options(options) raise(ArgumentError, "Argument must be a Hash, got: #{options.class}") unless options.is_a?(Hash) options.each_key do |option| raise(ArgumentError, "Option: #{option}, is not a cucumber option") unless CUKE_OPTIONS.include?(option.to_s) end raise_invalid_error('Profiles', 'a String or Array', options[:profiles]) unless valid_profiles?(options[:profiles]) raise_invalid_error('Tags', 'a String or Array', options[:tags]) unless valid_tags?(options[:tags]) raise_invalid_error('File path', 'a String or Array', options[:file_paths]) unless valid_file_paths?(options[:file_paths]) raise_invalid_error('Formatters', 'a Hash', options[:formatters]) unless valid_formatters?(options[:formatters]) raise_invalid_error('Excludes', 'a String or Array', options[:excludes]) unless valid_excludes?(options[:excludes]) raise_invalid_error('No-source', 'true or false', options[:no_source]) unless valid_no_source?(options[:no_source]) raise_invalid_error('No-color', 'true or false', options[:no_color]) unless valid_no_color?(options[:no_color]) raise_invalid_error('Color', 'true or false', options[:color]) unless valid_color?(options[:color]) raise_invalid_error('Backtrace', 'true or false', options[:backtrace]) unless valid_backtrace?(options[:backtrace]) raise_invalid_error('Expand', 'true or false', options[:expand]) unless valid_expand?(options[:expand]) raise_invalid_error('Guess', 'true or false', options[:guess]) unless valid_guess?(options[:guess]) raise_invalid_error('Help', 'true or false', options[:help]) unless valid_help?(options[:help]) raise_invalid_error('Dry run', 'true or false', options[:dry_run]) unless valid_dry_run?(options[:dry_run]) raise_invalid_error('No profile', 'true or false', options[:no_profile]) unless valid_no_profile?(options[:no_profile]) raise_invalid_error('Quiet', 'true or false', options[:quiet]) unless valid_quiet?(options[:quiet]) raise_invalid_error('Strict', 'true or false', options[:strict]) unless valid_strict?(options[:strict]) raise_invalid_error('Verbose', 'true or false', options[:verbose]) unless valid_verbose?(options[:verbose]) raise_invalid_error('Version', 'true or false', options[:version]) unless valid_version?(options[:version]) raise_invalid_error('Wip', 'true or false', options[:wip]) unless valid_wip?(options[:wip]) raise_invalid_error('Names', 'a String or Array', options[:names]) unless valid_names?(options[:names]) raise_invalid_error('Requires', 'a String or Array', options[:requires]) unless valid_requires?(options[:requires]) raise_invalid_error('Options', 'a String or Array', options[:options]) unless valid_options?(options[:options]) raise_invalid_error('Long Flags', 'true or false', options[:long_flags]) unless valid_long_flags?(options[:long_flags]) end
wrap_options(option_set)
click to toggle source
# File lib/cuke_commander/cl_generator.rb, line 100 def wrap_options(option_set) option_set.is_a?(Array) ? option_set : [option_set] end