Class: Generators::TDriverFeatureTestGenerator
- Defined in:
- lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #generate(files) ⇒ Object
- #generate_feature(data) ⇒ Object
- #generate_name(method) ⇒ Object
- #generate_scenarios(mode, arguments_table = nil) ⇒ Object
-
#has_method?(target, method_name) ⇒ Boolean
verify if.
-
#initialize(options) ⇒ TDriverFeatureTestGenerator
constructor
A new instance of TDriverFeatureTestGenerator.
- #process_arguments(arguments) ⇒ Object
- #process_attribute(attribute) ⇒ Object
- #process_attributes(attributes) ⇒ Object
- #process_file(file) ⇒ Object
- #process_method(method) ⇒ Object
- #process_methods(methods) ⇒ Object
- #process_module(_module) ⇒ Object
- #process_modules(modules) ⇒ Object
Constructor Details
#initialize(options) ⇒ TDriverFeatureTestGenerator
Returns a new instance of TDriverFeatureTestGenerator.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 37 def initialize( ) @options = @already_processed_files = [] @current_module_tests = [] @current_module = nil @output = { :files => [], :classes => [], :modules => [], :attributes => [], :methods => [], :aliases => [], :constants => [], :requires => [], :includes => []} end |
Class Method Details
.for(options) ⇒ Object
31 32 33 34 35 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 31 def self.for( ) new( ) end |
Instance Method Details
#generate(files) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 51 def generate( files ) # process files files.each{ | file | process_file( file ) unless @already_processed_files.include?( file.file_absolute_name ) } p "total scenarios: %s" % $scenarios #p @already_processed_files end |
#generate_feature(data) ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 406 def generate_feature( data ) path = File.join( data[:file] ) open( path, 'w' ){ | file | file << data[:header] file << data[:scenarios] } end |
#generate_name(method) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 335 def generate_name( method ) name = @module_path[ 1 .. -1 ].join("_") begin n = name.bytes.to_a result = "" n.each_with_index{ | byte, index | if byte == 95 result << byte.chr next end unless index == 0 prefix = "" if (65..90).include?( byte ) or (48..57).include?( byte ) prefix = "_" unless ( index + 1) > ( n.count - 1 ) next_byte = n[ index + 1 ] # do not add underscore if next character is in uppercase or numeric prefix = "" if (65..90).include?( next_byte ) or (48..57).include?( next_byte ) or next_byte == 95 else prev_byte = n[ index - 1 ] prefix = "" if ( 65..90 ).include?( prev_byte ) or ( 48..57 ).include?( prev_byte ) or prev_byte == 95 end end result << prefix + byte.chr.downcase else # first char, don't care if uppercase result << byte.chr end } name = result.gsub( /_+/, "_") rescue name = name.downcase end name << "_" << method name.gsub!(/[?!=]/){ | char | char = "_0x%x" % char[0] } ( name + ".feature" ).downcase end |
#generate_scenarios(mode, arguments_table = nil) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 175 def generate_scenarios( mode, arguments_table = nil ) results = [] # first scenario with all required arguments if mode.to_s =~ /method/ required_arguments = arguments_table.select{ | argument | argument.last == false }.to_a.collect{ | scenario | scenario.first } # Array conversion for ruby 1.9 compatibility results << $templates[ mode ] % [ @current_method.name, "required", "(s)", @current_method.name, required_arguments.join(", ") ] elsif mode.to_s =~ /attribute/ name = @current_attribute.first.name name << "=" if @current_attribute.count > 1 results << $templates[ mode ] % [ name, name ] end unless arguments_table.nil? # scenarios with one of each optional argument.. and eventually with all arguments arguments_table.select{ | argument | argument.last == true }.to_a.collect{ | scenario | scenario # Array conversion for ruby 1.9 compatibility scenario = required_arguments << scenario.first results << $templates[ mode ] % [ @current_method.name, "optional", " '%s'" % scenario.last.first, @current_method.name, scenario.join(", ") ] } end results end |
#has_method?(target, method_name) ⇒ Boolean
verify if
236 237 238 239 240 241 242 243 244 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 236 def has_method?( target, method_name ) target.method_list.select{ | method | method.name == method_name }.count > 0 end |
#process_arguments(arguments) ⇒ Object
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 110 def process_arguments( arguments ) # tokenize string tokenizer = RubyLex.new( arguments ) # get first token token = tokenizer.token # set previous token to nil by default previous_token = nil args = [] capture = false capture_depth = [] # loop while tokens available while token if [ RubyToken::TkLBRACE, RubyToken::TkLPAREN, RubyToken::TkLBRACK ].include?( token.class ) capture_depth << token capture = true elsif [ RubyToken::TkRBRACE, RubyToken::TkRPAREN, RubyToken::TkRBRACK ].include?( token.class ) capture_depth.pop capture = false if capture_depth.empty? # argument name elsif capture == false if token.kind_of?( RubyToken::TkIDENTIFIER ) args << [ token.name, nil, false ] # &blocks and *arguments are handled as optional parameters args.last[ -1 ] = true if [ RubyToken::TkBITAND, RubyToken::TkMULT ].include?( previous_token.class ) # detect optional argument elsif token.kind_of?( RubyToken::TkASSIGN ) # mark arguments as optional args.last[ -1 ] = true opt = true end end # store previous token previous_token = token # get next token token = tokenizer.token end args end |
#process_attribute(attribute) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 264 def process_attribute( attribute ) result = [] if ( @module_path.first =~ /MobyBehaviour/ ) @current_attribute = [ attribute ] #p @module_path scenarios = [] case attribute.rw when 'RW' # verify first that if attribute is overwritten as method unless has_method?( @current_module[ :object ], attribute.name ) scenarios << generate_scenarios( :scenario_attribute ) scenarios.pop if scenarios.last == [] end # verify first that if attribute is overwritten as method unless has_method?( @current_module[ :object ], "%s=" % attribute.name ) @current_attribute << "W" scenarios << generate_scenarios( :scenario_attribute ) scenarios.pop if scenarios.last == [] end when 'W' # verify first that if attribute is overwritten as method unless has_method?( @current_module[ :object ], "%s=" % attribute.name ) @current_attribute << "W" scenarios << generate_scenarios( :scenario_attribute ) scenarios.pop if scenarios.last == [] end when 'R' # verify first that if attribute is overwritten as method unless has_method?( @current_module[ :object ], attribute.name ) scenarios << generate_scenarios( :scenario_attribute ) scenarios.pop if scenarios.last == [] end else abort( "Unknown attribute rw status: %s" % attribute.rw ) end if scenarios.count > 0 #puts $templates[:feature] result << scenarios #puts scenarios $scenarios += scenarios.count end else #puts "%s method: %s" % [ method.visibility.to_s, method.name ] end result end |
#process_attributes(attributes) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 246 def process_attributes( attributes ) results = [] attributes.each{ | attribute | scenarios = process_attribute( attribute ) attr_name = attribute.name.gsub("=",'') results << { :header => $templates[:feature_attribute] % [ "%s#%s" % [ @module_path.join("::"), attribute.name ], attr_name, @module_path.join("::") ], :scenarios => scenarios, :file => generate_name( attr_name ), :module_path => @module_path, :name => attr_name } if scenarios.count > 0 } results end |
#process_file(file) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 66 def process_file( file ) @module_path = [] @current_file = file process_modules( file.modules ) end |
#process_method(method) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 213 def process_method( method ) scenarios = [] if ( method.visibility == :public && @module_path.first =~ /MobyBehaviour/ ) arguments_table = process_arguments( method.params ) @current_method = method scenarios = generate_scenarios( :scenario_method, arguments_table ) $scenarios += scenarios.count else end scenarios end |
#process_methods(methods) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 94 def process_methods( methods ) results = [] methods.each{ | method | scenarios = process_method( method ) results << { :header => $templates[:feature_method] % [ "%s#%s" % [ @module_path.join("::"), method.name ], method.name, @module_path.join("::") ], :scenarios => scenarios, :file => generate_name( method.name ), :module_path => @module_path, :name => method.name } if scenarios.count > 0 } results end |
#process_module(_module) ⇒ Object
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 420 def process_module( _module ) @already_processed_files << _module.full_name @current_module = { :object => _module, :scenarios => [] } # process methods methods = process_methods( _module.method_list ) # process attributes attributes = process_attributes( _module.attributes ) unless ( methods.empty? && attributes.empty? ) methods.each{ | method | generate_feature( method ) puts method[:file] puts method[:header] puts method[:scenarios] } attributes.each{ | method | generate_feature( method ) puts method[:file] puts method[:header] puts method[:scenarios] } end # process if any child modules process_modules( _module.modules ) unless _module.modules.empty? end |
#process_modules(modules) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb', line 76 def process_modules( modules ) modules.each{ | _module | unless @already_processed_files.include?( _module.full_name ) @module_path.push( _module.name ) process_module( _module ) @module_path.pop end } end |