Module: Cukesparse
- Defined in:
- lib/cukesparse.rb,
lib/cukesparse/version.rb
Constant Summary collapse
- VERSION =
"2.1.8"
Class Attribute Summary collapse
-
.command ⇒ Object
Returns the value of attribute command.
-
.config ⇒ Object
Returns the value of attribute config.
-
.config_file ⇒ Object
Returns current config file.
-
.parameters ⇒ Object
Returns the value of attribute parameters.
-
.task ⇒ Object
Returns the value of attribute task.
Class Method Summary collapse
-
.add_multiple(key, val) ⇒ Object
Add multiple options to key.
-
.argv ⇒ Object
Returns current argv.
-
.build_command ⇒ Object
Builds the command line string.
-
.check_for_parameters ⇒ Object
Checks parameters and returns boolean.
-
.check_for_task ⇒ Object
Checks for task in arguments.
-
.debug ⇒ Object
Outputs the debug information.
-
.execute ⇒ Object
Executes cukesparse by checking arguments passed.
-
.load_config ⇒ Object
Loads the config file.
-
.parse_argv ⇒ Object
Parses the options passed via command line.
-
.reset! ⇒ Object
Resets cukesparse.
-
.set_cucumber_defaults ⇒ Object
Updates parameters based on config cucumber defaults.
-
.set_runtime_defaults ⇒ Object
Updates parameters based on config runtime defaults.
-
.split_parameters(params, sym) ⇒ Object
Splits parameters passed.
Class Attribute Details
.command ⇒ Object
Returns the value of attribute command.
7 8 9 |
# File 'lib/cukesparse.rb', line 7 def command @command end |
.config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/cukesparse.rb', line 7 def config @config end |
.config_file ⇒ Object
Returns current config file
10 11 12 |
# File 'lib/cukesparse.rb', line 10 def config_file @config_file end |
.parameters ⇒ Object
Returns the value of attribute parameters.
7 8 9 |
# File 'lib/cukesparse.rb', line 7 def parameters @parameters end |
.task ⇒ Object
Returns the value of attribute task.
7 8 9 |
# File 'lib/cukesparse.rb', line 7 def task @task end |
Class Method Details
.add_multiple(key, val) ⇒ Object
Add multiple options to key
23 24 25 26 27 28 29 |
# File 'lib/cukesparse.rb', line 23 def add_multiple key, val return (@parameters[key] ||= []).push '--' + key + ' ' + val unless val.is_a? Array val.each do |v| (@parameters[key] ||= []).push '--' + key + ' ' + v end end |
.argv ⇒ Object
Returns current argv
15 16 17 |
# File 'lib/cukesparse.rb', line 15 def argv ARGV end |
.build_command ⇒ Object
Builds the command line string
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cukesparse.rb', line 46 def build_command unless @task.empty? && @parameters.empty? @command.push 'bundle exec cucumber' @command.push '--require features/' @command.push task['feature_order'].join(' ') if task.has_key? 'feature_order' @parameters.each { |k,v| @command.push(v) } @command.push task['defaults'].join(' ') if task.has_key? 'defaults' end return debug if @parameters.has_key? 'debug' begin result = system(@command.join(' ')) rescue Interrupt puts 'Quitting Cucumber and Cukesparse...' Process.kill('INT', -Process.getpgrp) else exit result end end |
.check_for_parameters ⇒ Object
Checks parameters and returns boolean
78 79 80 |
# File 'lib/cukesparse.rb', line 78 def check_for_parameters return puts 'WARN: No parameters passed to cukesparse'.yellow unless @parameters.any? end |
.check_for_task ⇒ Object
Checks for task in arguments
68 69 70 71 72 73 74 75 |
# File 'lib/cukesparse.rb', line 68 def check_for_task return abort 'ERROR: Your tasks.yml file is empty!'.red.underline unless @config task = argv & @config.keys return abort 'ERROR: No task was passed to cukesparse!'.red.underline if task.empty? return puts 'WARN: Multiple tasks have been passed!'.yellow if task.length > 1 return @task = @config[task[0]] end |
.debug ⇒ Object
Outputs the debug information
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cukesparse.rb', line 83 def debug puts 'DEBUG: Outputting ARGV passed'.yellow puts argv.inspect puts 'DEBUG: Outputting parsed config file'.yellow puts @config.inspect puts 'DEBUG: Outputting parameters created'.yellow puts @parameters.inspect puts 'DEBUG: Outputting command created'.yellow puts @command.join(' ') end |
.execute ⇒ Object
Executes cukesparse by checking arguments passed
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cukesparse.rb', line 32 def execute load_config return puts 'Cukesparse - a simple command line parser to pass arguments into Cucumber!'.yellow if argv.empty? return puts "You have the following tasks within your config file: #{@config.keys.join(', ')}".yellow if argv.dup.shift == 'tasks' parse_argv check_for_task check_for_parameters set_cucumber_defaults set_runtime_defaults build_command end |
.load_config ⇒ Object
Loads the config file
95 96 97 98 99 100 101 |
# File 'lib/cukesparse.rb', line 95 def load_config @config = YAML.load_file config_file rescue Psych::SyntaxError abort 'Your tasks file did not parse as expected!'.red.underline rescue Errno::ENOENT abort 'Your tasks file is missing!'.red.underline end |
.parse_argv ⇒ Object
Parses the options passed via command line
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cukesparse.rb', line 104 def parse_argv cli argv, # Cucumber options '-t' => lambda{ |t| add_multiple('tags', t) }, '-n --name' => lambda{ |n| add_multiple('name', n) }, '-f --format' => ->(f){ @parameters['format'] = "--format #{f}" }, '-d --dry-run' => ->{ @parameters['dry_run'] = "--dry-run" }, '-v --verbose' => ->{ @parameters['verbose'] = "--verbose" }, '-s --strict' => ->{ @parameters['strict'] = "--strict" }, '-g --guess' => ->{ @parameters['guess'] = "--guess" }, '-x --expand' => ->{ @parameters['expand'] = "--expand" }, # All options below have been added for custom project but can be used for example # Global options '-e --environment' => ->(e){ @parameters['environment'] = "ENVIRONMENT=#{e}" }, '-l --loglevel' => ->(l){ @parameters['log_level'] = "LOG_LEVEL=#{l}" }, '-c --controller' => ->(c){ @parameters['controller'] = "CONTROLLER=#{c}" }, '-h --headless' => ->{ @parameters['headless'] = "HEADLESS=TRUE" }, # Database options '--cleanup' => ->{ @parameters['cleanup'] = "CLEANUP=TRUE" }, '--no-cleanup' => ->{ @parameters['cleanup'] = "CLEANUP=FALSE" }, '--database' => ->{ @parameters['database'] = "DATABASE=TRUE" }, '--jenkins' => ->{ @parameters['jenkins'] = "JENKINS=TRUE" }, # Retry options '--retries' => ->(r){ @parameters['retries'] = "RETRIES=#{r}" }, '--timeout' => ->(t){ @parameters['timeout'] = "TIMEOUT=#{t}" }, # Driver Options '--screen' => ->(s){ split_parameters(s, 'screen') }, '--position' => ->(p){ split_parameters(p, 'position') }, '--screenwidth' => ->(w){ @parameters['screen_width'] = "SCREENWIDTH=#{w}" }, '--screenheight' => ->(h){ @parameters['screen_height'] = "SCREENHEIGHT=#{h}" }, '--xposition' => ->(x){ @parameters['xposition'] = "XPOSITION=#{x}" }, '--yposition' => ->(y){ @parameters['yposition'] = "YPOSITION=#{y}" }, '-H --highlight' => ->{ @parameters['highlight'] = "HIGHLIGHT=TRUE" }, # Debug '--debug' => ->{ @parameters['debug'] = "DEBUG=TRUE" } rescue abort 'Error processing passed CLI arguments!'.red.underline end |
.reset! ⇒ Object
Resets cukesparse
213 214 215 216 217 218 |
# File 'lib/cukesparse.rb', line 213 def reset! @config = {} @parameters = {} @task = {} @command = [] end |
.set_cucumber_defaults ⇒ Object
Updates parameters based on config cucumber defaults
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/cukesparse.rb', line 165 def set_cucumber_defaults return puts 'WARN: The task has no cucumber defaults!'.yellow unless @task.has_key? 'cucumber_defaults' @task['cucumber_defaults'].each do |key, val| case key when 'tags', 'name' add_multiple key, val when 'format' unless @parameters.has_key? key @parameters[key] = '--' + key.downcase + ' ' + val.to_s end when 'strict', 'verbose', 'guess', 'expand' unless @parameters.has_key? key && @parameters[key] == true @parameters[key] = '--' + key.downcase end when 'dry_run' unless @parameters.has_key? key && @parameters[key] == true @parameters[key] = '--dry-run' end else puts "WARN: The cucumber default #{key} isn't a known option!".yellow end end end |
.set_runtime_defaults ⇒ Object
Updates parameters based on config runtime defaults
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/cukesparse.rb', line 149 def set_runtime_defaults return puts 'WARN: The task has no runtime defaults!'.yellow unless @task.has_key? 'runtime_defaults' @task['runtime_defaults'].each do |key, val| case key when 'screen', 'position' split_parameters(val, key) else unless @parameters.has_key? key @parameters[key] = key.upcase + '=' + val.to_s end end end end |
.split_parameters(params, sym) ⇒ Object
Splits parameters passed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/cukesparse.rb', line 194 def split_parameters params, sym params = params.split '/' if params.length == 1 abort "ERROR: You have not passed enough parameters in the #{sym.to_s} command line argument!".red.underline elsif params.length > 2 abort "ERROR: You have passed to many parameters in the #{sym.to_s} command line argument!".red.underline end case sym when 'screen' @parameters['screenwidth'] = "SCREENWIDTH=#{params[0]}" @parameters['screenheight'] = "SCREENHEIGHT=#{params[1]}" when 'position' @parameters['xposition'] = "XPOSITION=#{params[0]}" @parameters['yposition'] = "YPOSITION=#{params[1]}" end end |